blob: 80ce289eea05326336a7edecbe8a132ee4900d23 [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
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002008 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03002009 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2010 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002011 } else {
2012 encode_uint32(xdr, args->layoutupdate_len);
2013 if (args->layoutupdate_pages) {
2014 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2015 args->layoutupdate_len);
2016 }
2017 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002018
Andy Adamson863a3c62011-03-23 13:27:54 +00002019 return 0;
2020}
Benny Halevycbe82602011-05-22 19:52:37 +03002021
2022static void
2023encode_layoutreturn(struct xdr_stream *xdr,
2024 const struct nfs4_layoutreturn_args *args,
2025 struct compound_hdr *hdr)
2026{
Trond Myklebust94e5c572016-09-15 18:49:52 -04002027 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
Benny Halevycbe82602011-05-22 19:52:37 +03002028 __be32 *p;
2029
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002030 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2031 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002032 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2033 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002034 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002035 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002036 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002037 p = xdr_encode_hyper(p, args->range.offset);
2038 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002039 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002040 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002041 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002042 if (args->ld_private->ops && args->ld_private->ops->encode)
2043 args->ld_private->ops->encode(xdr, args, args->ld_private);
2044 else if (lr_ops->encode_layoutreturn)
Trond Myklebust94e5c572016-09-15 18:49:52 -04002045 lr_ops->encode_layoutreturn(xdr, args);
2046 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002047 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002048}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002049
2050static int
2051encode_secinfo_no_name(struct xdr_stream *xdr,
2052 const struct nfs41_secinfo_no_name_args *args,
2053 struct compound_hdr *hdr)
2054{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002055 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2056 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002057 return 0;
2058}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002059
2060static void encode_test_stateid(struct xdr_stream *xdr,
2061 struct nfs41_test_stateid_args *args,
2062 struct compound_hdr *hdr)
2063{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002064 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2065 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002066 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002067}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002068
2069static void encode_free_stateid(struct xdr_stream *xdr,
2070 struct nfs41_free_stateid_args *args,
2071 struct compound_hdr *hdr)
2072{
Trond Myklebustab19b482012-03-04 18:13:57 -05002073 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002074 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002075}
Trond Myklebustcf805162016-11-15 14:56:07 -05002076#else
2077static inline void
2078encode_layoutreturn(struct xdr_stream *xdr,
2079 const struct nfs4_layoutreturn_args *args,
2080 struct compound_hdr *hdr)
2081{
2082}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002083#endif /* CONFIG_NFS_V4_1 */
2084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085/*
2086 * END OF "GENERIC" ENCODE ROUTINES.
2087 */
2088
Benny Halevy66cc0422009-04-01 09:22:10 -04002089static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2090{
2091#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002092 struct nfs4_session *session = args->sa_slot->table->session;
2093 if (session)
2094 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002095#endif /* CONFIG_NFS_V4_1 */
2096 return 0;
2097}
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099/*
2100 * Encode an ACCESS request
2101 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002102static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2103 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Chuck Lever9f06c712010-12-14 14:59:18 +00002109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putfh(xdr, args->fh, &hdr);
2112 encode_access(xdr, args->access, &hdr);
2113 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002114 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
2117/*
2118 * Encode LOOKUP request
2119 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002120static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Chuck Lever9f06c712010-12-14 14:59:18 +00002127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->dir_fh, &hdr);
2130 encode_lookup(xdr, args->name, &hdr);
2131 encode_getfh(xdr, &hdr);
2132 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002133 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136/*
2137 * Encode LOOKUP_ROOT request
2138 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002139static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2140 struct xdr_stream *xdr,
2141 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
Chuck Lever9f06c712010-12-14 14:59:18 +00002147 encode_compound_hdr(xdr, req, &hdr);
2148 encode_sequence(xdr, &args->seq_args, &hdr);
2149 encode_putrootfh(xdr, &hdr);
2150 encode_getfh(xdr, &hdr);
2151 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002152 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153}
2154
2155/*
2156 * Encode REMOVE request
2157 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002158static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002169 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/*
2173 * Encode RENAME request
2174 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002175static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2176 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Chuck Lever9f06c712010-12-14 14:59:18 +00002182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->old_dir, &hdr);
2185 encode_savefh(xdr, &hdr);
2186 encode_putfh(xdr, args->new_dir, &hdr);
2187 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002188 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189}
2190
2191/*
2192 * Encode LINK request
2193 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002194static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2195 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002198 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_compound_hdr(xdr, req, &hdr);
2202 encode_sequence(xdr, &args->seq_args, &hdr);
2203 encode_putfh(xdr, args->fh, &hdr);
2204 encode_savefh(xdr, &hdr);
2205 encode_putfh(xdr, args->dir_fh, &hdr);
2206 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002207 encode_restorefh(xdr, &hdr);
2208 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002209 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210}
2211
2212/*
2213 * Encode CREATE request
2214 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002215static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2216 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Chuck Lever9f06c712010-12-14 14:59:18 +00002222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002225 encode_create(xdr, args, &hdr);
2226 encode_getfh(xdr, &hdr);
2227 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002228 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * Encode SYMLINK request
2233 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002234static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2235 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Chuck Lever9f06c712010-12-14 14:59:18 +00002237 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
2240/*
2241 * Encode GETATTR request
2242 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002243static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2244 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_compound_hdr(xdr, req, &hdr);
2251 encode_sequence(xdr, &args->seq_args, &hdr);
2252 encode_putfh(xdr, args->fh, &hdr);
2253 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002254 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255}
2256
2257/*
2258 * Encode a CLOSE request
2259 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002260static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2261 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Andy Adamson05d564f2008-12-23 16:06:15 -05002263 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002264 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_sequence(xdr, &args->seq_args, &hdr);
2269 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002270 if (args->lr_args)
2271 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002272 if (args->bitmask != NULL)
2273 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002274 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002275 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276}
2277
2278/*
2279 * Encode an OPEN request
2280 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002281static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2282 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Chuck Lever9f06c712010-12-14 14:59:18 +00002288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002291 encode_open(xdr, args, &hdr);
2292 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002293 if (args->access)
2294 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002295 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002296 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297}
2298
2299/*
2300 * Encode an OPEN_CONFIRM request
2301 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002302static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2303 struct xdr_stream *xdr,
2304 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002307 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Chuck Lever9f06c712010-12-14 14:59:18 +00002310 encode_compound_hdr(xdr, req, &hdr);
2311 encode_putfh(xdr, args->fh, &hdr);
2312 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002313 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
2316/*
2317 * Encode an OPEN request with no attributes.
2318 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002319static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2320 struct xdr_stream *xdr,
2321 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002324 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
Chuck Lever9f06c712010-12-14 14:59:18 +00002327 encode_compound_hdr(xdr, req, &hdr);
2328 encode_sequence(xdr, &args->seq_args, &hdr);
2329 encode_putfh(xdr, args->fh, &hdr);
2330 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002331 if (args->access)
2332 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002333 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002334 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
2337/*
2338 * Encode an OPEN_DOWNGRADE request
2339 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002340static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2341 struct xdr_stream *xdr,
2342 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002345 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Chuck Lever9f06c712010-12-14 14:59:18 +00002348 encode_compound_hdr(xdr, req, &hdr);
2349 encode_sequence(xdr, &args->seq_args, &hdr);
2350 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002351 if (args->lr_args)
2352 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002353 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002354 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
2357/*
2358 * Encode a LOCK request
2359 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002360static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2361 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002364 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Chuck Lever9f06c712010-12-14 14:59:18 +00002367 encode_compound_hdr(xdr, req, &hdr);
2368 encode_sequence(xdr, &args->seq_args, &hdr);
2369 encode_putfh(xdr, args->fh, &hdr);
2370 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002371 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372}
2373
2374/*
2375 * Encode a LOCKT request
2376 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002377static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2378 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002381 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
Chuck Lever9f06c712010-12-14 14:59:18 +00002384 encode_compound_hdr(xdr, req, &hdr);
2385 encode_sequence(xdr, &args->seq_args, &hdr);
2386 encode_putfh(xdr, args->fh, &hdr);
2387 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002388 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389}
2390
2391/*
2392 * Encode a LOCKU request
2393 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002394static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2395 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002398 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
Chuck Lever9f06c712010-12-14 14:59:18 +00002401 encode_compound_hdr(xdr, req, &hdr);
2402 encode_sequence(xdr, &args->seq_args, &hdr);
2403 encode_putfh(xdr, args->fh, &hdr);
2404 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002405 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406}
2407
Chuck Lever9f06c712010-12-14 14:59:18 +00002408static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2409 struct xdr_stream *xdr,
2410 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002411{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002412 struct compound_hdr hdr = {
2413 .minorversion = 0,
2414 };
2415
Chuck Lever9f06c712010-12-14 14:59:18 +00002416 encode_compound_hdr(xdr, req, &hdr);
2417 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002418 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002419}
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421/*
2422 * Encode a READLINK request
2423 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002424static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2425 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002428 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Chuck Lever9f06c712010-12-14 14:59:18 +00002431 encode_compound_hdr(xdr, req, &hdr);
2432 encode_sequence(xdr, &args->seq_args, &hdr);
2433 encode_putfh(xdr, args->fh, &hdr);
2434 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002435
Benny Halevy28f56692009-04-01 09:22:09 -04002436 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002437 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002438 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
2440
2441/*
2442 * Encode a READDIR request
2443 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002444static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2445 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002448 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->fh, &hdr);
2454 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002455
Benny Halevy28f56692009-04-01 09:22:09 -04002456 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002457 args->pgbase, args->count);
2458 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002459 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002460 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002461 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
2464/*
2465 * Encode a READ request
2466 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002467static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002468 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002471 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Chuck Lever9f06c712010-12-14 14:59:18 +00002474 encode_compound_hdr(xdr, req, &hdr);
2475 encode_sequence(xdr, &args->seq_args, &hdr);
2476 encode_putfh(xdr, args->fh, &hdr);
2477 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478
Benny Halevy28f56692009-04-01 09:22:09 -04002479 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002481 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002482 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
2485/*
2486 * Encode an SETATTR request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2489 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Andy Adamson05d564f2008-12-23 16:06:15 -05002491 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002492 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002493 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Chuck Lever9f06c712010-12-14 14:59:18 +00002495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_sequence(xdr, &args->seq_args, &hdr);
2497 encode_putfh(xdr, args->fh, &hdr);
2498 encode_setattr(xdr, args, args->server, &hdr);
2499 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002500 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501}
2502
2503/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002504 * Encode a GETACL request
2505 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002506static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2507 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002508{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002509 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002510 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002511 };
Benny Halevy28f56692009-04-01 09:22:09 -04002512 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002513
Chuck Lever9f06c712010-12-14 14:59:18 +00002514 encode_compound_hdr(xdr, req, &hdr);
2515 encode_sequence(xdr, &args->seq_args, &hdr);
2516 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002517 replen = hdr.replen + op_decode_hdr_maxsz;
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002519
Benny Halevy28f56692009-04-01 09:22:09 -04002520 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002521 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002522
Andy Adamsond0179312008-12-23 16:06:17 -05002523 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002524}
2525
2526/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 * Encode a WRITE request
2528 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002529static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002530 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002533 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
Chuck Lever9f06c712010-12-14 14:59:18 +00002536 encode_compound_hdr(xdr, req, &hdr);
2537 encode_sequence(xdr, &args->seq_args, &hdr);
2538 encode_putfh(xdr, args->fh, &hdr);
2539 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002540 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002541 if (args->bitmask)
2542 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002543 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544}
2545
2546/*
2547 * a COMMIT request
2548 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002549static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002550 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002553 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
Chuck Lever9f06c712010-12-14 14:59:18 +00002556 encode_compound_hdr(xdr, req, &hdr);
2557 encode_sequence(xdr, &args->seq_args, &hdr);
2558 encode_putfh(xdr, args->fh, &hdr);
2559 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002560 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561}
2562
2563/*
2564 * FSINFO request
2565 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002566static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2567 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002570 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572
Chuck Lever9f06c712010-12-14 14:59:18 +00002573 encode_compound_hdr(xdr, req, &hdr);
2574 encode_sequence(xdr, &args->seq_args, &hdr);
2575 encode_putfh(xdr, args->fh, &hdr);
2576 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002577 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578}
2579
2580/*
2581 * a PATHCONF request
2582 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002583static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2584 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002587 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
Chuck Lever9f06c712010-12-14 14:59:18 +00002590 encode_compound_hdr(xdr, req, &hdr);
2591 encode_sequence(xdr, &args->seq_args, &hdr);
2592 encode_putfh(xdr, args->fh, &hdr);
2593 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002594 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002595 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
2598/*
2599 * a STATFS request
2600 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002601static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2602 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fh, &hdr);
2611 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002612 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002613 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614}
2615
2616/*
2617 * GETATTR_BITMAP request
2618 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002619static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2620 struct xdr_stream *xdr,
2621 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Kinglong Mee8c612822015-08-26 21:12:58 +08002623 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002625 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
Chuck Lever9f06c712010-12-14 14:59:18 +00002628 encode_compound_hdr(xdr, req, &hdr);
2629 encode_sequence(xdr, &args->seq_args, &hdr);
2630 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002631 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002632 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633}
2634
2635/*
2636 * a RENEW request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2639 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002642 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 };
2644
Chuck Lever9f06c712010-12-14 14:59:18 +00002645 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002646 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002647 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648}
2649
2650/*
2651 * a SETCLIENTID request
2652 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002653static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2654 struct xdr_stream *xdr,
2655 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002658 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 };
2660
Chuck Lever9f06c712010-12-14 14:59:18 +00002661 encode_compound_hdr(xdr, req, &hdr);
2662 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002663 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664}
2665
2666/*
2667 * a SETCLIENTID_CONFIRM request
2668 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002669static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002674 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002679 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680}
2681
2682/*
2683 * DELEGRETURN request
2684 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002685static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2686 struct xdr_stream *xdr,
2687 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002690 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
Chuck Lever9f06c712010-12-14 14:59:18 +00002693 encode_compound_hdr(xdr, req, &hdr);
2694 encode_sequence(xdr, &args->seq_args, &hdr);
2695 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002696 if (args->lr_args)
2697 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002698 if (args->bitmask)
2699 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002700 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002701 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702}
2703
2704/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002705 * Encode FS_LOCATIONS request
2706 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002707static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2708 struct xdr_stream *xdr,
2709 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002710{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002711 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002712 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002713 };
Benny Halevy28f56692009-04-01 09:22:09 -04002714 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002715
Chuck Lever9f06c712010-12-14 14:59:18 +00002716 encode_compound_hdr(xdr, req, &hdr);
2717 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002718 if (args->migration) {
2719 encode_putfh(xdr, args->fh, &hdr);
2720 replen = hdr.replen;
2721 encode_fs_locations(xdr, args->bitmask, &hdr);
2722 if (args->renew)
2723 encode_renew(xdr, args->clientid, &hdr);
2724 } else {
2725 encode_putfh(xdr, args->dir_fh, &hdr);
2726 encode_lookup(xdr, args->name, &hdr);
2727 replen = hdr.replen;
2728 encode_fs_locations(xdr, args->bitmask, &hdr);
2729 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002730
Chuck Leverb03d7352013-10-17 14:12:50 -04002731 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002732 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002733 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002734 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002735}
2736
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002737/*
2738 * Encode SECINFO request
2739 */
2740static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2741 struct xdr_stream *xdr,
2742 struct nfs4_secinfo_arg *args)
2743{
2744 struct compound_hdr hdr = {
2745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2746 };
2747
2748 encode_compound_hdr(xdr, req, &hdr);
2749 encode_sequence(xdr, &args->seq_args, &hdr);
2750 encode_putfh(xdr, args->dir_fh, &hdr);
2751 encode_secinfo(xdr, args->name, &hdr);
2752 encode_nops(&hdr);
2753}
2754
Chuck Lever44c99932013-10-17 14:13:30 -04002755/*
2756 * Encode FSID_PRESENT request
2757 */
2758static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2759 struct xdr_stream *xdr,
2760 struct nfs4_fsid_present_arg *args)
2761{
2762 struct compound_hdr hdr = {
2763 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2764 };
2765
2766 encode_compound_hdr(xdr, req, &hdr);
2767 encode_sequence(xdr, &args->seq_args, &hdr);
2768 encode_putfh(xdr, args->fh, &hdr);
2769 encode_getfh(xdr, &hdr);
2770 if (args->renew)
2771 encode_renew(xdr, args->clientid, &hdr);
2772 encode_nops(&hdr);
2773}
2774
Benny Halevy99fe60d2009-04-01 09:22:29 -04002775#if defined(CONFIG_NFS_V4_1)
2776/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002777 * BIND_CONN_TO_SESSION request
2778 */
2779static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2780 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002781 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002782{
2783 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002784 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002785 };
2786
2787 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002788 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002789 encode_nops(&hdr);
2790}
2791
2792/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002793 * EXCHANGE_ID request
2794 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002795static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
2797 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002798{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002799 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002800 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002801 };
2802
Chuck Lever9f06c712010-12-14 14:59:18 +00002803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002805 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002806}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002807
2808/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002809 * a CREATE_SESSION request
2810 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002811static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002814{
Andy Adamsonfc931582009-04-01 09:22:31 -04002815 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002816 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002817 };
2818
Chuck Lever9f06c712010-12-14 14:59:18 +00002819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002821 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002822}
2823
2824/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002825 * a DESTROY_SESSION request
2826 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002827static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2828 struct xdr_stream *xdr,
2829 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002830{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002831 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002832 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002833 };
2834
Chuck Lever9f06c712010-12-14 14:59:18 +00002835 encode_compound_hdr(xdr, req, &hdr);
2836 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002837 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002838}
2839
2840/*
Trond Myklebust66245532012-05-25 17:18:09 -04002841 * a DESTROY_CLIENTID request
2842 */
2843static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs_client *clp)
2846{
2847 struct compound_hdr hdr = {
2848 .minorversion = clp->cl_mvops->minor_version,
2849 };
2850
2851 encode_compound_hdr(xdr, req, &hdr);
2852 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2853 encode_nops(&hdr);
2854}
2855
2856/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002857 * a SEQUENCE request
2858 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002859static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2860 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002861{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(args),
2864 };
2865
Chuck Lever9f06c712010-12-14 14:59:18 +00002866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002868 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002869}
2870
2871/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002872 * a GET_LEASE_TIME request
2873 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002874static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2875 struct xdr_stream *xdr,
2876 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002877{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002878 struct compound_hdr hdr = {
2879 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2880 };
Fred Isamandae100c2011-07-30 20:52:37 -04002881 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002882
Chuck Lever9f06c712010-12-14 14:59:18 +00002883 encode_compound_hdr(xdr, req, &hdr);
2884 encode_sequence(xdr, &args->la_seq_args, &hdr);
2885 encode_putrootfh(xdr, &hdr);
2886 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002887 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002888}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002889
2890/*
2891 * a RECLAIM_COMPLETE request
2892 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002893static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002896{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2899 };
2900
Chuck Lever9f06c712010-12-14 14:59:18 +00002901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002904 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002905}
2906
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002907/*
2908 * Encode GETDEVICEINFO request
2909 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002910static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2911 struct xdr_stream *xdr,
2912 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002913{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002914 struct compound_hdr hdr = {
2915 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2916 };
2917
Chuck Lever9f06c712010-12-14 14:59:18 +00002918 encode_compound_hdr(xdr, req, &hdr);
2919 encode_sequence(xdr, &args->seq_args, &hdr);
2920 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002921
2922 /* set up reply kvec. Subtract notification bitmap max size (2)
2923 * so that notification bitmap is put in xdr_buf tail */
2924 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2925 args->pdev->pages, args->pdev->pgbase,
2926 args->pdev->pglen);
2927
2928 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002929}
2930
2931/*
2932 * Encode LAYOUTGET request
2933 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002934static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2935 struct xdr_stream *xdr,
2936 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002937{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002938 struct compound_hdr hdr = {
2939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2940 };
2941
Chuck Lever9f06c712010-12-14 14:59:18 +00002942 encode_compound_hdr(xdr, req, &hdr);
2943 encode_sequence(xdr, &args->seq_args, &hdr);
2944 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2945 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002946
2947 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2948 args->layout.pages, 0, args->layout.pglen);
2949
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002950 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002951}
Andy Adamson863a3c62011-03-23 13:27:54 +00002952
2953/*
2954 * Encode LAYOUTCOMMIT request
2955 */
Benny Halevycbe82602011-05-22 19:52:37 +03002956static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2957 struct xdr_stream *xdr,
2958 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002959{
Benny Halevyac7db722011-05-22 19:53:48 +03002960 struct nfs4_layoutcommit_data *data =
2961 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2964 };
2965
2966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, &args->seq_args, &hdr);
2968 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002969 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002970 encode_getfattr(xdr, args->bitmask, &hdr);
2971 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002972}
2973
2974/*
2975 * Encode LAYOUTRETURN request
2976 */
2977static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2978 struct xdr_stream *xdr,
2979 struct nfs4_layoutreturn_args *args)
2980{
2981 struct compound_hdr hdr = {
2982 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2983 };
2984
2985 encode_compound_hdr(xdr, req, &hdr);
2986 encode_sequence(xdr, &args->seq_args, &hdr);
2987 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2988 encode_layoutreturn(xdr, args, &hdr);
2989 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002990}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002991
2992/*
2993 * Encode SECINFO_NO_NAME request
2994 */
2995static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2996 struct xdr_stream *xdr,
2997 struct nfs41_secinfo_no_name_args *args)
2998{
2999 struct compound_hdr hdr = {
3000 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3001 };
3002
3003 encode_compound_hdr(xdr, req, &hdr);
3004 encode_sequence(xdr, &args->seq_args, &hdr);
3005 encode_putrootfh(xdr, &hdr);
3006 encode_secinfo_no_name(xdr, args, &hdr);
3007 encode_nops(&hdr);
3008 return 0;
3009}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003010
3011/*
3012 * Encode TEST_STATEID request
3013 */
3014static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3015 struct xdr_stream *xdr,
3016 struct nfs41_test_stateid_args *args)
3017{
3018 struct compound_hdr hdr = {
3019 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3020 };
3021
3022 encode_compound_hdr(xdr, req, &hdr);
3023 encode_sequence(xdr, &args->seq_args, &hdr);
3024 encode_test_stateid(xdr, args, &hdr);
3025 encode_nops(&hdr);
3026}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003027
3028/*
3029 * Encode FREE_STATEID request
3030 */
3031static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3032 struct xdr_stream *xdr,
3033 struct nfs41_free_stateid_args *args)
3034{
3035 struct compound_hdr hdr = {
3036 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3037 };
3038
3039 encode_compound_hdr(xdr, req, &hdr);
3040 encode_sequence(xdr, &args->seq_args, &hdr);
3041 encode_free_stateid(xdr, args, &hdr);
3042 encode_nops(&hdr);
3043}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003044#endif /* CONFIG_NFS_V4_1 */
3045
Benny Halevy686841b2009-08-14 17:19:48 +03003046static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3047{
3048 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3049 "Remaining buffer length is %tu words.\n",
3050 func, xdr->end - xdr->p);
3051}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052
Trond Myklebust683b57b2006-06-09 09:34:22 -04003053static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003055 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3056 NFS4_OPAQUE_LIMIT);
3057 if (unlikely(ret < 0)) {
3058 if (ret == -EBADMSG)
3059 print_overflow_msg(__func__, xdr);
3060 return -EIO;
3061 }
3062 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 return 0;
3064}
3065
3066static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3067{
Al Viro8687b632006-10-19 23:28:48 -07003068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069
Benny Halevyc0eae662009-08-14 17:20:14 +03003070 p = xdr_inline_decode(xdr, 8);
3071 if (unlikely(!p))
3072 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003073 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003074 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003075
Benny Halevyc0eae662009-08-14 17:20:14 +03003076 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3077 if (unlikely(!p))
3078 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 hdr->tag = (char *)p;
3080 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003081 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003082 if (unlikely(hdr->nops < 1))
3083 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003085out_overflow:
3086 print_overflow_msg(__func__, xdr);
3087 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088}
3089
Trond Myklebustc7848f62013-12-04 17:39:23 -05003090static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3091 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092{
Al Viro8687b632006-10-19 23:28:48 -07003093 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 uint32_t opnum;
3095 int32_t nfserr;
3096
Benny Halevyc0eae662009-08-14 17:20:14 +03003097 p = xdr_inline_decode(xdr, 8);
3098 if (unlikely(!p))
3099 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003100 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003101 if (unlikely(opnum != expected))
3102 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003103 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003104 if (nfserr == NFS_OK)
3105 *nfs_retval = 0;
3106 else
3107 *nfs_retval = nfs4_stat_to_errno(nfserr);
3108 return true;
3109out_bad_operation:
3110 dprintk("nfs: Server returned operation"
3111 " %d but we issued a request for %d\n",
3112 opnum, expected);
3113 *nfs_retval = -EREMOTEIO;
3114 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003115out_overflow:
3116 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003117 *nfs_retval = -EIO;
3118 return false;
3119}
3120
3121static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3122{
3123 int retval;
3124
3125 __decode_op_hdr(xdr, expected, &retval);
3126 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
3129/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003130static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131{
Al Viro8687b632006-10-19 23:28:48 -07003132 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003133 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 char *str;
3135
Benny Halevyc0eae662009-08-14 17:20:14 +03003136 p = xdr_inline_decode(xdr, 12);
3137 if (likely(p))
3138 return decode_opaque_inline(xdr, &strlen, &str);
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141}
3142
3143static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3144{
Al Viro8687b632006-10-19 23:28:48 -07003145 uint32_t bmlen;
3146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
Benny Halevyc0eae662009-08-14 17:20:14 +03003148 p = xdr_inline_decode(xdr, 4);
3149 if (unlikely(!p))
3150 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003151 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
Fred Isamandae100c2011-07-30 20:52:37 -04003153 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003154 p = xdr_inline_decode(xdr, (bmlen << 2));
3155 if (unlikely(!p))
3156 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003158 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003159 if (bmlen > 1) {
3160 bitmap[1] = be32_to_cpup(p++);
3161 if (bmlen > 2)
3162 bitmap[2] = be32_to_cpup(p);
3163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 }
3165 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003166out_overflow:
3167 print_overflow_msg(__func__, xdr);
3168 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169}
3170
Trond Myklebust256e48b2012-06-21 11:18:13 -04003171static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172{
Al Viro8687b632006-10-19 23:28:48 -07003173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Benny Halevyc0eae662009-08-14 17:20:14 +03003175 p = xdr_inline_decode(xdr, 4);
3176 if (unlikely(!p))
3177 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003178 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003179 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003181out_overflow:
3182 print_overflow_msg(__func__, xdr);
3183 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
3186static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3187{
3188 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003189 int ret;
3190 ret = decode_attr_bitmap(xdr, bitmask);
3191 if (unlikely(ret < 0))
3192 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3194 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003195 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3196 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3197 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 return 0;
3199}
3200
3201static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3202{
Al Viro8687b632006-10-19 23:28:48 -07003203 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003204 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
3206 *type = 0;
3207 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3208 return -EIO;
3209 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003210 p = xdr_inline_decode(xdr, 4);
3211 if (unlikely(!p))
3212 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003213 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003215 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 return -EIO;
3217 }
3218 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003219 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003221 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003222 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003223out_overflow:
3224 print_overflow_msg(__func__, xdr);
3225 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226}
3227
Chuck Lever264e6352012-03-01 17:02:05 -05003228static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3229 uint32_t *bitmap, uint32_t *type)
3230{
3231 __be32 *p;
3232
3233 *type = 0;
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3235 return -EIO;
3236 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3237 p = xdr_inline_decode(xdr, 4);
3238 if (unlikely(!p))
3239 goto out_overflow;
3240 *type = be32_to_cpup(p);
3241 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3242 }
3243 dprintk("%s: expire type=0x%x\n", __func__, *type);
3244 return 0;
3245out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
3248}
3249
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3251{
Al Viro8687b632006-10-19 23:28:48 -07003252 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003253 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255 *change = 0;
3256 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3257 return -EIO;
3258 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003259 p = xdr_inline_decode(xdr, 8);
3260 if (unlikely(!p))
3261 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003262 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003264 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003266 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003268 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003269out_overflow:
3270 print_overflow_msg(__func__, xdr);
3271 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272}
3273
3274static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3275{
Al Viro8687b632006-10-19 23:28:48 -07003276 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003277 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278
3279 *size = 0;
3280 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3281 return -EIO;
3282 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003283 p = xdr_inline_decode(xdr, 8);
3284 if (unlikely(!p))
3285 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003286 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003288 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003290 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003291 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003292out_overflow:
3293 print_overflow_msg(__func__, xdr);
3294 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295}
3296
3297static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3298{
Al Viro8687b632006-10-19 23:28:48 -07003299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
3301 *res = 0;
3302 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3303 return -EIO;
3304 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003305 p = xdr_inline_decode(xdr, 4);
3306 if (unlikely(!p))
3307 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003308 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3310 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003311 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003313out_overflow:
3314 print_overflow_msg(__func__, xdr);
3315 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316}
3317
3318static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3319{
Al Viro8687b632006-10-19 23:28:48 -07003320 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
3322 *res = 0;
3323 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3324 return -EIO;
3325 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003326 p = xdr_inline_decode(xdr, 4);
3327 if (unlikely(!p))
3328 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003329 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3331 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003332 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003334out_overflow:
3335 print_overflow_msg(__func__, xdr);
3336 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337}
3338
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003339static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340{
Al Viro8687b632006-10-19 23:28:48 -07003341 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 fsid->major = 0;
3345 fsid->minor = 0;
3346 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3347 return -EIO;
3348 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003349 p = xdr_inline_decode(xdr, 16);
3350 if (unlikely(!p))
3351 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003352 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003353 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003357 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 (unsigned long long)fsid->major,
3359 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003360 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003361out_overflow:
3362 print_overflow_msg(__func__, xdr);
3363 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
3366static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3367{
Al Viro8687b632006-10-19 23:28:48 -07003368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369
3370 *res = 60;
3371 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3372 return -EIO;
3373 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003374 p = xdr_inline_decode(xdr, 4);
3375 if (unlikely(!p))
3376 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003377 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3379 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003380 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003382out_overflow:
3383 print_overflow_msg(__func__, xdr);
3384 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385}
3386
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003387static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003388{
3389 __be32 *p;
3390
3391 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3392 return -EIO;
3393 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3394 p = xdr_inline_decode(xdr, 4);
3395 if (unlikely(!p))
3396 goto out_overflow;
3397 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003398 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003399 }
3400 return 0;
3401out_overflow:
3402 print_overflow_msg(__func__, xdr);
3403 return -EIO;
3404}
3405
Kinglong Mee8c612822015-08-26 21:12:58 +08003406static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3407 uint32_t *bitmap, uint32_t *bitmask)
3408{
3409 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3410 int ret;
3411 ret = decode_attr_bitmap(xdr, bitmask);
3412 if (unlikely(ret < 0))
3413 return ret;
3414 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3415 } else
3416 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3417 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3418 bitmask[0], bitmask[1], bitmask[2]);
3419 return 0;
3420}
3421
Bryan Schumakerae42c702010-10-21 16:33:17 -04003422static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3423{
3424 __be32 *p;
3425 int len;
3426
Trond Myklebust7ad07352010-10-23 15:34:20 -04003427 if (fh != NULL)
3428 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003429
3430 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3431 return -EIO;
3432 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3433 p = xdr_inline_decode(xdr, 4);
3434 if (unlikely(!p))
3435 goto out_overflow;
3436 len = be32_to_cpup(p);
3437 if (len > NFS4_FHSIZE)
3438 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003439 p = xdr_inline_decode(xdr, len);
3440 if (unlikely(!p))
3441 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003442 if (fh != NULL) {
3443 memcpy(fh->data, p, len);
3444 fh->size = len;
3445 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003446 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3447 }
3448 return 0;
3449out_overflow:
3450 print_overflow_msg(__func__, xdr);
3451 return -EIO;
3452}
3453
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3455{
Al Viro8687b632006-10-19 23:28:48 -07003456 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003458 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3460 return -EIO;
3461 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003462 p = xdr_inline_decode(xdr, 4);
3463 if (unlikely(!p))
3464 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003465 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3467 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003468 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003470out_overflow:
3471 print_overflow_msg(__func__, xdr);
3472 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473}
3474
3475static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3476{
Al Viro8687b632006-10-19 23:28:48 -07003477 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003478 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 *fileid = 0;
3481 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3482 return -EIO;
3483 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003484 p = xdr_inline_decode(xdr, 8);
3485 if (unlikely(!p))
3486 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003487 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003489 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003491 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003492 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003493out_overflow:
3494 print_overflow_msg(__func__, xdr);
3495 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496}
3497
Manoj Naik99baf622006-06-09 09:34:24 -04003498static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3499{
Al Viro8687b632006-10-19 23:28:48 -07003500 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003501 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003502
3503 *fileid = 0;
3504 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3505 return -EIO;
3506 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003507 p = xdr_inline_decode(xdr, 8);
3508 if (unlikely(!p))
3509 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003510 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003511 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003512 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003513 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003514 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003515 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003516out_overflow:
3517 print_overflow_msg(__func__, xdr);
3518 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003519}
3520
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3522{
Al Viro8687b632006-10-19 23:28:48 -07003523 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 int status = 0;
3525
3526 *res = 0;
3527 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3528 return -EIO;
3529 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003530 p = xdr_inline_decode(xdr, 8);
3531 if (unlikely(!p))
3532 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003533 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3535 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003536 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003538out_overflow:
3539 print_overflow_msg(__func__, xdr);
3540 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541}
3542
3543static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3544{
Al Viro8687b632006-10-19 23:28:48 -07003545 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 int status = 0;
3547
3548 *res = 0;
3549 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3550 return -EIO;
3551 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003552 p = xdr_inline_decode(xdr, 8);
3553 if (unlikely(!p))
3554 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003555 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3557 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003558 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003560out_overflow:
3561 print_overflow_msg(__func__, xdr);
3562 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563}
3564
3565static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3566{
Al Viro8687b632006-10-19 23:28:48 -07003567 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 int status = 0;
3569
3570 *res = 0;
3571 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3572 return -EIO;
3573 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003574 p = xdr_inline_decode(xdr, 8);
3575 if (unlikely(!p))
3576 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003577 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3579 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003580 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003582out_overflow:
3583 print_overflow_msg(__func__, xdr);
3584 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585}
3586
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003587static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3588{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003589 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003590 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003591 int status = 0;
3592
Benny Halevyc0eae662009-08-14 17:20:14 +03003593 p = xdr_inline_decode(xdr, 4);
3594 if (unlikely(!p))
3595 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003596 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003597 if (n == 0)
3598 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003599 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003600 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3601 dprintk("cannot parse %d components in path\n", n);
3602 goto out_eio;
3603 }
3604 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003605 struct nfs4_string *component = &path->components[path->ncomponents];
3606 status = decode_opaque_inline(xdr, &component->len, &component->data);
3607 if (unlikely(status != 0))
3608 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003609 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003610 pr_cont("%s%.*s ",
3611 (path->ncomponents != n ? "/ " : ""),
3612 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003613 }
3614out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003615 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003616root_path:
3617/* a root pathname is sent as a zero component4 */
3618 path->ncomponents = 1;
3619 path->components[0].len=0;
3620 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003621 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003622 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003623out_eio:
3624 dprintk(" status %d", status);
3625 status = -EIO;
3626 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003627out_overflow:
3628 print_overflow_msg(__func__, xdr);
3629 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003630}
3631
3632static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003633{
3634 int n;
Al Viro8687b632006-10-19 23:28:48 -07003635 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003636 int status = -EIO;
3637
3638 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3639 goto out;
3640 status = 0;
3641 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3642 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003643 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003644 status = -EIO;
3645 /* Ignore borken servers that return unrequested attrs */
3646 if (unlikely(res == NULL))
3647 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003648 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003649 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003650 if (unlikely(status != 0))
3651 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003652 p = xdr_inline_decode(xdr, 4);
3653 if (unlikely(!p))
3654 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003655 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003656 if (n <= 0)
3657 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003658 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003659 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003660 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003661
Trond Myklebust809b4262013-03-27 11:54:45 -04003662 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3663 break;
3664 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003665 p = xdr_inline_decode(xdr, 4);
3666 if (unlikely(!p))
3667 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003668 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003669
Chuck Lever02a29762012-03-01 17:00:31 -05003670 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003671 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3672 struct nfs4_string *server;
3673
3674 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003675 unsigned int i;
3676 dprintk("%s: using first %u of %u servers "
3677 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003678 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003679 NFS4_FS_LOCATION_MAXSERVERS,
3680 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003681 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003682 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003683 char *data;
3684 status = decode_opaque_inline(xdr, &len, &data);
3685 if (unlikely(status != 0))
3686 goto out_eio;
3687 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003688 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003689 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003690 server = &loc->servers[loc->nservers];
3691 status = decode_opaque_inline(xdr, &server->len, &server->data);
3692 if (unlikely(status != 0))
3693 goto out_eio;
3694 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003695 }
3696 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003697 if (unlikely(status != 0))
3698 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003699 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003700 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003701 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003702out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003703 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003704 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003705out_overflow:
3706 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003707out_eio:
3708 status = -EIO;
3709 goto out;
3710}
3711
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3713{
Al Viro8687b632006-10-19 23:28:48 -07003714 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 int status = 0;
3716
3717 *res = 0;
3718 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3719 return -EIO;
3720 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003721 p = xdr_inline_decode(xdr, 8);
3722 if (unlikely(!p))
3723 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003724 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3726 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003727 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003729out_overflow:
3730 print_overflow_msg(__func__, xdr);
3731 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732}
3733
3734static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3735{
Al Viro8687b632006-10-19 23:28:48 -07003736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 int status = 0;
3738
3739 *maxlink = 1;
3740 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3741 return -EIO;
3742 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003743 p = xdr_inline_decode(xdr, 4);
3744 if (unlikely(!p))
3745 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003746 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3748 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003749 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003751out_overflow:
3752 print_overflow_msg(__func__, xdr);
3753 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754}
3755
3756static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3757{
Al Viro8687b632006-10-19 23:28:48 -07003758 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 int status = 0;
3760
3761 *maxname = 1024;
3762 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3763 return -EIO;
3764 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003765 p = xdr_inline_decode(xdr, 4);
3766 if (unlikely(!p))
3767 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003768 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3770 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003771 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003773out_overflow:
3774 print_overflow_msg(__func__, xdr);
3775 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776}
3777
3778static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3779{
Al Viro8687b632006-10-19 23:28:48 -07003780 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 int status = 0;
3782
3783 *res = 1024;
3784 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3785 return -EIO;
3786 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3787 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003788 p = xdr_inline_decode(xdr, 8);
3789 if (unlikely(!p))
3790 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003791 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 if (maxread > 0x7FFFFFFF)
3793 maxread = 0x7FFFFFFF;
3794 *res = (uint32_t)maxread;
3795 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3796 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003797 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003799out_overflow:
3800 print_overflow_msg(__func__, xdr);
3801 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802}
3803
3804static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3805{
Al Viro8687b632006-10-19 23:28:48 -07003806 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 int status = 0;
3808
3809 *res = 1024;
3810 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3811 return -EIO;
3812 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3813 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003814 p = xdr_inline_decode(xdr, 8);
3815 if (unlikely(!p))
3816 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003817 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 if (maxwrite > 0x7FFFFFFF)
3819 maxwrite = 0x7FFFFFFF;
3820 *res = (uint32_t)maxwrite;
3821 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3822 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003823 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003825out_overflow:
3826 print_overflow_msg(__func__, xdr);
3827 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828}
3829
Trond Myklebustbca79472009-03-11 14:10:26 -04003830static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831{
Trond Myklebustbca79472009-03-11 14:10:26 -04003832 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003833 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003834 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835
3836 *mode = 0;
3837 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3838 return -EIO;
3839 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003840 p = xdr_inline_decode(xdr, 4);
3841 if (unlikely(!p))
3842 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003843 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003844 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003848 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003850out_overflow:
3851 print_overflow_msg(__func__, xdr);
3852 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853}
3854
3855static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3856{
Al Viro8687b632006-10-19 23:28:48 -07003857 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003858 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859
3860 *nlink = 1;
3861 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3862 return -EIO;
3863 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003864 p = xdr_inline_decode(xdr, 4);
3865 if (unlikely(!p))
3866 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003867 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003869 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003871 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003873out_overflow:
3874 print_overflow_msg(__func__, xdr);
3875 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876}
3877
Trond Myklebust686a8162017-02-19 16:08:32 -05003878static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3879 struct nfs4_string *name, gfp_t gfp_flags)
3880{
3881 ssize_t ret;
3882
3883 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3884 XDR_MAX_NETOBJ, gfp_flags);
3885 name->len = 0;
3886 if (ret > 0)
3887 name->len = ret;
3888 return ret;
3889}
3890
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003891static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003892 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003893 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894{
Trond Myklebust686a8162017-02-19 16:08:32 -05003895 ssize_t len;
3896 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897
Eric W. Biedermane5782072013-02-01 14:22:02 -08003898 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3900 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003901 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3902 return 0;
3903 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3904
3905 if (owner_name != NULL) {
3906 len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
3907 if (len <= 0)
3908 goto out;
3909 dprintk("%s: name=%s\n", __func__, owner_name->data);
3910 return NFS_ATTR_FATTR_OWNER_NAME;
3911 } else {
3912 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3913 XDR_MAX_NETOBJ);
3914 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3915 goto out;
3916 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3917 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003919out:
3920 if (len != -EBADMSG)
3921 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003922 print_overflow_msg(__func__, xdr);
3923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924}
3925
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003926static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003927 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003928 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929{
Trond Myklebust686a8162017-02-19 16:08:32 -05003930 ssize_t len;
3931 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Eric W. Biedermane5782072013-02-01 14:22:02 -08003933 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3935 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003936 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3937 return 0;
3938 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3939
3940 if (group_name != NULL) {
3941 len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
3942 if (len <= 0)
3943 goto out;
3944 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003945 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003946 } else {
3947 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3948 XDR_MAX_NETOBJ);
3949 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3950 goto out;
3951 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3952 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003954out:
3955 if (len != -EBADMSG)
3956 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957 print_overflow_msg(__func__, xdr);
3958 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959}
3960
3961static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3962{
Al Viro8687b632006-10-19 23:28:48 -07003963 uint32_t major = 0, minor = 0;
3964 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003965 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966
3967 *rdev = MKDEV(0,0);
3968 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3969 return -EIO;
3970 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3971 dev_t tmp;
3972
Benny Halevyc0eae662009-08-14 17:20:14 +03003973 p = xdr_inline_decode(xdr, 8);
3974 if (unlikely(!p))
3975 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003976 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003977 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 tmp = MKDEV(major, minor);
3979 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3980 *rdev = tmp;
3981 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003982 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003984 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003985 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003986out_overflow:
3987 print_overflow_msg(__func__, xdr);
3988 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989}
3990
3991static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3992{
Al Viro8687b632006-10-19 23:28:48 -07003993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 int status = 0;
3995
3996 *res = 0;
3997 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3998 return -EIO;
3999 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004000 p = xdr_inline_decode(xdr, 8);
4001 if (unlikely(!p))
4002 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004003 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4005 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004006 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004008out_overflow:
4009 print_overflow_msg(__func__, xdr);
4010 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011}
4012
4013static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4014{
Al Viro8687b632006-10-19 23:28:48 -07004015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 int status = 0;
4017
4018 *res = 0;
4019 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4020 return -EIO;
4021 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004022 p = xdr_inline_decode(xdr, 8);
4023 if (unlikely(!p))
4024 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004025 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4027 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004028 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004030out_overflow:
4031 print_overflow_msg(__func__, xdr);
4032 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033}
4034
4035static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4036{
Al Viro8687b632006-10-19 23:28:48 -07004037 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 int status = 0;
4039
4040 *res = 0;
4041 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4042 return -EIO;
4043 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004044 p = xdr_inline_decode(xdr, 8);
4045 if (unlikely(!p))
4046 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004047 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4049 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004050 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004052out_overflow:
4053 print_overflow_msg(__func__, xdr);
4054 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055}
4056
4057static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4058{
Al Viro8687b632006-10-19 23:28:48 -07004059 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004060 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061
4062 *used = 0;
4063 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4064 return -EIO;
4065 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004066 p = xdr_inline_decode(xdr, 8);
4067 if (unlikely(!p))
4068 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004069 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004071 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004073 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004075 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004076out_overflow:
4077 print_overflow_msg(__func__, xdr);
4078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079}
4080
4081static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4082{
Al Viro8687b632006-10-19 23:28:48 -07004083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 uint64_t sec;
4085 uint32_t nsec;
4086
Benny Halevyc0eae662009-08-14 17:20:14 +03004087 p = xdr_inline_decode(xdr, 12);
4088 if (unlikely(!p))
4089 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004090 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004091 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 time->tv_sec = (time_t)sec;
4093 time->tv_nsec = (long)nsec;
4094 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004095out_overflow:
4096 print_overflow_msg(__func__, xdr);
4097 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098}
4099
4100static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4101{
4102 int status = 0;
4103
4104 time->tv_sec = 0;
4105 time->tv_nsec = 0;
4106 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4107 return -EIO;
4108 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4109 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004110 if (status == 0)
4111 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4113 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004114 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 return status;
4116}
4117
4118static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4119{
4120 int status = 0;
4121
4122 time->tv_sec = 0;
4123 time->tv_nsec = 0;
4124 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4125 return -EIO;
4126 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4127 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004128 if (status == 0)
4129 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4131 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004132 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 return status;
4134}
4135
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004136static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4137 struct timespec *time)
4138{
4139 int status = 0;
4140
4141 time->tv_sec = 0;
4142 time->tv_nsec = 0;
4143 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4144 return -EIO;
4145 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4146 status = decode_attr_time(xdr, time);
4147 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4148 }
4149 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4150 (long)time->tv_nsec);
4151 return status;
4152}
4153
David Quigleyaa9c2662013-05-22 12:50:44 -04004154static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4155 struct nfs4_label *label)
4156{
4157 uint32_t pi = 0;
4158 uint32_t lfs = 0;
4159 __u32 len;
4160 __be32 *p;
4161 int status = 0;
4162
4163 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4164 return -EIO;
4165 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4166 p = xdr_inline_decode(xdr, 4);
4167 if (unlikely(!p))
4168 goto out_overflow;
4169 lfs = be32_to_cpup(p++);
4170 p = xdr_inline_decode(xdr, 4);
4171 if (unlikely(!p))
4172 goto out_overflow;
4173 pi = be32_to_cpup(p++);
4174 p = xdr_inline_decode(xdr, 4);
4175 if (unlikely(!p))
4176 goto out_overflow;
4177 len = be32_to_cpup(p++);
4178 p = xdr_inline_decode(xdr, len);
4179 if (unlikely(!p))
4180 goto out_overflow;
4181 if (len < NFS4_MAXLABELLEN) {
4182 if (label) {
4183 memcpy(label->label, p, len);
4184 label->len = len;
4185 label->pi = pi;
4186 label->lfs = lfs;
4187 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4188 }
4189 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4190 } else
4191 printk(KERN_WARNING "%s: label too long (%u)!\n",
4192 __func__, len);
4193 }
4194 if (label && label->label)
4195 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4196 (char *)label->label, label->len, label->pi, label->lfs);
4197 return status;
4198
4199out_overflow:
4200 print_overflow_msg(__func__, xdr);
4201 return -EIO;
4202}
4203
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4205{
4206 int status = 0;
4207
4208 time->tv_sec = 0;
4209 time->tv_nsec = 0;
4210 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4211 return -EIO;
4212 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4213 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004214 if (status == 0)
4215 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4217 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004218 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 return status;
4220}
4221
Trond Myklebust256e48b2012-06-21 11:18:13 -04004222static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223{
4224 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004225 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226
4227 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004228 dprintk("%s: server returned incorrect attribute length: "
4229 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004230 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 attrwords << 2,
4232 (attrwords < nwords) ? '<' : '>',
4233 nwords << 2);
4234 return -EIO;
4235 }
4236 return 0;
4237}
4238
4239static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4240{
Al Viro8687b632006-10-19 23:28:48 -07004241 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242
Benny Halevyc0eae662009-08-14 17:20:14 +03004243 p = xdr_inline_decode(xdr, 20);
4244 if (unlikely(!p))
4245 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004246 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004247 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004248 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004250out_overflow:
4251 print_overflow_msg(__func__, xdr);
4252 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253}
4254
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004255static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256{
Al Viro8687b632006-10-19 23:28:48 -07004257 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 uint32_t supp, acc;
4259 int status;
4260
4261 status = decode_op_hdr(xdr, OP_ACCESS);
4262 if (status)
4263 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004264 p = xdr_inline_decode(xdr, 8);
4265 if (unlikely(!p))
4266 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004267 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004268 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004269 *supported = supp;
4270 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004272out_overflow:
4273 print_overflow_msg(__func__, xdr);
4274 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275}
4276
Benny Halevy07d30432009-08-14 17:19:52 +03004277static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004279 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4280 if (unlikely(ret < 0)) {
4281 print_overflow_msg(__func__, xdr);
4282 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004283 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004284 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004285}
4286
4287static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4288{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004289 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290}
4291
Trond Myklebust93b717f2016-05-16 17:42:43 -04004292static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4293{
4294 stateid->type = NFS4_OPEN_STATEID_TYPE;
4295 return decode_stateid(xdr, stateid);
4296}
4297
4298static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4299{
4300 stateid->type = NFS4_LOCK_STATEID_TYPE;
4301 return decode_stateid(xdr, stateid);
4302}
4303
4304static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4305{
4306 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4307 return decode_stateid(xdr, stateid);
4308}
4309
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 int status;
4313
4314 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004315 if (status != -EIO)
4316 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004317 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004318 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004319 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320}
4321
Benny Halevydb942bb2009-08-14 17:19:56 +03004322static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4323{
Chuck Levercd937102012-03-02 17:14:31 -05004324 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325}
4326
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004327static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4328{
4329 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4330}
4331
Fred Isaman0b7c0152012-04-20 14:47:39 -04004332static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 int status;
4335
4336 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004337 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004338 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004339 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340}
4341
4342static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4343{
Al Viro8687b632006-10-19 23:28:48 -07004344 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 uint32_t bmlen;
4346 int status;
4347
4348 status = decode_op_hdr(xdr, OP_CREATE);
4349 if (status)
4350 return status;
4351 if ((status = decode_change_info(xdr, cinfo)))
4352 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004353 p = xdr_inline_decode(xdr, 4);
4354 if (unlikely(!p))
4355 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004356 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004357 p = xdr_inline_decode(xdr, bmlen << 2);
4358 if (likely(p))
4359 return 0;
4360out_overflow:
4361 print_overflow_msg(__func__, xdr);
4362 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363}
4364
4365static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4366{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004367 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004368 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 int status;
4370
4371 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4372 goto xdr_error;
4373 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4378 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004379 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4380 &res->fh_expire_type)) != 0)
4381 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4383 goto xdr_error;
4384 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4385 goto xdr_error;
4386 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4387 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004388 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4389 res->exclcreat_bitmask)) != 0)
4390 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 status = verify_attr_len(xdr, savep, attrlen);
4392xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004393 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 return status;
4395}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004396
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4398{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004399 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004400 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004402
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4404 goto xdr_error;
4405 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4406 goto xdr_error;
4407 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4408 goto xdr_error;
4409
4410 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4411 goto xdr_error;
4412 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4413 goto xdr_error;
4414 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4415 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004416
4417 status = -EIO;
4418 if (unlikely(bitmap[0]))
4419 goto xdr_error;
4420
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4422 goto xdr_error;
4423 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4424 goto xdr_error;
4425 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4426 goto xdr_error;
4427
4428 status = verify_attr_len(xdr, savep, attrlen);
4429xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004430 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 return status;
4432}
4433
4434static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4435{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004436 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004437 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004439
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4441 goto xdr_error;
4442 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4443 goto xdr_error;
4444 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4445 goto xdr_error;
4446
4447 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4448 goto xdr_error;
4449 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4450 goto xdr_error;
4451
4452 status = verify_attr_len(xdr, savep, attrlen);
4453xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004454 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 return status;
4456}
4457
Andy Adamson88034c32012-05-23 05:02:34 -04004458static int decode_threshold_hint(struct xdr_stream *xdr,
4459 uint32_t *bitmap,
4460 uint64_t *res,
4461 uint32_t hint_bit)
4462{
4463 __be32 *p;
4464
4465 *res = 0;
4466 if (likely(bitmap[0] & hint_bit)) {
4467 p = xdr_inline_decode(xdr, 8);
4468 if (unlikely(!p))
4469 goto out_overflow;
4470 xdr_decode_hyper(p, res);
4471 }
4472 return 0;
4473out_overflow:
4474 print_overflow_msg(__func__, xdr);
4475 return -EIO;
4476}
4477
4478static int decode_first_threshold_item4(struct xdr_stream *xdr,
4479 struct nfs4_threshold *res)
4480{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004481 __be32 *p;
4482 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004483 uint32_t bitmap[3] = {0,}, attrlen;
4484 int status;
4485
4486 /* layout type */
4487 p = xdr_inline_decode(xdr, 4);
4488 if (unlikely(!p)) {
4489 print_overflow_msg(__func__, xdr);
4490 return -EIO;
4491 }
4492 res->l_type = be32_to_cpup(p);
4493
4494 /* thi_hintset bitmap */
4495 status = decode_attr_bitmap(xdr, bitmap);
4496 if (status < 0)
4497 goto xdr_error;
4498
4499 /* thi_hintlist length */
4500 status = decode_attr_length(xdr, &attrlen, &savep);
4501 if (status < 0)
4502 goto xdr_error;
4503 /* thi_hintlist */
4504 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4505 if (status < 0)
4506 goto xdr_error;
4507 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4508 if (status < 0)
4509 goto xdr_error;
4510 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4511 THRESHOLD_RD_IO);
4512 if (status < 0)
4513 goto xdr_error;
4514 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4515 THRESHOLD_WR_IO);
4516 if (status < 0)
4517 goto xdr_error;
4518
4519 status = verify_attr_len(xdr, savep, attrlen);
4520 res->bm = bitmap[0];
4521
4522 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4523 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4524 res->wr_io_sz);
4525xdr_error:
4526 dprintk("%s ret=%d!\n", __func__, status);
4527 return status;
4528}
4529
4530/*
4531 * Thresholds on pNFS direct I/O vrs MDS I/O
4532 */
4533static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4534 uint32_t *bitmap,
4535 struct nfs4_threshold *res)
4536{
4537 __be32 *p;
4538 int status = 0;
4539 uint32_t num;
4540
4541 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4542 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004543 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004544 /* Did the server return an unrequested attribute? */
4545 if (unlikely(res == NULL))
4546 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004547 p = xdr_inline_decode(xdr, 4);
4548 if (unlikely(!p))
4549 goto out_overflow;
4550 num = be32_to_cpup(p);
4551 if (num == 0)
4552 return 0;
4553 if (num > 1)
4554 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4555 "drivers per filesystem not supported\n",
4556 __func__);
4557
4558 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004559 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004560 }
4561 return status;
4562out_overflow:
4563 print_overflow_msg(__func__, xdr);
4564 return -EIO;
4565}
4566
Bryan Schumakerae42c702010-10-21 16:33:17 -04004567static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4568 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004569 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004570 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571{
Trond Myklebustbca79472009-03-11 14:10:26 -04004572 int status;
4573 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004574 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004575 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577 status = decode_attr_type(xdr, bitmap, &type);
4578 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004580 fattr->mode = 0;
4581 if (status != 0) {
4582 fattr->mode |= nfs_type2fmt[type];
4583 fattr->valid |= status;
4584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004586 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4587 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004589 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004590
4591 status = decode_attr_size(xdr, bitmap, &fattr->size);
4592 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004594 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595
4596 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4597 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004599 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004600
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004601 err = 0;
4602 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004603 if (status < 0)
4604 goto xdr_error;
4605
4606 status = decode_attr_filehandle(xdr, bitmap, fh);
4607 if (status < 0)
4608 goto xdr_error;
4609
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004610 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4611 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004613 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004614
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004615 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004616 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004617 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004618 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004619
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004620 status = -EIO;
4621 if (unlikely(bitmap[0]))
4622 goto xdr_error;
4623
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004624 status = decode_attr_mode(xdr, bitmap, &fmode);
4625 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004627 if (status != 0) {
4628 fattr->mode |= fmode;
4629 fattr->valid |= status;
4630 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004631
4632 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4633 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004635 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004636
Trond Myklebust6926afd2012-01-07 13:22:46 -05004637 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004638 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004640 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641
Trond Myklebust6926afd2012-01-07 13:22:46 -05004642 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004643 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004645 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004646
4647 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4648 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004650 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004651
4652 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4653 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004655 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004656
4657 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4658 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004660 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004661
4662 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4663 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004665 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004666
4667 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4668 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004670 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004671
Trond Myklebust28331a42011-04-27 13:47:52 -04004672 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004673 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004674 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004675 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004676
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004677 status = -EIO;
4678 if (unlikely(bitmap[1]))
4679 goto xdr_error;
4680
Andy Adamson88034c32012-05-23 05:02:34 -04004681 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4682 if (status < 0)
4683 goto xdr_error;
4684
David Quigleyaa9c2662013-05-22 12:50:44 -04004685 if (label) {
4686 status = decode_attr_security_label(xdr, bitmap, label);
4687 if (status < 0)
4688 goto xdr_error;
4689 fattr->valid |= status;
4690 }
4691
Bryan Schumakerae42c702010-10-21 16:33:17 -04004692xdr_error:
4693 dprintk("%s: xdr returned %d\n", __func__, -status);
4694 return status;
4695}
4696
4697static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004698 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004699 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004700{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004701 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004702 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004703 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004704 int status;
4705
4706 status = decode_op_hdr(xdr, OP_GETATTR);
4707 if (status < 0)
4708 goto xdr_error;
4709
4710 status = decode_attr_bitmap(xdr, bitmap);
4711 if (status < 0)
4712 goto xdr_error;
4713
4714 status = decode_attr_length(xdr, &attrlen, &savep);
4715 if (status < 0)
4716 goto xdr_error;
4717
David Quigleyaa9c2662013-05-22 12:50:44 -04004718 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4719 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004720 if (status < 0)
4721 goto xdr_error;
4722
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004723 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004725 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 return status;
4727}
4728
David Quigleyaa9c2662013-05-22 12:50:44 -04004729static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4730 struct nfs4_label *label, const struct nfs_server *server)
4731{
4732 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4733}
4734
Bryan Schumakerae42c702010-10-21 16:33:17 -04004735static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004736 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004737{
David Quigleyaa9c2662013-05-22 12:50:44 -04004738 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004739}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740
Andy Adamson504913f2010-10-20 00:17:57 -04004741/*
Jeff Layton3132e492016-08-10 15:58:24 -04004742 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004743 */
Jeff Layton3132e492016-08-10 15:58:24 -04004744static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004745 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004746{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004747 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004748 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004749
4750 p = xdr_inline_decode(xdr, 4);
4751 if (unlikely(!p))
4752 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004753 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004754
4755 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004756 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004757 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004758
4759 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004760 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004761 if (unlikely(!p))
4762 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004763
4764 /* If we get too many, then just cap it at the max */
4765 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4766 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4767 __func__, fsinfo->nlayouttypes);
4768 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4769 }
4770
4771 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4772 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004773 return 0;
4774out_overflow:
4775 print_overflow_msg(__func__, xdr);
4776 return -EIO;
4777}
4778
4779/*
4780 * The type of file system exported.
4781 * Note we must ensure that layouttype is set in any non-error case.
4782 */
4783static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004784 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004785{
4786 int status = 0;
4787
4788 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4789 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4790 return -EIO;
4791 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004792 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004793 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004794 }
Andy Adamson504913f2010-10-20 00:17:57 -04004795 return status;
4796}
4797
Fred Isamandae100c2011-07-30 20:52:37 -04004798/*
4799 * The prefered block size for layout directed io
4800 */
4801static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4802 uint32_t *res)
4803{
4804 __be32 *p;
4805
4806 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4807 *res = 0;
4808 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4809 p = xdr_inline_decode(xdr, 4);
4810 if (unlikely(!p)) {
4811 print_overflow_msg(__func__, xdr);
4812 return -EIO;
4813 }
4814 *res = be32_to_cpup(p);
4815 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4816 }
4817 return 0;
4818}
4819
Peng Tao2a92ee92015-09-26 02:24:37 +08004820/*
4821 * The granularity of a CLONE operation.
4822 */
4823static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4824 uint32_t *res)
4825{
4826 __be32 *p;
4827
4828 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4829 *res = 0;
4830 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4831 p = xdr_inline_decode(xdr, 4);
4832 if (unlikely(!p)) {
4833 print_overflow_msg(__func__, xdr);
4834 return -EIO;
4835 }
4836 *res = be32_to_cpup(p);
4837 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4838 }
4839 return 0;
4840}
4841
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4843{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004844 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004845 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 int status;
4847
4848 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4849 goto xdr_error;
4850 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4851 goto xdr_error;
4852 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4853 goto xdr_error;
4854
4855 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4856
4857 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4858 goto xdr_error;
4859 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4860 goto xdr_error;
4861 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4862 goto xdr_error;
4863 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4864 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4865 goto xdr_error;
4866 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004867
4868 status = -EIO;
4869 if (unlikely(bitmap[0]))
4870 goto xdr_error;
4871
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004872 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4873 if (status != 0)
4874 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004875 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004876 if (status != 0)
4877 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004878
4879 status = -EIO;
4880 if (unlikely(bitmap[1]))
4881 goto xdr_error;
4882
Fred Isamandae100c2011-07-30 20:52:37 -04004883 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4884 if (status)
4885 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004886 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4887 if (status)
4888 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889
4890 status = verify_attr_len(xdr, savep, attrlen);
4891xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004892 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 return status;
4894}
4895
4896static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4897{
Al Viro8687b632006-10-19 23:28:48 -07004898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 uint32_t len;
4900 int status;
4901
Trond Myklebust99367812007-07-17 21:52:41 -04004902 /* Zero handle first to allow comparisons */
4903 memset(fh, 0, sizeof(*fh));
4904
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 status = decode_op_hdr(xdr, OP_GETFH);
4906 if (status)
4907 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908
Benny Halevyc0eae662009-08-14 17:20:14 +03004909 p = xdr_inline_decode(xdr, 4);
4910 if (unlikely(!p))
4911 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004912 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 if (len > NFS4_FHSIZE)
4914 return -EIO;
4915 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004916 p = xdr_inline_decode(xdr, len);
4917 if (unlikely(!p))
4918 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004919 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004921out_overflow:
4922 print_overflow_msg(__func__, xdr);
4923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924}
4925
4926static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4927{
4928 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004929
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 status = decode_op_hdr(xdr, OP_LINK);
4931 if (status)
4932 return status;
4933 return decode_change_info(xdr, cinfo);
4934}
4935
4936/*
4937 * We create the owner, so we know a proper owner.id length is 4.
4938 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004939static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004941 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004942 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004943 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004945 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004946 if (unlikely(!p))
4947 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004948 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004949 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004950 type = be32_to_cpup(p++); /* 4 byte read */
4951 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004952 fl->fl_start = (loff_t)offset;
4953 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4954 if (length == ~(uint64_t)0)
4955 fl->fl_end = OFFSET_MAX;
4956 fl->fl_type = F_WRLCK;
4957 if (type & 1)
4958 fl->fl_type = F_RDLCK;
4959 fl->fl_pid = 0;
4960 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004961 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4962 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4963 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004964 if (likely(p))
4965 return -NFS4ERR_DENIED;
4966out_overflow:
4967 print_overflow_msg(__func__, xdr);
4968 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969}
4970
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004971static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 int status;
4974
4975 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004976 if (status == -EIO)
4977 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004979 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004980 if (unlikely(status))
4981 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004983 status = decode_lock_denied(xdr, NULL);
4984 if (res->open_seqid != NULL)
4985 nfs_increment_open_seqid(status, res->open_seqid);
4986 nfs_increment_lock_seqid(status, res->lock_seqid);
4987out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 return status;
4989}
4990
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004991static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992{
4993 int status;
4994 status = decode_op_hdr(xdr, OP_LOCKT);
4995 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004996 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 return status;
4998}
4999
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005000static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 int status;
5003
5004 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005005 if (status != -EIO)
5006 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005007 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005008 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 return status;
5010}
5011
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005012static int decode_release_lockowner(struct xdr_stream *xdr)
5013{
5014 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5015}
5016
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017static int decode_lookup(struct xdr_stream *xdr)
5018{
5019 return decode_op_hdr(xdr, OP_LOOKUP);
5020}
5021
5022/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005023static int decode_space_limit(struct xdr_stream *xdr,
5024 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025{
Andy Adamson05d564f2008-12-23 16:06:15 -05005026 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005028 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029
Benny Halevyc0eae662009-08-14 17:20:14 +03005030 p = xdr_inline_decode(xdr, 12);
5031 if (unlikely(!p))
5032 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005033 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005035 case NFS4_LIMIT_SIZE:
5036 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005037 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005038 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005039 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005040 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005041 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005043 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005044 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005046out_overflow:
5047 print_overflow_msg(__func__, xdr);
5048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049}
5050
Trond Myklebust6ae37332015-01-30 14:21:14 -05005051static int decode_rw_delegation(struct xdr_stream *xdr,
5052 uint32_t delegation_type,
5053 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054{
Andy Adamson05d564f2008-12-23 16:06:15 -05005055 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005056 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057
Trond Myklebust93b717f2016-05-16 17:42:43 -04005058 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005059 if (unlikely(status))
5060 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005061 p = xdr_inline_decode(xdr, 4);
5062 if (unlikely(!p))
5063 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005064 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005065
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005067 case NFS4_OPEN_DELEGATE_READ:
5068 res->delegation_type = FMODE_READ;
5069 break;
5070 case NFS4_OPEN_DELEGATE_WRITE:
5071 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005072 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 return -EIO;
5074 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005075 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005076out_overflow:
5077 print_overflow_msg(__func__, xdr);
5078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079}
5080
Trond Myklebust6ae37332015-01-30 14:21:14 -05005081static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5082{
5083 __be32 *p;
5084 uint32_t why_no_delegation;
5085
5086 p = xdr_inline_decode(xdr, 4);
5087 if (unlikely(!p))
5088 goto out_overflow;
5089 why_no_delegation = be32_to_cpup(p);
5090 switch (why_no_delegation) {
5091 case WND4_CONTENTION:
5092 case WND4_RESOURCE:
5093 xdr_inline_decode(xdr, 4);
5094 /* Ignore for now */
5095 }
5096 return 0;
5097out_overflow:
5098 print_overflow_msg(__func__, xdr);
5099 return -EIO;
5100}
5101
5102static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5103{
5104 __be32 *p;
5105 uint32_t delegation_type;
5106
5107 p = xdr_inline_decode(xdr, 4);
5108 if (unlikely(!p))
5109 goto out_overflow;
5110 delegation_type = be32_to_cpup(p);
5111 res->delegation_type = 0;
5112 switch (delegation_type) {
5113 case NFS4_OPEN_DELEGATE_NONE:
5114 return 0;
5115 case NFS4_OPEN_DELEGATE_READ:
5116 case NFS4_OPEN_DELEGATE_WRITE:
5117 return decode_rw_delegation(xdr, delegation_type, res);
5118 case NFS4_OPEN_DELEGATE_NONE_EXT:
5119 return decode_no_delegation(xdr, res);
5120 }
5121 return -EIO;
5122out_overflow:
5123 print_overflow_msg(__func__, xdr);
5124 return -EIO;
5125}
5126
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5128{
Andy Adamson05d564f2008-12-23 16:06:15 -05005129 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005130 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005131 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
Trond Myklebustc7848f62013-12-04 17:39:23 -05005133 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5134 return status;
5135 nfs_increment_open_seqid(status, res->seqid);
5136 if (status)
5137 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005138 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005139 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005140 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141
Andy Adamson05d564f2008-12-23 16:06:15 -05005142 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143
Benny Halevyc0eae662009-08-14 17:20:14 +03005144 p = xdr_inline_decode(xdr, 8);
5145 if (unlikely(!p))
5146 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005147 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005148 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005149 if (bmlen > 10)
5150 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151
Benny Halevyc0eae662009-08-14 17:20:14 +03005152 p = xdr_inline_decode(xdr, bmlen << 2);
5153 if (unlikely(!p))
5154 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005155 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5156 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005157 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005158 for (; i < NFS4_BITMAP_SIZE; i++)
5159 res->attrset[i] = 0;
5160
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 return decode_delegation(xdr, res);
5162xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005163 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005165out_overflow:
5166 print_overflow_msg(__func__, xdr);
5167 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168}
5169
5170static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 int status;
5173
Andy Adamson05d564f2008-12-23 16:06:15 -05005174 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005175 if (status != -EIO)
5176 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005177 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005178 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005179 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180}
5181
5182static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 int status;
5185
5186 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005187 if (status != -EIO)
5188 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005189 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005190 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005191 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192}
5193
5194static int decode_putfh(struct xdr_stream *xdr)
5195{
5196 return decode_op_hdr(xdr, OP_PUTFH);
5197}
5198
5199static int decode_putrootfh(struct xdr_stream *xdr)
5200{
5201 return decode_op_hdr(xdr, OP_PUTROOTFH);
5202}
5203
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005204static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5205 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206{
Al Viro8687b632006-10-19 23:28:48 -07005207 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005208 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 int status;
5210
5211 status = decode_op_hdr(xdr, OP_READ);
5212 if (status)
5213 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005214 p = xdr_inline_decode(xdr, 8);
5215 if (unlikely(!p))
5216 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005217 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005218 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005219 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005221 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 "count %u > recvd %u\n", count, recvd);
5223 count = recvd;
5224 eof = 0;
5225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 res->eof = eof;
5227 res->count = count;
5228 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005229out_overflow:
5230 print_overflow_msg(__func__, xdr);
5231 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232}
5233
5234static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5235{
Chuck Leverbcecff72007-10-26 13:32:03 -04005236 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005237 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238
5239 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005240 if (!status)
5241 status = decode_verifier(xdr, readdir->verifier.data);
5242 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005244 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005245 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005246 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005247 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248}
5249
5250static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5251{
5252 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005253 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005254 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255 int status;
5256
5257 status = decode_op_hdr(xdr, OP_READLINK);
5258 if (status)
5259 return status;
5260
5261 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005262 p = xdr_inline_decode(xdr, 4);
5263 if (unlikely(!p))
5264 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005265 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005267 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 return -ENAMETOOLONG;
5269 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005270 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005272 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 "count %u > recvd %u\n", len, recvd);
5274 return -EIO;
5275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 /*
5277 * The XDR encode routine has set things up so that
5278 * the link text will be copied directly into the
5279 * buffer. We just have to do overflow-checking,
5280 * and and null-terminate the text (the VFS expects
5281 * null-termination).
5282 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005283 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005285out_overflow:
5286 print_overflow_msg(__func__, xdr);
5287 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288}
5289
5290static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5291{
5292 int status;
5293
5294 status = decode_op_hdr(xdr, OP_REMOVE);
5295 if (status)
5296 goto out;
5297 status = decode_change_info(xdr, cinfo);
5298out:
5299 return status;
5300}
5301
5302static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5303 struct nfs4_change_info *new_cinfo)
5304{
5305 int status;
5306
5307 status = decode_op_hdr(xdr, OP_RENAME);
5308 if (status)
5309 goto out;
5310 if ((status = decode_change_info(xdr, old_cinfo)))
5311 goto out;
5312 status = decode_change_info(xdr, new_cinfo);
5313out:
5314 return status;
5315}
5316
5317static int decode_renew(struct xdr_stream *xdr)
5318{
5319 return decode_op_hdr(xdr, OP_RENEW);
5320}
5321
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005322static int
5323decode_restorefh(struct xdr_stream *xdr)
5324{
5325 return decode_op_hdr(xdr, OP_RESTOREFH);
5326}
5327
J. Bruce Fields029d1052005-06-22 17:16:22 +00005328static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005329 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005330{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005331 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005332 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005333 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005334 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005335 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005336
Andy Adamsonbf118a32011-12-07 11:55:27 -05005337 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005338 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5339 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005340
Trond Myklebust519d3952012-08-14 17:30:10 -04005341 xdr_enter_page(xdr, xdr->buf->page_len);
5342
Trond Myklebustcff298c2012-08-14 17:14:17 -04005343 /* Calculate the offset of the page data */
5344 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005345
J. Bruce Fields029d1052005-06-22 17:16:22 +00005346 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5347 goto out;
5348 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5349 goto out;
5350
5351 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5352 return -EIO;
5353 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005354
Andy Adamsonbf118a32011-12-07 11:55:27 -05005355 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5356 * are stored with the acl data to handle the problem of
5357 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005358 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005359 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005360
5361 /* Check for receive buffer overflow */
5362 if (res->acl_len > (xdr->nwords << 2) ||
5363 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5364 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005365 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005366 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005367 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005368 } else
5369 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005370
5371out:
5372 return status;
5373}
5374
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375static int
5376decode_savefh(struct xdr_stream *xdr)
5377{
5378 return decode_op_hdr(xdr, OP_SAVEFH);
5379}
5380
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005381static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382{
Al Viro8687b632006-10-19 23:28:48 -07005383 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 uint32_t bmlen;
5385 int status;
5386
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387 status = decode_op_hdr(xdr, OP_SETATTR);
5388 if (status)
5389 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005390 p = xdr_inline_decode(xdr, 4);
5391 if (unlikely(!p))
5392 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005393 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005394 p = xdr_inline_decode(xdr, bmlen << 2);
5395 if (likely(p))
5396 return 0;
5397out_overflow:
5398 print_overflow_msg(__func__, xdr);
5399 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400}
5401
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005402static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403{
Al Viro8687b632006-10-19 23:28:48 -07005404 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 uint32_t opnum;
5406 int32_t nfserr;
5407
Benny Halevyc0eae662009-08-14 17:20:14 +03005408 p = xdr_inline_decode(xdr, 8);
5409 if (unlikely(!p))
5410 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005411 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005413 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005414 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415 return -EIO;
5416 }
Benny Halevycccddf42009-08-14 17:20:19 +03005417 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005419 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5420 if (unlikely(!p))
5421 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005422 p = xdr_decode_hyper(p, &res->clientid);
5423 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424 } else if (nfserr == NFSERR_CLID_INUSE) {
5425 uint32_t len;
5426
5427 /* skip netid 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
5436 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005437 p = xdr_inline_decode(xdr, 4);
5438 if (unlikely(!p))
5439 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005440 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005441 p = xdr_inline_decode(xdr, len);
5442 if (unlikely(!p))
5443 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 return -NFSERR_CLID_INUSE;
5445 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005446 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447
5448 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005449out_overflow:
5450 print_overflow_msg(__func__, xdr);
5451 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452}
5453
5454static int decode_setclientid_confirm(struct xdr_stream *xdr)
5455{
5456 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5457}
5458
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005459static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460{
Al Viro8687b632006-10-19 23:28:48 -07005461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462 int status;
5463
5464 status = decode_op_hdr(xdr, OP_WRITE);
5465 if (status)
5466 return status;
5467
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005468 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005469 if (unlikely(!p))
5470 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005471 res->count = be32_to_cpup(p++);
5472 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005473 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005474out_overflow:
5475 print_overflow_msg(__func__, xdr);
5476 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477}
5478
5479static int decode_delegreturn(struct xdr_stream *xdr)
5480{
5481 return decode_op_hdr(xdr, OP_DELEGRETURN);
5482}
5483
Chuck Leverfb15b262013-03-16 15:54:34 -04005484static int decode_secinfo_gss(struct xdr_stream *xdr,
5485 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005486{
Chuck Leverfb15b262013-03-16 15:54:34 -04005487 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005488 __be32 *p;
5489
5490 p = xdr_inline_decode(xdr, 4);
5491 if (unlikely(!p))
5492 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005493 oid_len = be32_to_cpup(p);
5494 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005495 goto out_err;
5496
Chuck Leverfb15b262013-03-16 15:54:34 -04005497 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005498 if (unlikely(!p))
5499 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005500 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5501 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005502
5503 p = xdr_inline_decode(xdr, 8);
5504 if (unlikely(!p))
5505 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005506 flavor->flavor_info.qop = be32_to_cpup(p++);
5507 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005508
5509 return 0;
5510
5511out_overflow:
5512 print_overflow_msg(__func__, xdr);
5513 return -EIO;
5514out_err:
5515 return -EINVAL;
5516}
5517
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005518static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005519{
Chuck Leverfb15b262013-03-16 15:54:34 -04005520 struct nfs4_secinfo4 *sec_flavor;
5521 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005522 int status;
5523 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005524
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005525 p = xdr_inline_decode(xdr, 4);
5526 if (unlikely(!p))
5527 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005528
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005529 res->flavors->num_flavors = 0;
5530 num_flavors = be32_to_cpup(p);
5531
5532 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005533 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005534 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005535 break;
5536
5537 p = xdr_inline_decode(xdr, 4);
5538 if (unlikely(!p))
5539 goto out_overflow;
5540 sec_flavor->flavor = be32_to_cpup(p);
5541
5542 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005543 status = decode_secinfo_gss(xdr, sec_flavor);
5544 if (status)
5545 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005546 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005547 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005548 }
5549
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005550 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005551out:
5552 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005553out_overflow:
5554 print_overflow_msg(__func__, xdr);
5555 return -EIO;
5556}
5557
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005558static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5559{
5560 int status = decode_op_hdr(xdr, OP_SECINFO);
5561 if (status)
5562 return status;
5563 return decode_secinfo_common(xdr, res);
5564}
5565
Benny Halevy99fe60d2009-04-01 09:22:29 -04005566#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005567static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5568{
5569 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5570 if (status)
5571 return status;
5572 return decode_secinfo_common(xdr, res);
5573}
5574
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005575static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5576{
5577 __be32 *p;
5578 uint32_t bitmap_words;
5579 unsigned int i;
5580
5581 p = xdr_inline_decode(xdr, 4);
5582 bitmap_words = be32_to_cpup(p++);
5583 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5584 return -EIO;
5585 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5586 for (i = 0; i < bitmap_words; i++)
5587 op_map->u.words[i] = be32_to_cpup(p++);
5588
5589 return 0;
5590}
5591
Benny Halevy99fe60d2009-04-01 09:22:29 -04005592static int decode_exchange_id(struct xdr_stream *xdr,
5593 struct nfs41_exchange_id_res *res)
5594{
5595 __be32 *p;
5596 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005597 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005598 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005599 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005600
5601 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5602 if (status)
5603 return status;
5604
Benny Halevyc0eae662009-08-14 17:20:14 +03005605 p = xdr_inline_decode(xdr, 8);
5606 if (unlikely(!p))
5607 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005608 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005609 p = xdr_inline_decode(xdr, 12);
5610 if (unlikely(!p))
5611 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005612 res->seqid = be32_to_cpup(p++);
5613 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005614
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005615 res->state_protect.how = be32_to_cpup(p);
5616 switch (res->state_protect.how) {
5617 case SP4_NONE:
5618 break;
5619 case SP4_MACH_CRED:
5620 status = decode_op_map(xdr, &res->state_protect.enforce);
5621 if (status)
5622 return status;
5623 status = decode_op_map(xdr, &res->state_protect.allow);
5624 if (status)
5625 return status;
5626 break;
5627 default:
5628 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005629 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005630 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005631
Chuck Leveracdeb692012-05-21 22:46:16 -04005632 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005633 p = xdr_inline_decode(xdr, 8);
5634 if (unlikely(!p))
5635 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005636 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005637
Chuck Leveracdeb692012-05-21 22:46:16 -04005638 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005639 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5640 if (unlikely(status))
5641 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005642 memcpy(res->server_owner->major_id, dummy_str, dummy);
5643 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005644
Chuck Leveracdeb692012-05-21 22:46:16 -04005645 /* server_scope4 */
5646 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5647 if (unlikely(status))
5648 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005649 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5650 res->server_scope->server_scope_sz = dummy;
5651
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005652 /* Implementation Id */
5653 p = xdr_inline_decode(xdr, 4);
5654 if (unlikely(!p))
5655 goto out_overflow;
5656 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005657
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005658 if (impl_id_count) {
5659 /* nii_domain */
5660 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5661 if (unlikely(status))
5662 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005663 memcpy(res->impl_id->domain, dummy_str, dummy);
5664
5665 /* nii_name */
5666 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5667 if (unlikely(status))
5668 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005669 memcpy(res->impl_id->name, dummy_str, dummy);
5670
5671 /* nii_date */
5672 p = xdr_inline_decode(xdr, 12);
5673 if (unlikely(!p))
5674 goto out_overflow;
5675 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5676 res->impl_id->date.nseconds = be32_to_cpup(p);
5677
5678 /* if there's more than one entry, ignore the rest */
5679 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005680 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005681out_overflow:
5682 print_overflow_msg(__func__, xdr);
5683 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005684}
Andy Adamsonfc931582009-04-01 09:22:31 -04005685
5686static int decode_chan_attrs(struct xdr_stream *xdr,
5687 struct nfs4_channel_attrs *attrs)
5688{
5689 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005690 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005691
Benny Halevyc0eae662009-08-14 17:20:14 +03005692 p = xdr_inline_decode(xdr, 28);
5693 if (unlikely(!p))
5694 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005695 val = be32_to_cpup(p++); /* headerpadsz */
5696 if (val)
5697 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005698 attrs->max_rqst_sz = be32_to_cpup(p++);
5699 attrs->max_resp_sz = be32_to_cpup(p++);
5700 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5701 attrs->max_ops = be32_to_cpup(p++);
5702 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005703 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005704 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005705 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5706 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005707 return -EINVAL;
5708 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005709 if (nr_attrs == 1) {
5710 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5711 if (unlikely(!p))
5712 goto out_overflow;
5713 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005714 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005715out_overflow:
5716 print_overflow_msg(__func__, xdr);
5717 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005718}
5719
Benny Halevye78291e2009-08-14 17:20:00 +03005720static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5721{
5722 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005723}
5724
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005725static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5726 struct nfs41_bind_conn_to_session_res *res)
5727{
5728 __be32 *p;
5729 int status;
5730
5731 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5732 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005733 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005734 if (unlikely(status))
5735 return status;
5736
5737 /* dir flags, rdma mode bool */
5738 p = xdr_inline_decode(xdr, 8);
5739 if (unlikely(!p))
5740 goto out_overflow;
5741
5742 res->dir = be32_to_cpup(p++);
5743 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5744 return -EIO;
5745 if (be32_to_cpup(p) == 0)
5746 res->use_conn_in_rdma_mode = false;
5747 else
5748 res->use_conn_in_rdma_mode = true;
5749
5750 return 0;
5751out_overflow:
5752 print_overflow_msg(__func__, xdr);
5753 return -EIO;
5754}
5755
Andy Adamsonfc931582009-04-01 09:22:31 -04005756static int decode_create_session(struct xdr_stream *xdr,
5757 struct nfs41_create_session_res *res)
5758{
5759 __be32 *p;
5760 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005761
5762 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005763 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005764 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005765 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005766 return status;
5767
Andy Adamsonfc931582009-04-01 09:22:31 -04005768 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005769 p = xdr_inline_decode(xdr, 8);
5770 if (unlikely(!p))
5771 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005772 res->seqid = be32_to_cpup(p++);
5773 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005774
5775 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005776 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005777 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005778 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005779 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005780out_overflow:
5781 print_overflow_msg(__func__, xdr);
5782 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005783}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005784
5785static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5786{
5787 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5788}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005789
Trond Myklebust66245532012-05-25 17:18:09 -04005790static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5791{
5792 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5793}
5794
Ricardo Labiaga180197532009-12-05 16:08:40 -05005795static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5796{
5797 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5798}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005799#endif /* CONFIG_NFS_V4_1 */
5800
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005801static int decode_sequence(struct xdr_stream *xdr,
5802 struct nfs4_sequence_res *res,
5803 struct rpc_rqst *rqstp)
5804{
5805#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005806 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005807 struct nfs4_sessionid id;
5808 u32 dummy;
5809 int status;
5810 __be32 *p;
5811
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005812 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005813 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005814 if (!res->sr_slot->table->session)
5815 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005816
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005817 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005818 if (!status)
5819 status = decode_sessionid(xdr, &id);
5820 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005821 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005822
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005823 /*
5824 * If the server returns different values for sessionID, slotID or
5825 * sequence number, the server is looney tunes.
5826 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005827 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005828 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005829
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005830 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005831 NFS4_MAX_SESSIONID_LEN)) {
5832 dprintk("%s Invalid session id\n", __func__);
5833 goto out_err;
5834 }
Benny Halevye78291e2009-08-14 17:20:00 +03005835
Benny Halevyc0eae662009-08-14 17:20:14 +03005836 p = xdr_inline_decode(xdr, 20);
5837 if (unlikely(!p))
5838 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005839
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005840 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005841 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005842 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005843 dprintk("%s Invalid sequence number\n", __func__);
5844 goto out_err;
5845 }
5846 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005847 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005848 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005849 dprintk("%s Invalid slot id\n", __func__);
5850 goto out_err;
5851 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005852 /* highest slot id */
5853 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005854 /* target highest slot id */
5855 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005856 /* result flags */
5857 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005858 status = 0;
5859out_err:
5860 res->sr_status = status;
5861 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005862out_overflow:
5863 print_overflow_msg(__func__, xdr);
5864 status = -EIO;
5865 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005866#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005867 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005868#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005869}
5870
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005871#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005872static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5873{
5874 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5875 return decode_stateid(xdr, stateid);
5876}
5877
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005878static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005879 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005880{
Trond Myklebust4e590802015-03-09 14:01:25 -04005881 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005882 __be32 *p;
5883 uint32_t len, type;
5884 int status;
5885
5886 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5887 if (status) {
5888 if (status == -ETOOSMALL) {
5889 p = xdr_inline_decode(xdr, 4);
5890 if (unlikely(!p))
5891 goto out_overflow;
5892 pdev->mincount = be32_to_cpup(p);
5893 dprintk("%s: Min count too small. mincnt = %u\n",
5894 __func__, pdev->mincount);
5895 }
5896 return status;
5897 }
5898
5899 p = xdr_inline_decode(xdr, 8);
5900 if (unlikely(!p))
5901 goto out_overflow;
5902 type = be32_to_cpup(p++);
5903 if (type != pdev->layout_type) {
5904 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5905 __func__, pdev->layout_type, type);
5906 return -EINVAL;
5907 }
5908 /*
5909 * Get the length of the opaque device_addr4. xdr_read_pages places
5910 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5911 * and places the remaining xdr data in xdr_buf->tail
5912 */
5913 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005914 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5915 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005916
5917 /* Parse notification bitmap, verifying that it is zero. */
5918 p = xdr_inline_decode(xdr, 4);
5919 if (unlikely(!p))
5920 goto out_overflow;
5921 len = be32_to_cpup(p);
5922 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005923 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005924
5925 p = xdr_inline_decode(xdr, 4 * len);
5926 if (unlikely(!p))
5927 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005928
Trond Myklebust4e590802015-03-09 14:01:25 -04005929 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005930 for (i = 1; i < len; i++) {
5931 if (be32_to_cpup(p++)) {
5932 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005933 __func__);
5934 return -EIO;
5935 }
5936 }
5937 }
5938 return 0;
5939out_overflow:
5940 print_overflow_msg(__func__, xdr);
5941 return -EIO;
5942}
5943
5944static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5945 struct nfs4_layoutget_res *res)
5946{
5947 __be32 *p;
5948 int status;
5949 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005950 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005951
5952 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5953 if (status)
5954 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005955 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005956 if (unlikely(!p))
5957 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005958 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005959 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005960 p = xdr_inline_decode(xdr, 4);
5961 if (unlikely(!p))
5962 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005963 layout_count = be32_to_cpup(p);
5964 if (!layout_count) {
5965 dprintk("%s: server responded with empty layout array\n",
5966 __func__);
5967 return -EINVAL;
5968 }
5969
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005970 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005971 if (unlikely(!p))
5972 goto out_overflow;
5973 p = xdr_decode_hyper(p, &res->range.offset);
5974 p = xdr_decode_hyper(p, &res->range.length);
5975 res->range.iomode = be32_to_cpup(p++);
5976 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005977 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005978
5979 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5980 __func__,
5981 (unsigned long)res->range.offset,
5982 (unsigned long)res->range.length,
5983 res->range.iomode,
5984 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005985 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005986
Trond Myklebust64bd5772012-06-20 22:35:05 -04005987 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005988 if (res->layoutp->len > recvd) {
5989 dprintk("NFS: server cheating in layoutget reply: "
5990 "layout len %u > recvd %u\n",
5991 res->layoutp->len, recvd);
5992 return -EINVAL;
5993 }
5994
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005995 if (layout_count > 1) {
5996 /* We only handle a length one array at the moment. Any
5997 * further entries are just ignored. Note that this means
5998 * the client may see a response that is less than the
5999 * minimum it requested.
6000 */
6001 dprintk("%s: server responded with %d layouts, dropping tail\n",
6002 __func__, layout_count);
6003 }
6004
6005 return 0;
6006out_overflow:
6007 print_overflow_msg(__func__, xdr);
6008 return -EIO;
6009}
Andy Adamson863a3c62011-03-23 13:27:54 +00006010
Benny Halevycbe82602011-05-22 19:52:37 +03006011static int decode_layoutreturn(struct xdr_stream *xdr,
6012 struct nfs4_layoutreturn_res *res)
6013{
6014 __be32 *p;
6015 int status;
6016
6017 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6018 if (status)
6019 return status;
6020 p = xdr_inline_decode(xdr, 4);
6021 if (unlikely(!p))
6022 goto out_overflow;
6023 res->lrs_present = be32_to_cpup(p);
6024 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006025 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006026 return status;
6027out_overflow:
6028 print_overflow_msg(__func__, xdr);
6029 return -EIO;
6030}
6031
Andy Adamson863a3c62011-03-23 13:27:54 +00006032static int decode_layoutcommit(struct xdr_stream *xdr,
6033 struct rpc_rqst *req,
6034 struct nfs4_layoutcommit_res *res)
6035{
6036 __be32 *p;
6037 __u32 sizechanged;
6038 int status;
6039
6040 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006041 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006042 if (status)
6043 return status;
6044
6045 p = xdr_inline_decode(xdr, 4);
6046 if (unlikely(!p))
6047 goto out_overflow;
6048 sizechanged = be32_to_cpup(p);
6049
6050 if (sizechanged) {
6051 /* throw away new size */
6052 p = xdr_inline_decode(xdr, 8);
6053 if (unlikely(!p))
6054 goto out_overflow;
6055 }
6056 return 0;
6057out_overflow:
6058 print_overflow_msg(__func__, xdr);
6059 return -EIO;
6060}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006061
6062static int decode_test_stateid(struct xdr_stream *xdr,
6063 struct nfs41_test_stateid_res *res)
6064{
6065 __be32 *p;
6066 int status;
6067 int num_res;
6068
6069 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6070 if (status)
6071 return status;
6072
6073 p = xdr_inline_decode(xdr, 4);
6074 if (unlikely(!p))
6075 goto out_overflow;
6076 num_res = be32_to_cpup(p++);
6077 if (num_res != 1)
6078 goto out;
6079
6080 p = xdr_inline_decode(xdr, 4);
6081 if (unlikely(!p))
6082 goto out_overflow;
6083 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006084
6085 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006086out_overflow:
6087 print_overflow_msg(__func__, xdr);
6088out:
6089 return -EIO;
6090}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006091
6092static int decode_free_stateid(struct xdr_stream *xdr,
6093 struct nfs41_free_stateid_res *res)
6094{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006095 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006096 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006097}
Trond Myklebustcf805162016-11-15 14:56:07 -05006098#else
6099static inline
6100int decode_layoutreturn(struct xdr_stream *xdr,
6101 struct nfs4_layoutreturn_res *res)
6102{
6103 return 0;
6104}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006105#endif /* CONFIG_NFS_V4_1 */
6106
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107/*
Benny Halevy49c25592008-12-23 16:06:16 -05006108 * END OF "GENERIC" DECODE ROUTINES.
6109 */
6110
6111/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 * Decode OPEN_DOWNGRADE response
6113 */
Chuck Leverbf269552010-12-14 14:59:29 +00006114static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6115 struct xdr_stream *xdr,
6116 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117{
Andy Adamson05d564f2008-12-23 16:06:15 -05006118 struct compound_hdr hdr;
6119 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006122 if (status)
6123 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006125 if (status)
6126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006128 if (status)
6129 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006130 if (res->lr_res) {
6131 status = decode_layoutreturn(xdr, res->lr_res);
6132 res->lr_ret = status;
6133 if (status)
6134 goto out;
6135 }
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006138 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139}
6140
6141/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 * Decode ACCESS response
6143 */
Chuck Leverbf269552010-12-14 14:59:29 +00006144static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6145 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 struct compound_hdr hdr;
6148 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006149
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006151 if (status)
6152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006157 if (status != 0)
6158 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006159 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006160 if (status != 0)
6161 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006162 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163out:
6164 return status;
6165}
6166
6167/*
6168 * Decode LOOKUP response
6169 */
Chuck Leverbf269552010-12-14 14:59:29 +00006170static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6171 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 struct compound_hdr hdr;
6174 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006175
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006177 if (status)
6178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006180 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_putfh(xdr);
6183 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_lookup(xdr);
6186 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_getfh(xdr, res->fh);
6189 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006191 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192out:
6193 return status;
6194}
6195
6196/*
6197 * Decode LOOKUP_ROOT response
6198 */
Chuck Leverbf269552010-12-14 14:59:29 +00006199static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6200 struct xdr_stream *xdr,
6201 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 struct compound_hdr hdr;
6204 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006205
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006207 if (status)
6208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006210 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_putrootfh(xdr);
6213 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_getfh(xdr, res->fh);
6216 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006217 status = decode_getfattr_label(xdr, res->fattr,
6218 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219out:
6220 return status;
6221}
6222
6223/*
6224 * Decode REMOVE response
6225 */
Chuck Leverbf269552010-12-14 14:59:29 +00006226static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 struct compound_hdr hdr;
6230 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006231
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006233 if (status)
6234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_putfh(xdr);
6239 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242out:
6243 return status;
6244}
6245
6246/*
6247 * Decode RENAME response
6248 */
Chuck Leverbf269552010-12-14 14:59:29 +00006249static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6250 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 struct compound_hdr hdr;
6253 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006254
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_putfh(xdr);
6262 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_savefh(xdr);
6265 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_putfh(xdr);
6268 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271out:
6272 return status;
6273}
6274
6275/*
6276 * Decode LINK response
6277 */
Chuck Leverbf269552010-12-14 14:59:29 +00006278static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 struct compound_hdr hdr;
6282 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006283
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006288 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_putfh(xdr);
6291 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_savefh(xdr);
6294 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_putfh(xdr);
6297 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_link(xdr, &res->cinfo);
6300 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006301 goto out;
6302 /*
6303 * Note order: OP_LINK leaves the directory as the current
6304 * filehandle.
6305 */
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_restorefh(xdr);
6307 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006308 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006309 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310out:
6311 return status;
6312}
6313
6314/*
6315 * Decode CREATE response
6316 */
Chuck Leverbf269552010-12-14 14:59:29 +00006317static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6318 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320 struct compound_hdr hdr;
6321 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006322
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006324 if (status)
6325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006327 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_putfh(xdr);
6330 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_create(xdr, &res->dir_cinfo);
6333 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_getfh(xdr, res->fh);
6336 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006338 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339out:
6340 return status;
6341}
6342
6343/*
6344 * Decode SYMLINK response
6345 */
Chuck Leverbf269552010-12-14 14:59:29 +00006346static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6347 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348{
Chuck Leverbf269552010-12-14 14:59:29 +00006349 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350}
6351
6352/*
6353 * Decode GETATTR response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006370 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371out:
6372 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373}
6374
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006375/*
6376 * Encode an SETACL request
6377 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006378static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6379 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006380{
Andy Adamson05d564f2008-12-23 16:06:15 -05006381 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006382 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006383 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006384
Chuck Lever9f06c712010-12-14 14:59:18 +00006385 encode_compound_hdr(xdr, req, &hdr);
6386 encode_sequence(xdr, &args->seq_args, &hdr);
6387 encode_putfh(xdr, args->fh, &hdr);
6388 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006389 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006390}
Andy Adamson05d564f2008-12-23 16:06:15 -05006391
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006392/*
6393 * Decode SETACL response
6394 */
6395static int
Chuck Leverbf269552010-12-14 14:59:29 +00006396nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006397 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006398{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006399 struct compound_hdr hdr;
6400 int status;
6401
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006403 if (status)
6404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006406 if (status)
6407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006409 if (status)
6410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006412out:
6413 return status;
6414}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415
6416/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006417 * Decode GETACL response
6418 */
6419static int
Chuck Leverbf269552010-12-14 14:59:29 +00006420nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006421 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006422{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006423 struct compound_hdr hdr;
6424 int status;
6425
Trond Myklebust331818f2012-02-03 18:30:53 -05006426 if (res->acl_scratch != NULL) {
6427 void *p = page_address(res->acl_scratch);
6428 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6429 }
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006434 if (status)
6435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006437 if (status)
6438 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006439 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006440
6441out:
6442 return status;
6443}
6444
6445/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 * Decode CLOSE response
6447 */
Chuck Leverbf269552010-12-14 14:59:29 +00006448static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6449 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450{
Andy Adamson05d564f2008-12-23 16:06:15 -05006451 struct compound_hdr hdr;
6452 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006455 if (status)
6456 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006458 if (status)
6459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006461 if (status)
6462 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006463 if (res->lr_res) {
6464 status = decode_layoutreturn(xdr, res->lr_res);
6465 res->lr_ret = status;
6466 if (status)
6467 goto out;
6468 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006469 if (res->fattr != NULL) {
6470 status = decode_getfattr(xdr, res->fattr, res->server);
6471 if (status != 0)
6472 goto out;
6473 }
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006476 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477}
6478
6479/*
6480 * Decode OPEN response
6481 */
Chuck Leverbf269552010-12-14 14:59:29 +00006482static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6483 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484{
Andy Adamson05d564f2008-12-23 16:06:15 -05006485 struct compound_hdr hdr;
6486 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006489 if (status)
6490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006492 if (status)
6493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006498 if (status)
6499 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006500 status = decode_getfh(xdr, &res->fh);
6501 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006503 if (res->access_request)
6504 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006505 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006507 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508}
6509
6510/*
6511 * Decode OPEN_CONFIRM response
6512 */
Chuck Leverbf269552010-12-14 14:59:29 +00006513static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6514 struct xdr_stream *xdr,
6515 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516{
Andy Adamson05d564f2008-12-23 16:06:15 -05006517 struct compound_hdr hdr;
6518 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006521 if (status)
6522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006528 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529}
6530
6531/*
6532 * Decode OPEN response
6533 */
Chuck Leverbf269552010-12-14 14:59:29 +00006534static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6535 struct xdr_stream *xdr,
6536 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537{
Andy Adamson05d564f2008-12-23 16:06:15 -05006538 struct compound_hdr hdr;
6539 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006542 if (status)
6543 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006545 if (status)
6546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006548 if (status)
6549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006550 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006551 if (status)
6552 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006553 if (res->access_request)
6554 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006555 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006557 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558}
6559
6560/*
6561 * Decode SETATTR response
6562 */
Chuck Leverbf269552010-12-14 14:59:29 +00006563static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6564 struct xdr_stream *xdr,
6565 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566{
Andy Adamson05d564f2008-12-23 16:06:15 -05006567 struct compound_hdr hdr;
6568 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006571 if (status)
6572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006574 if (status)
6575 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006576 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006577 if (status)
6578 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006579 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006580 if (status)
6581 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006582 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006584 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585}
6586
6587/*
6588 * Decode LOCK response
6589 */
Chuck Leverbf269552010-12-14 14:59:29 +00006590static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6591 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006592{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 struct compound_hdr hdr;
6594 int status;
6595
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 if (status)
6598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006600 if (status)
6601 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 if (status)
6604 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606out:
6607 return status;
6608}
6609
6610/*
6611 * Decode LOCKT response
6612 */
Chuck Leverbf269552010-12-14 14:59:29 +00006613static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6614 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 struct compound_hdr hdr;
6617 int status;
6618
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 if (status)
6621 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006623 if (status)
6624 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626 if (status)
6627 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629out:
6630 return status;
6631}
6632
6633/*
6634 * Decode LOCKU response
6635 */
Chuck Leverbf269552010-12-14 14:59:29 +00006636static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6637 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 struct compound_hdr hdr;
6640 int status;
6641
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 if (status)
6644 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006645 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006646 if (status)
6647 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (status)
6650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652out:
6653 return status;
6654}
6655
Chuck Leverbf269552010-12-14 14:59:29 +00006656static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6657 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006658{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006659 struct compound_hdr hdr;
6660 int status;
6661
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006663 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006665 return status;
6666}
6667
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668/*
6669 * Decode READLINK response
6670 */
Chuck Leverbf269552010-12-14 14:59:29 +00006671static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6672 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006673 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 struct compound_hdr hdr;
6676 int status;
6677
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 if (status)
6680 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006681 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006682 if (status)
6683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 if (status)
6686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688out:
6689 return status;
6690}
6691
6692/*
6693 * Decode READDIR response
6694 */
Chuck Leverbf269552010-12-14 14:59:29 +00006695static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6696 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698 struct compound_hdr hdr;
6699 int status;
6700
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 if (status)
6703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006705 if (status)
6706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 if (status)
6709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711out:
6712 return status;
6713}
6714
6715/*
6716 * Decode Read response
6717 */
Chuck Leverbf269552010-12-14 14:59:29 +00006718static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006719 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721 struct compound_hdr hdr;
6722 int status;
6723
Chuck Leverbf269552010-12-14 14:59:29 +00006724 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006725 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 if (status)
6727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006729 if (status)
6730 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732 if (status)
6733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 if (!status)
6736 status = res->count;
6737out:
6738 return status;
6739}
6740
6741/*
6742 * Decode WRITE response
6743 */
Chuck Leverbf269552010-12-14 14:59:29 +00006744static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006745 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747 struct compound_hdr hdr;
6748 int status;
6749
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006751 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752 if (status)
6753 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006755 if (status)
6756 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758 if (status)
6759 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006761 if (status)
6762 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006763 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006764 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006765 if (!status)
6766 status = res->count;
6767out:
6768 return status;
6769}
6770
6771/*
6772 * Decode COMMIT response
6773 */
Chuck Leverbf269552010-12-14 14:59:29 +00006774static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006775 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777 struct compound_hdr hdr;
6778 int status;
6779
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006781 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782 if (status)
6783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006785 if (status)
6786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 if (status)
6789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791out:
6792 return status;
6793}
6794
6795/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006796 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797 */
Chuck Leverbf269552010-12-14 14:59:29 +00006798static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006799 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 struct compound_hdr hdr;
6802 int status;
6803
Chuck Leverbf269552010-12-14 14:59:29 +00006804 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006806 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006807 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006810 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 return status;
6812}
6813
6814/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006815 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 */
Chuck Leverbf269552010-12-14 14:59:29 +00006817static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006818 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 struct compound_hdr hdr;
6821 int status;
6822
Chuck Leverbf269552010-12-14 14:59:29 +00006823 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006824 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006825 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006826 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006828 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 return status;
6831}
6832
6833/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006834 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006835 */
Chuck Leverbf269552010-12-14 14:59:29 +00006836static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006837 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006839 struct compound_hdr hdr;
6840 int status;
6841
Chuck Leverbf269552010-12-14 14:59:29 +00006842 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006844 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006845 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006846 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006848 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 return status;
6850}
6851
6852/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006853 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006854 */
Chuck Leverbf269552010-12-14 14:59:29 +00006855static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6856 struct xdr_stream *xdr,
6857 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859 struct compound_hdr hdr;
6860 int status;
6861
Chuck Leverbf269552010-12-14 14:59:29 +00006862 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006863 if (status)
6864 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006865 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006866 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006868 status = decode_putfh(xdr);
6869 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006870 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006871 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872out:
6873 return status;
6874}
6875
6876/*
6877 * Decode RENEW response
6878 */
Chuck Leverbf269552010-12-14 14:59:29 +00006879static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6880 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882 struct compound_hdr hdr;
6883 int status;
6884
Chuck Leverbf269552010-12-14 14:59:29 +00006885 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006887 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888 return status;
6889}
6890
6891/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006892 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893 */
Chuck Leverbf269552010-12-14 14:59:29 +00006894static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6895 struct xdr_stream *xdr,
6896 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898 struct compound_hdr hdr;
6899 int status;
6900
Chuck Leverbf269552010-12-14 14:59:29 +00006901 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006903 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904 return status;
6905}
6906
6907/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006908 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006909 */
Chuck Leverbf269552010-12-14 14:59:29 +00006910static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006911 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913 struct compound_hdr hdr;
6914 int status;
6915
Chuck Leverbf269552010-12-14 14:59:29 +00006916 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006917 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919 return status;
6920}
6921
6922/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006923 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 */
Chuck Leverbf269552010-12-14 14:59:29 +00006925static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6926 struct xdr_stream *xdr,
6927 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929 struct compound_hdr hdr;
6930 int status;
6931
Chuck Leverbf269552010-12-14 14:59:29 +00006932 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006933 if (status)
6934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006935 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006936 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006938 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006939 if (status != 0)
6940 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006941 if (res->lr_res) {
6942 status = decode_layoutreturn(xdr, res->lr_res);
6943 res->lr_ret = status;
6944 if (status)
6945 goto out;
6946 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006947 if (res->fattr) {
6948 status = decode_getfattr(xdr, res->fattr, res->server);
6949 if (status != 0)
6950 goto out;
6951 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006952 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006953out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 return status;
6955}
6956
Trond Myklebust683b57b2006-06-09 09:34:22 -04006957/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006958 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006959 */
Chuck Leverbf269552010-12-14 14:59:29 +00006960static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6961 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006962 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006963{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006964 struct compound_hdr hdr;
6965 int status;
6966
Chuck Leverbf269552010-12-14 14:59:29 +00006967 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006968 if (status)
6969 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006970 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006971 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006972 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006973 status = decode_putfh(xdr);
6974 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006975 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006976 if (res->migration) {
6977 xdr_enter_page(xdr, PAGE_SIZE);
6978 status = decode_getfattr_generic(xdr,
6979 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006980 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006981 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006982 if (status)
6983 goto out;
6984 if (res->renew)
6985 status = decode_renew(xdr);
6986 } else {
6987 status = decode_lookup(xdr);
6988 if (status)
6989 goto out;
6990 xdr_enter_page(xdr, PAGE_SIZE);
6991 status = decode_getfattr_generic(xdr,
6992 &res->fs_locations->fattr,
6993 NULL, res->fs_locations,
6994 NULL, res->fs_locations->server);
6995 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006996out:
6997 return status;
6998}
6999
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007000/*
7001 * Decode SECINFO response
7002 */
7003static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7004 struct xdr_stream *xdr,
7005 struct nfs4_secinfo_res *res)
7006{
7007 struct compound_hdr hdr;
7008 int status;
7009
7010 status = decode_compound_hdr(xdr, &hdr);
7011 if (status)
7012 goto out;
7013 status = decode_sequence(xdr, &res->seq_res, rqstp);
7014 if (status)
7015 goto out;
7016 status = decode_putfh(xdr);
7017 if (status)
7018 goto out;
7019 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007020out:
7021 return status;
7022}
7023
Chuck Lever44c99932013-10-17 14:13:30 -04007024/*
7025 * Decode FSID_PRESENT response
7026 */
7027static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7028 struct xdr_stream *xdr,
7029 struct nfs4_fsid_present_res *res)
7030{
7031 struct compound_hdr hdr;
7032 int status;
7033
7034 status = decode_compound_hdr(xdr, &hdr);
7035 if (status)
7036 goto out;
7037 status = decode_sequence(xdr, &res->seq_res, rqstp);
7038 if (status)
7039 goto out;
7040 status = decode_putfh(xdr);
7041 if (status)
7042 goto out;
7043 status = decode_getfh(xdr, res->fh);
7044 if (status)
7045 goto out;
7046 if (res->renew)
7047 status = decode_renew(xdr);
7048out:
7049 return status;
7050}
7051
Benny Halevy99fe60d2009-04-01 09:22:29 -04007052#if defined(CONFIG_NFS_V4_1)
7053/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007054 * Decode BIND_CONN_TO_SESSION response
7055 */
7056static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7057 struct xdr_stream *xdr,
7058 void *res)
7059{
7060 struct compound_hdr hdr;
7061 int status;
7062
7063 status = decode_compound_hdr(xdr, &hdr);
7064 if (!status)
7065 status = decode_bind_conn_to_session(xdr, res);
7066 return status;
7067}
7068
7069/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007070 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007071 */
Chuck Leverbf269552010-12-14 14:59:29 +00007072static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7073 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007074 void *res)
7075{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007076 struct compound_hdr hdr;
7077 int status;
7078
Chuck Leverbf269552010-12-14 14:59:29 +00007079 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007080 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007081 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007082 return status;
7083}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007084
7085/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007086 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007087 */
Chuck Leverbf269552010-12-14 14:59:29 +00007088static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7089 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007090 struct nfs41_create_session_res *res)
7091{
Andy Adamsonfc931582009-04-01 09:22:31 -04007092 struct compound_hdr hdr;
7093 int status;
7094
Chuck Leverbf269552010-12-14 14:59:29 +00007095 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007096 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007097 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007098 return status;
7099}
7100
7101/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007102 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007103 */
Chuck Leverbf269552010-12-14 14:59:29 +00007104static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7105 struct xdr_stream *xdr,
7106 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007107{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007108 struct compound_hdr hdr;
7109 int status;
7110
Chuck Leverbf269552010-12-14 14:59:29 +00007111 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007112 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007113 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007114 return status;
7115}
7116
7117/*
Trond Myklebust66245532012-05-25 17:18:09 -04007118 * Decode DESTROY_CLIENTID response
7119 */
7120static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7121 struct xdr_stream *xdr,
7122 void *res)
7123{
7124 struct compound_hdr hdr;
7125 int status;
7126
7127 status = decode_compound_hdr(xdr, &hdr);
7128 if (!status)
7129 status = decode_destroy_clientid(xdr, res);
7130 return status;
7131}
7132
7133/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007134 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007135 */
Chuck Leverbf269552010-12-14 14:59:29 +00007136static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7137 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007138 struct nfs4_sequence_res *res)
7139{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007140 struct compound_hdr hdr;
7141 int status;
7142
Chuck Leverbf269552010-12-14 14:59:29 +00007143 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007144 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007145 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007146 return status;
7147}
7148
7149/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007150 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007151 */
Chuck Leverbf269552010-12-14 14:59:29 +00007152static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7153 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007154 struct nfs4_get_lease_time_res *res)
7155{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007156 struct compound_hdr hdr;
7157 int status;
7158
Chuck Leverbf269552010-12-14 14:59:29 +00007159 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007160 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007161 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007162 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007163 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007164 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007165 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007166 return status;
7167}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007168
7169/*
7170 * Decode RECLAIM_COMPLETE response
7171 */
Chuck Leverbf269552010-12-14 14:59:29 +00007172static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7173 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007174 struct nfs41_reclaim_complete_res *res)
7175{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007176 struct compound_hdr hdr;
7177 int status;
7178
Chuck Leverbf269552010-12-14 14:59:29 +00007179 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007180 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007181 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007182 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307183 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007184 return status;
7185}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007186
7187/*
7188 * Decode GETDEVINFO response
7189 */
Chuck Leverbf269552010-12-14 14:59:29 +00007190static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7191 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007192 struct nfs4_getdeviceinfo_res *res)
7193{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007194 struct compound_hdr hdr;
7195 int status;
7196
Chuck Leverbf269552010-12-14 14:59:29 +00007197 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007198 if (status != 0)
7199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007200 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007201 if (status != 0)
7202 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007203 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007204out:
7205 return status;
7206}
7207
7208/*
7209 * Decode LAYOUTGET response
7210 */
Chuck Leverbf269552010-12-14 14:59:29 +00007211static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7212 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007213 struct nfs4_layoutget_res *res)
7214{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007215 struct compound_hdr hdr;
7216 int status;
7217
Chuck Leverbf269552010-12-14 14:59:29 +00007218 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007219 if (status)
7220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007221 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007222 if (status)
7223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007224 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007225 if (status)
7226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007227 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007228out:
7229 return status;
7230}
Andy Adamson863a3c62011-03-23 13:27:54 +00007231
7232/*
Benny Halevycbe82602011-05-22 19:52:37 +03007233 * Decode LAYOUTRETURN response
7234 */
7235static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7236 struct xdr_stream *xdr,
7237 struct nfs4_layoutreturn_res *res)
7238{
7239 struct compound_hdr hdr;
7240 int status;
7241
7242 status = decode_compound_hdr(xdr, &hdr);
7243 if (status)
7244 goto out;
7245 status = decode_sequence(xdr, &res->seq_res, rqstp);
7246 if (status)
7247 goto out;
7248 status = decode_putfh(xdr);
7249 if (status)
7250 goto out;
7251 status = decode_layoutreturn(xdr, res);
7252out:
7253 return status;
7254}
7255
7256/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007257 * Decode LAYOUTCOMMIT response
7258 */
7259static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7260 struct xdr_stream *xdr,
7261 struct nfs4_layoutcommit_res *res)
7262{
7263 struct compound_hdr hdr;
7264 int status;
7265
7266 status = decode_compound_hdr(xdr, &hdr);
7267 if (status)
7268 goto out;
7269 status = decode_sequence(xdr, &res->seq_res, rqstp);
7270 if (status)
7271 goto out;
7272 status = decode_putfh(xdr);
7273 if (status)
7274 goto out;
7275 status = decode_layoutcommit(xdr, rqstp, res);
7276 if (status)
7277 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007278 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007279out:
7280 return status;
7281}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007282
7283/*
7284 * Decode SECINFO_NO_NAME response
7285 */
7286static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7287 struct xdr_stream *xdr,
7288 struct nfs4_secinfo_res *res)
7289{
7290 struct compound_hdr hdr;
7291 int status;
7292
7293 status = decode_compound_hdr(xdr, &hdr);
7294 if (status)
7295 goto out;
7296 status = decode_sequence(xdr, &res->seq_res, rqstp);
7297 if (status)
7298 goto out;
7299 status = decode_putrootfh(xdr);
7300 if (status)
7301 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007302 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007303out:
7304 return status;
7305}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007306
7307/*
7308 * Decode TEST_STATEID response
7309 */
7310static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7311 struct xdr_stream *xdr,
7312 struct nfs41_test_stateid_res *res)
7313{
7314 struct compound_hdr hdr;
7315 int status;
7316
7317 status = decode_compound_hdr(xdr, &hdr);
7318 if (status)
7319 goto out;
7320 status = decode_sequence(xdr, &res->seq_res, rqstp);
7321 if (status)
7322 goto out;
7323 status = decode_test_stateid(xdr, res);
7324out:
7325 return status;
7326}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007327
7328/*
7329 * Decode FREE_STATEID response
7330 */
7331static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7332 struct xdr_stream *xdr,
7333 struct nfs41_free_stateid_res *res)
7334{
7335 struct compound_hdr hdr;
7336 int status;
7337
7338 status = decode_compound_hdr(xdr, &hdr);
7339 if (status)
7340 goto out;
7341 status = decode_sequence(xdr, &res->seq_res, rqstp);
7342 if (status)
7343 goto out;
7344 status = decode_free_stateid(xdr, res);
7345out:
7346 return status;
7347}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007348#endif /* CONFIG_NFS_V4_1 */
7349
Chuck Lever573c4e12010-12-14 14:58:11 +00007350/**
7351 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7352 * the local page cache.
7353 * @xdr: XDR stream where entry resides
7354 * @entry: buffer to fill in with entry data
7355 * @plus: boolean indicating whether this should be a readdirplus entry
7356 *
7357 * Returns zero if successful, otherwise a negative errno value is
7358 * returned.
7359 *
7360 * This function is not invoked during READDIR reply decoding, but
7361 * rather whenever an application invokes the getdents(2) system call
7362 * on a directory already in our cache.
7363 */
7364int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7365 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007366{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007367 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007368 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007369 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007370 __be32 *p = xdr_inline_decode(xdr, 4);
7371 if (unlikely(!p))
7372 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007373 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007374 p = xdr_inline_decode(xdr, 4);
7375 if (unlikely(!p))
7376 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007377 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007378 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007379 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007380 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007381 }
7382
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007383 p = xdr_inline_decode(xdr, 12);
7384 if (unlikely(!p))
7385 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007386 entry->prev_cookie = entry->cookie;
7387 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007388 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007389
Trond Myklebust9af8c222010-10-24 11:52:55 -04007390 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007391 if (unlikely(!p))
7392 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007393 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007394
7395 /*
7396 * In case the server doesn't return an inode number,
7397 * we fake one here. (We don't use inode number 0,
7398 * since glibc seems to choke on it...)
7399 */
7400 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007401 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007402
Trond Myklebust9af8c222010-10-24 11:52:55 -04007403 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007404 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007405
Trond Myklebust256e48b2012-06-21 11:18:13 -04007406 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007407 goto out_overflow;
7408
Chuck Lever573c4e12010-12-14 14:58:11 +00007409 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007410 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007411 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007412 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7413 entry->ino = entry->fattr->mounted_on_fileid;
7414 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007415 entry->ino = entry->fattr->fileid;
7416
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007417 entry->d_type = DT_UNKNOWN;
7418 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7419 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7420
Chuck Lever573c4e12010-12-14 14:58:11 +00007421 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007422
7423out_overflow:
7424 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007425 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007426}
7427
7428/*
7429 * We need to translate between nfs status return values and
7430 * the local errno values which may not be the same.
7431 */
7432static struct {
7433 int stat;
7434 int errno;
7435} nfs_errtbl[] = {
7436 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007437 { NFS4ERR_PERM, -EPERM },
7438 { NFS4ERR_NOENT, -ENOENT },
7439 { NFS4ERR_IO, -errno_NFSERR_IO},
7440 { NFS4ERR_NXIO, -ENXIO },
7441 { NFS4ERR_ACCESS, -EACCES },
7442 { NFS4ERR_EXIST, -EEXIST },
7443 { NFS4ERR_XDEV, -EXDEV },
7444 { NFS4ERR_NOTDIR, -ENOTDIR },
7445 { NFS4ERR_ISDIR, -EISDIR },
7446 { NFS4ERR_INVAL, -EINVAL },
7447 { NFS4ERR_FBIG, -EFBIG },
7448 { NFS4ERR_NOSPC, -ENOSPC },
7449 { NFS4ERR_ROFS, -EROFS },
7450 { NFS4ERR_MLINK, -EMLINK },
7451 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7452 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7453 { NFS4ERR_DQUOT, -EDQUOT },
7454 { NFS4ERR_STALE, -ESTALE },
7455 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007456 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7457 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7458 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007459 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007460 { NFS4ERR_BADTYPE, -EBADTYPE },
7461 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007462 { NFS4ERR_SYMLINK, -ELOOP },
7463 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7464 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007465 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007466};
7467
7468/*
7469 * Convert an NFS error code to a local one.
7470 * This one is used jointly by NFSv2 and NFSv3.
7471 */
7472static int
David Howells0a8ea432006-08-22 20:06:08 -04007473nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474{
7475 int i;
7476 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7477 if (nfs_errtbl[i].stat == stat)
7478 return nfs_errtbl[i].errno;
7479 }
7480 if (stat <= 10000 || stat > 10100) {
7481 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007482 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007483 }
7484 /* If we cannot translate the error, the recovery routines should
7485 * handle it.
7486 * Note: remaining NFSv4 error codes have values > 10000, so should
7487 * not conflict with native Linux error codes.
7488 */
Benny Halevy856dff32008-03-31 17:39:06 +03007489 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007490}
7491
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007492#ifdef CONFIG_NFS_V4_2
7493#include "nfs42xdr.c"
7494#endif /* CONFIG_NFS_V4_2 */
7495
Linus Torvalds1da177e2005-04-16 15:20:36 -07007496#define PROC(proc, argtype, restype) \
7497[NFSPROC4_CLNT_##proc] = { \
7498 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007499 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007500 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007501 .p_arglen = NFS4_##argtype##_sz, \
7502 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007503 .p_statidx = NFSPROC4_CLNT_##proc, \
7504 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007505}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007506
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007507#define STUB(proc) \
7508[NFSPROC4_CLNT_##proc] = { \
7509 .p_name = #proc, \
7510}
7511
Linus Torvalds1da177e2005-04-16 15:20:36 -07007512struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007513 PROC(READ, enc_read, dec_read),
7514 PROC(WRITE, enc_write, dec_write),
7515 PROC(COMMIT, enc_commit, dec_commit),
7516 PROC(OPEN, enc_open, dec_open),
7517 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7518 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7519 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7520 PROC(CLOSE, enc_close, dec_close),
7521 PROC(SETATTR, enc_setattr, dec_setattr),
7522 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7523 PROC(RENEW, enc_renew, dec_renew),
7524 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7525 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7526 PROC(LOCK, enc_lock, dec_lock),
7527 PROC(LOCKT, enc_lockt, dec_lockt),
7528 PROC(LOCKU, enc_locku, dec_locku),
7529 PROC(ACCESS, enc_access, dec_access),
7530 PROC(GETATTR, enc_getattr, dec_getattr),
7531 PROC(LOOKUP, enc_lookup, dec_lookup),
7532 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7533 PROC(REMOVE, enc_remove, dec_remove),
7534 PROC(RENAME, enc_rename, dec_rename),
7535 PROC(LINK, enc_link, dec_link),
7536 PROC(SYMLINK, enc_symlink, dec_symlink),
7537 PROC(CREATE, enc_create, dec_create),
7538 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7539 PROC(STATFS, enc_statfs, dec_statfs),
7540 PROC(READLINK, enc_readlink, dec_readlink),
7541 PROC(READDIR, enc_readdir, dec_readdir),
7542 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7543 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7544 PROC(GETACL, enc_getacl, dec_getacl),
7545 PROC(SETACL, enc_setacl, dec_setacl),
7546 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7547 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007548 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007549 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007550#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007551 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7552 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7553 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7554 PROC(SEQUENCE, enc_sequence, dec_sequence),
7555 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7556 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7557 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7558 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007559 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007560 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007561 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007562 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007563 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007564 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007565 PROC(BIND_CONN_TO_SESSION,
7566 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007567 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007568#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007569#ifdef CONFIG_NFS_V4_2
7570 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007571 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007572 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007573 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007574 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007575 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007576#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007577};
7578
Trond Myklebusta613fa12012-01-20 13:53:56 -05007579const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007580 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007581 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007582 .procs = nfs4_procedures
7583};
7584
7585/*
7586 * Local variables:
7587 * c-basic-offset: 8
7588 * End:
7589 */