]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - fs/nfs/nfs4xdr.c
pNFS: Skip checking for return-on-close if the layout is invalid
[mirror_ubuntu-zesty-kernel.git] / fs / nfs / nfs4xdr.c
CommitLineData
1da177e4
LT
1/*
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>
6c0195a4 11 *
1da177e4
LT
12 * 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>
1da177e4
LT
41#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>
db8ac8ba
WAA
47#include <linux/module.h>
48#include <linux/utsname.h>
1da177e4 49#include <linux/sunrpc/clnt.h>
2449ea2e 50#include <linux/sunrpc/msg_prot.h>
5a5ea0d4 51#include <linux/sunrpc/gss_api.h>
1da177e4
LT
52#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
f092075d 55
4ce79717 56#include "nfs4_fs.h"
4882ef72 57#include "internal.h"
40c64c26 58#include "nfs4idmap.h"
76e697ba 59#include "nfs4session.h"
b1f69b75 60#include "pnfs.h"
f092075d 61#include "netns.h"
1da177e4
LT
62
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
0a8ea437 68static int nfs4_stat_to_errno(int);
1da177e4
LT
69
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
6c0195a4 77/* lock,open owner id:
9f958ab8 78 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
1da177e4 79 */
95b72eb0 80#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
d035c36c 81#define lock_owner_id_maxsz (1 + 1 + 4)
9104a55d 82#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1da177e4
LT
83#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
9104a55d
TM
87#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
1da177e4
LT
91#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
e5012d1f 99#define nfs4_fattr_bitmap_maxsz 4
96928206 100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1da177e4
LT
101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
bd625ba8
TM
103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
aa9c2669
DQ
105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
aa9c2669
DQ
108#else
109#define nfs4_label_maxsz 0
aa9c2669 110#endif
88034c3d
AA
111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
96928206
BF
113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
88034c3d 115 3 + 3 + 3 + nfs4_owner_maxsz + \
aa9c2669
DQ
116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
96928206
BF
118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
9104a55d
TM
121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
aa9c2669 125 nfs4_label_maxsz + \
9104a55d 126 4 + 4)
1da177e4
LT
127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
56ae19f3
TM
129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
2f42b5d0 131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
dae100c2
FI
132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1da177e4
LT
137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
cc38bac3 141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
b8fb2f59
JL
142 /* client name */ \
143 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
cc38bac3 144 1 /* sc_prog */ + \
6dd3436b
CL
145 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
cc38bac3 147 1) /* sc_cb_ident */
1da177e4
LT
148#define decode_setclientid_maxsz \
149 (op_decode_hdr_maxsz + \
6dd3436b
CL
150 2 /* clientid */ + \
151 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
1da177e4
LT
154#define encode_setclientid_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 3 + (NFS4_VERIFIER_SIZE >> 2))
157#define decode_setclientid_confirm_maxsz \
158 (op_decode_hdr_maxsz)
e6889620
TM
159#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
160#define decode_lookup_maxsz (op_decode_hdr_maxsz)
2cebf828
TM
161#define encode_share_access_maxsz \
162 (2)
4882ef72 163#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
2cebf828
TM
164#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
165#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
166#define encode_open_maxsz (op_encode_hdr_maxsz + \
167 2 + encode_share_access_maxsz + 2 + \
168 open_owner_id_maxsz + \
169 encode_opentype_maxsz + \
170 encode_claim_null_maxsz)
171#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
9104a55d 172#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
2cebf828
TM
173 decode_ace_maxsz)
174#define decode_change_info_maxsz (5)
175#define decode_open_maxsz (op_decode_hdr_maxsz + \
9104a55d 176 decode_stateid_maxsz + \
2cebf828
TM
177 decode_change_info_maxsz + 1 + \
178 nfs4_fattr_bitmap_maxsz + \
179 decode_delegation_maxsz)
9104a55d
TM
180#define encode_open_confirm_maxsz \
181 (op_encode_hdr_maxsz + \
182 encode_stateid_maxsz + 1)
183#define decode_open_confirm_maxsz \
184 (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_open_downgrade_maxsz \
187 (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 1 + \
189 encode_share_access_maxsz)
190#define decode_open_downgrade_maxsz \
191 (op_decode_hdr_maxsz + \
192 decode_stateid_maxsz)
193#define encode_close_maxsz (op_encode_hdr_maxsz + \
194 1 + encode_stateid_maxsz)
195#define decode_close_maxsz (op_decode_hdr_maxsz + \
196 decode_stateid_maxsz)
197#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
198 encode_stateid_maxsz + \
199 encode_attrs_maxsz)
200#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
201 nfs4_fattr_bitmap_maxsz)
202#define encode_read_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 3)
204#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
205#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
aa9c2669
DQ
206 2 + encode_verifier_maxsz + 5 + \
207 nfs4_label_maxsz)
9104a55d 208#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
a7697f6f 209 decode_verifier_maxsz)
9104a55d
TM
210#define encode_readlink_maxsz (op_encode_hdr_maxsz)
211#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
212#define encode_write_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + 4)
214#define decode_write_maxsz (op_decode_hdr_maxsz + \
215 2 + decode_verifier_maxsz)
216#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
217#define decode_commit_maxsz (op_decode_hdr_maxsz + \
218 decode_verifier_maxsz)
1da177e4
LT
219#define encode_remove_maxsz (op_encode_hdr_maxsz + \
220 nfs4_name_maxsz)
6ce18391
BH
221#define decode_remove_maxsz (op_decode_hdr_maxsz + \
222 decode_change_info_maxsz)
1da177e4
LT
223#define encode_rename_maxsz (op_encode_hdr_maxsz + \
224 2 * nfs4_name_maxsz)
6ce18391
BH
225#define decode_rename_maxsz (op_decode_hdr_maxsz + \
226 decode_change_info_maxsz + \
227 decode_change_info_maxsz)
1da177e4
LT
228#define encode_link_maxsz (op_encode_hdr_maxsz + \
229 nfs4_name_maxsz)
6ce18391 230#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
daccbded 231#define encode_lockowner_maxsz (7)
9104a55d
TM
232#define encode_lock_maxsz (op_encode_hdr_maxsz + \
233 7 + \
daccbded
TM
234 1 + encode_stateid_maxsz + 1 + \
235 encode_lockowner_maxsz)
9104a55d
TM
236#define decode_lock_denied_maxsz \
237 (8 + decode_lockowner_maxsz)
238#define decode_lock_maxsz (op_decode_hdr_maxsz + \
239 decode_lock_denied_maxsz)
daccbded
TM
240#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
241 encode_lockowner_maxsz)
9104a55d
TM
242#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
243 decode_lock_denied_maxsz)
244#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
245 encode_stateid_maxsz + \
246 4)
247#define decode_locku_maxsz (op_decode_hdr_maxsz + \
248 decode_stateid_maxsz)
d3c7b7cc
TM
249#define encode_release_lockowner_maxsz \
250 (op_encode_hdr_maxsz + \
251 encode_lockowner_maxsz)
252#define decode_release_lockowner_maxsz \
253 (op_decode_hdr_maxsz)
9104a55d
TM
254#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
255#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
1da177e4
LT
256#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
257 1 + nfs4_name_maxsz + \
94a6d753 258 1 + \
96928206 259 nfs4_fattr_maxsz)
1da177e4
LT
260#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
261#define encode_create_maxsz (op_encode_hdr_maxsz + \
9104a55d
TM
262 1 + 2 + nfs4_name_maxsz + \
263 encode_attrs_maxsz)
2cebf828
TM
264#define decode_create_maxsz (op_decode_hdr_maxsz + \
265 decode_change_info_maxsz + \
266 nfs4_fattr_bitmap_maxsz)
9104a55d
TM
267#define encode_statfs_maxsz (encode_getattr_maxsz)
268#define decode_statfs_maxsz (decode_getattr_maxsz)
1da177e4
LT
269#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
270#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
9104a55d
TM
271#define encode_getacl_maxsz (encode_getattr_maxsz)
272#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
273 nfs4_fattr_bitmap_maxsz + 1)
274#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
275 encode_stateid_maxsz + 3)
276#define decode_setacl_maxsz (decode_setattr_maxsz)
e6889620
TM
277#define encode_fs_locations_maxsz \
278 (encode_getattr_maxsz)
279#define decode_fs_locations_maxsz \
280 (0)
5a5ea0d4 281#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
1650add2 282#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
9b7b9fcc
AA
283
284#if defined(CONFIG_NFS_V4_1)
fc931582 285#define NFS4_MAX_MACHINE_NAME_LEN (64)
d751f748
JR
286#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
287 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
fc931582 288
99fe60d0
BH
289#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
290 encode_verifier_maxsz + \
291 1 /* co_ownerid.len */ + \
b8fb2f59
JL
292 /* eia_clientowner */ \
293 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
99fe60d0
BH
294 1 /* flags */ + \
295 1 /* spa_how */ + \
2031cd1a
WAA
296 /* max is SP4_MACH_CRED (for now) */ + \
297 1 + NFS4_OP_MAP_NUM_WORDS + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
db8ac8ba
WAA
299 1 /* implementation id array of size 1 */ + \
300 1 /* nii_domain */ + \
301 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
302 1 /* nii_name */ + \
d751f748 303 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
db8ac8ba 304 3 /* nii_date */)
99fe60d0
BH
305#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
306 2 /* eir_clientid */ + \
307 1 /* eir_sequenceid */ + \
308 1 /* eir_flags */ + \
309 1 /* spr_how */ + \
2031cd1a
WAA
310 /* max is SP4_MACH_CRED (for now) */ + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
99fe60d0
BH
313 2 /* eir_server_owner.so_minor_id */ + \
314 /* eir_server_owner.so_major_id<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 /* eir_server_scope<> */ \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
318 1 /* eir_server_impl_id array length */ + \
7d2ed9ac
WAA
319 1 /* nii_domain */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
321 1 /* nii_name */ + \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
323 3 /* nii_date */)
fc931582
AA
324#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
325#define decode_channel_attrs_maxsz (6 + \
326 1 /* ca_rdma_ird.len */ + \
327 1 /* ca_rdma_ird */)
328#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
329 2 /* csa_clientid */ + \
330 1 /* csa_sequence */ + \
331 1 /* csa_flags */ + \
332 encode_channel_attrs_maxsz + \
333 encode_channel_attrs_maxsz + \
334 1 /* csa_cb_program */ + \
335 1 /* csa_sec_parms.len (1) */ + \
336 1 /* cb_secflavor (AUTH_SYS) */ + \
337 1 /* stamp */ + \
338 1 /* machinename.len */ + \
339 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340 1 /* uid */ + \
341 1 /* gid */ + \
342 1 /* gids.len (0) */)
343#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
344 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
345 1 /* csr_sequence */ + \
346 1 /* csr_flags */ + \
347 decode_channel_attrs_maxsz + \
348 decode_channel_attrs_maxsz)
7c44f1ae
WAA
349#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
350 /* bctsa_sessid */ \
351 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
352 1 /* bctsa_dir */ + \
353 1 /* bctsa_use_conn_in_rdma_mode */)
354#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
355 /* bctsr_sessid */ \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsr_dir */ + \
358 1 /* bctsr_use_conn_in_rdma_mode */)
0f3e66c6
AA
359#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
360#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
66245539
TM
361#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
362#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
fc01cea9
AA
363#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
365#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
18019753
RL
367#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
368#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
84c9dee3
CH
369#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
370 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
371 1 /* layout type */ + \
372 1 /* maxcount */ + \
373 1 /* bitmap size */ + \
374 1 /* notification bitmap length */ + \
375 1 /* notification bitmap, word 0 */)
b1f69b75
AA
376#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
377 1 /* layout type */ + \
378 1 /* opaque devaddr4 length */ + \
379 /* devaddr4 payload is read into page */ \
380 1 /* notification bitmap length */ + \
84c9dee3 381 1 /* notification bitmap, word 0 */)
b1f69b75
AA
382#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
383 encode_stateid_maxsz)
384#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
385 decode_stateid_maxsz + \
386 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
863a3c6c
AA
387#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
388 2 /* offset */ + \
389 2 /* length */ + \
390 1 /* reclaim */ + \
391 encode_stateid_maxsz + \
392 1 /* new offset (true) */ + \
393 2 /* last byte written */ + \
394 1 /* nt_timechanged (false) */ + \
395 1 /* layoutupdate4 layout type */ + \
5f919c9f
CH
396 1 /* layoutupdate4 opaqueue len */)
397 /* the actual content of layoutupdate4 should
398 be allocated by drivers and spliced in
399 using xdr_write_pages */
863a3c6c 400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
cbe82603
BH
401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
6669cb8b
TM
403 1 + \
404 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
cbe82603
BH
405#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
406 1 + decode_stateid_maxsz)
fca78d6d
BS
407#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
408#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
7d974794
BS
409#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
410 XDR_QUADLEN(NFS4_STATEID_SIZE))
411#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
9aeda35f
BS
412#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
413 XDR_QUADLEN(NFS4_STATEID_SIZE))
9f79fb48 414#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
9b7b9fcc
AA
415#else /* CONFIG_NFS_V4_1 */
416#define encode_sequence_maxsz 0
417#define decode_sequence_maxsz 0
418#endif /* CONFIG_NFS_V4_1 */
419
1da177e4
LT
420#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
422#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 423 encode_sequence_maxsz + \
1da177e4 424 encode_putfh_maxsz + \
9104a55d 425 encode_read_maxsz)
1da177e4 426#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 427 decode_sequence_maxsz + \
1da177e4 428 decode_putfh_maxsz + \
9104a55d 429 decode_read_maxsz)
1da177e4 430#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 431 encode_sequence_maxsz + \
1da177e4 432 encode_putfh_maxsz + \
9104a55d 433 encode_readlink_maxsz)
1da177e4 434#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 435 decode_sequence_maxsz + \
1da177e4 436 decode_putfh_maxsz + \
9104a55d 437 decode_readlink_maxsz)
1da177e4 438#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 439 encode_sequence_maxsz + \
1da177e4 440 encode_putfh_maxsz + \
9104a55d 441 encode_readdir_maxsz)
1da177e4 442#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 443 decode_sequence_maxsz + \
1da177e4 444 decode_putfh_maxsz + \
9104a55d 445 decode_readdir_maxsz)
1da177e4 446#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 447 encode_sequence_maxsz + \
1da177e4 448 encode_putfh_maxsz + \
9104a55d 449 encode_write_maxsz + \
4f9838c7 450 encode_getattr_maxsz)
1da177e4 451#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 452 decode_sequence_maxsz + \
1da177e4 453 decode_putfh_maxsz + \
9104a55d 454 decode_write_maxsz + \
4f9838c7 455 decode_getattr_maxsz)
1da177e4 456#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 457 encode_sequence_maxsz + \
1da177e4 458 encode_putfh_maxsz + \
8582715e 459 encode_commit_maxsz)
1da177e4 460#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 461 decode_sequence_maxsz + \
1da177e4 462 decode_putfh_maxsz + \
8582715e 463 decode_commit_maxsz)
1da177e4 464#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 465 encode_sequence_maxsz + \
2cebf828 466 encode_putfh_maxsz + \
2cebf828 467 encode_open_maxsz + \
6168f62c 468 encode_access_maxsz + \
2cebf828 469 encode_getfh_maxsz + \
2cebf828 470 encode_getattr_maxsz)
1da177e4 471#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 472 decode_sequence_maxsz + \
2cebf828 473 decode_putfh_maxsz + \
2cebf828 474 decode_open_maxsz + \
6168f62c 475 decode_access_maxsz + \
2cebf828 476 decode_getfh_maxsz + \
2cebf828 477 decode_getattr_maxsz)
9104a55d
TM
478#define NFS4_enc_open_confirm_sz \
479 (compound_encode_hdr_maxsz + \
480 encode_putfh_maxsz + \
481 encode_open_confirm_maxsz)
482#define NFS4_dec_open_confirm_sz \
483 (compound_decode_hdr_maxsz + \
484 decode_putfh_maxsz + \
485 decode_open_confirm_maxsz)
1da177e4 486#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 487 encode_sequence_maxsz + \
1da177e4 488 encode_putfh_maxsz + \
2cebf828 489 encode_open_maxsz + \
6168f62c 490 encode_access_maxsz + \
2cebf828 491 encode_getattr_maxsz)
1da177e4 492#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 493 decode_sequence_maxsz + \
1da177e4 494 decode_putfh_maxsz + \
2cebf828 495 decode_open_maxsz + \
6168f62c 496 decode_access_maxsz + \
2cebf828 497 decode_getattr_maxsz)
1da177e4
LT
498#define NFS4_enc_open_downgrade_sz \
499 (compound_encode_hdr_maxsz + \
9b7b9fcc 500 encode_sequence_maxsz + \
9104a55d 501 encode_putfh_maxsz + \
3947b74d 502 encode_open_downgrade_maxsz)
1da177e4
LT
503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
9b7b9fcc 505 decode_sequence_maxsz + \
9104a55d 506 decode_putfh_maxsz + \
3947b74d 507 decode_open_downgrade_maxsz)
9104a55d 508#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 509 encode_sequence_maxsz + \
9104a55d
TM
510 encode_putfh_maxsz + \
511 encode_close_maxsz + \
512 encode_getattr_maxsz)
513#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 514 decode_sequence_maxsz + \
9104a55d
TM
515 decode_putfh_maxsz + \
516 decode_close_maxsz + \
517 decode_getattr_maxsz)
518#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 519 encode_sequence_maxsz + \
9104a55d
TM
520 encode_putfh_maxsz + \
521 encode_setattr_maxsz + \
522 encode_getattr_maxsz)
523#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 524 decode_sequence_maxsz + \
9104a55d
TM
525 decode_putfh_maxsz + \
526 decode_setattr_maxsz + \
527 decode_getattr_maxsz)
1da177e4 528#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 529 encode_sequence_maxsz + \
1da177e4
LT
530 encode_putfh_maxsz + \
531 encode_fsinfo_maxsz)
532#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 533 decode_sequence_maxsz + \
1da177e4
LT
534 decode_putfh_maxsz + \
535 decode_fsinfo_maxsz)
536#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
537 encode_renew_maxsz)
538#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
539 decode_renew_maxsz)
540#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
541 encode_setclientid_maxsz)
542#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
543 decode_setclientid_maxsz)
544#define NFS4_enc_setclientid_confirm_sz \
545 (compound_encode_hdr_maxsz + \
83ca7f5a 546 encode_setclientid_confirm_maxsz)
1da177e4
LT
547#define NFS4_dec_setclientid_confirm_sz \
548 (compound_decode_hdr_maxsz + \
83ca7f5a 549 decode_setclientid_confirm_maxsz)
1da177e4 550#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 551 encode_sequence_maxsz + \
1da177e4 552 encode_putfh_maxsz + \
9104a55d 553 encode_lock_maxsz)
1da177e4 554#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 555 decode_sequence_maxsz + \
1da177e4 556 decode_putfh_maxsz + \
9104a55d 557 decode_lock_maxsz)
1da177e4 558#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 559 encode_sequence_maxsz + \
1da177e4 560 encode_putfh_maxsz + \
9104a55d
TM
561 encode_lockt_maxsz)
562#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 563 decode_sequence_maxsz + \
9104a55d
TM
564 decode_putfh_maxsz + \
565 decode_lockt_maxsz)
1da177e4 566#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 567 encode_sequence_maxsz + \
1da177e4 568 encode_putfh_maxsz + \
9104a55d 569 encode_locku_maxsz)
1da177e4 570#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 571 decode_sequence_maxsz + \
1da177e4 572 decode_putfh_maxsz + \
9104a55d 573 decode_locku_maxsz)
d3c7b7cc
TM
574#define NFS4_enc_release_lockowner_sz \
575 (compound_encode_hdr_maxsz + \
576 encode_lockowner_maxsz)
577#define NFS4_dec_release_lockowner_sz \
578 (compound_decode_hdr_maxsz + \
579 decode_lockowner_maxsz)
1da177e4 580#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 581 encode_sequence_maxsz + \
1da177e4 582 encode_putfh_maxsz + \
76b32999
TM
583 encode_access_maxsz + \
584 encode_getattr_maxsz)
1da177e4 585#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 586 decode_sequence_maxsz + \
1da177e4 587 decode_putfh_maxsz + \
76b32999
TM
588 decode_access_maxsz + \
589 decode_getattr_maxsz)
1da177e4 590#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 591 encode_sequence_maxsz + \
1da177e4 592 encode_putfh_maxsz + \
44c99933
CL
593 encode_getattr_maxsz + \
594 encode_renew_maxsz)
1da177e4 595#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 596 decode_sequence_maxsz + \
1da177e4 597 decode_putfh_maxsz + \
44c99933
CL
598 decode_getattr_maxsz + \
599 decode_renew_maxsz)
1da177e4 600#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 601 encode_sequence_maxsz + \
1da177e4
LT
602 encode_putfh_maxsz + \
603 encode_lookup_maxsz + \
604 encode_getattr_maxsz + \
605 encode_getfh_maxsz)
606#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 607 decode_sequence_maxsz + \
1da177e4 608 decode_putfh_maxsz + \
e6889620 609 decode_lookup_maxsz + \
1da177e4
LT
610 decode_getattr_maxsz + \
611 decode_getfh_maxsz)
612#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 613 encode_sequence_maxsz + \
1da177e4
LT
614 encode_putrootfh_maxsz + \
615 encode_getattr_maxsz + \
616 encode_getfh_maxsz)
617#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 618 decode_sequence_maxsz + \
1da177e4
LT
619 decode_putrootfh_maxsz + \
620 decode_getattr_maxsz + \
621 decode_getfh_maxsz)
622#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 623 encode_sequence_maxsz + \
1da177e4 624 encode_putfh_maxsz + \
778d2817 625 encode_remove_maxsz)
1da177e4 626#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 627 decode_sequence_maxsz + \
1da177e4 628 decode_putfh_maxsz + \
778d2817 629 decode_remove_maxsz)
1da177e4 630#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 631 encode_sequence_maxsz + \
1da177e4
LT
632 encode_putfh_maxsz + \
633 encode_savefh_maxsz + \
634 encode_putfh_maxsz + \
778d2817 635 encode_rename_maxsz)
1da177e4 636#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 637 decode_sequence_maxsz + \
1da177e4
LT
638 decode_putfh_maxsz + \
639 decode_savefh_maxsz + \
640 decode_putfh_maxsz + \
778d2817 641 decode_rename_maxsz)
1da177e4 642#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 643 encode_sequence_maxsz + \
1da177e4
LT
644 encode_putfh_maxsz + \
645 encode_savefh_maxsz + \
646 encode_putfh_maxsz + \
91ba2eee 647 encode_link_maxsz + \
91ba2eee 648 encode_restorefh_maxsz + \
a9f6991b 649 encode_getattr_maxsz)
1da177e4 650#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 651 decode_sequence_maxsz + \
1da177e4
LT
652 decode_putfh_maxsz + \
653 decode_savefh_maxsz + \
654 decode_putfh_maxsz + \
91ba2eee 655 decode_link_maxsz + \
91ba2eee
TM
656 decode_restorefh_maxsz + \
657 decode_getattr_maxsz)
1da177e4 658#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 659 encode_sequence_maxsz + \
1da177e4
LT
660 encode_putfh_maxsz + \
661 encode_symlink_maxsz + \
662 encode_getattr_maxsz + \
663 encode_getfh_maxsz)
664#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 665 decode_sequence_maxsz + \
1da177e4
LT
666 decode_putfh_maxsz + \
667 decode_symlink_maxsz + \
668 decode_getattr_maxsz + \
669 decode_getfh_maxsz)
670#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 671 encode_sequence_maxsz + \
1da177e4
LT
672 encode_putfh_maxsz + \
673 encode_create_maxsz + \
56ae19f3 674 encode_getfh_maxsz + \
56ae19f3 675 encode_getattr_maxsz)
1da177e4 676#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 677 decode_sequence_maxsz + \
1da177e4
LT
678 decode_putfh_maxsz + \
679 decode_create_maxsz + \
56ae19f3 680 decode_getfh_maxsz + \
56ae19f3 681 decode_getattr_maxsz)
1da177e4 682#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 683 encode_sequence_maxsz + \
1da177e4
LT
684 encode_putfh_maxsz + \
685 encode_getattr_maxsz)
686#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 687 decode_sequence_maxsz + \
1da177e4
LT
688 decode_putfh_maxsz + \
689 decode_getattr_maxsz)
690#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 691 encode_sequence_maxsz + \
1da177e4 692 encode_putfh_maxsz + \
9104a55d 693 encode_statfs_maxsz)
1da177e4 694#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 695 decode_sequence_maxsz + \
1da177e4 696 decode_putfh_maxsz + \
9104a55d 697 decode_statfs_maxsz)
1da177e4 698#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 699 encode_sequence_maxsz + \
ab91f264 700 encode_putfh_maxsz + \
1da177e4
LT
701 encode_getattr_maxsz)
702#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 703 decode_sequence_maxsz + \
ab91f264 704 decode_putfh_maxsz + \
1da177e4
LT
705 decode_getattr_maxsz)
706#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 707 encode_sequence_maxsz + \
1da177e4 708 encode_putfh_maxsz + \
fa178f29
TM
709 encode_delegreturn_maxsz + \
710 encode_getattr_maxsz)
1da177e4 711#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 712 decode_sequence_maxsz + \
fa178f29
TM
713 decode_delegreturn_maxsz + \
714 decode_getattr_maxsz)
029d105e 715#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 716 encode_sequence_maxsz + \
029d105e 717 encode_putfh_maxsz + \
9104a55d 718 encode_getacl_maxsz)
029d105e 719#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 720 decode_sequence_maxsz + \
029d105e 721 decode_putfh_maxsz + \
9104a55d 722 decode_getacl_maxsz)
23ec6965 723#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 724 encode_sequence_maxsz + \
23ec6965 725 encode_putfh_maxsz + \
9104a55d 726 encode_setacl_maxsz)
23ec6965 727#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 728 decode_sequence_maxsz + \
23ec6965 729 decode_putfh_maxsz + \
9104a55d 730 decode_setacl_maxsz)
683b57b4
TM
731#define NFS4_enc_fs_locations_sz \
732 (compound_encode_hdr_maxsz + \
9b7b9fcc 733 encode_sequence_maxsz + \
683b57b4 734 encode_putfh_maxsz + \
e6889620 735 encode_lookup_maxsz + \
b03d735b
CL
736 encode_fs_locations_maxsz + \
737 encode_renew_maxsz)
683b57b4
TM
738#define NFS4_dec_fs_locations_sz \
739 (compound_decode_hdr_maxsz + \
9b7b9fcc 740 decode_sequence_maxsz + \
683b57b4 741 decode_putfh_maxsz + \
e6889620 742 decode_lookup_maxsz + \
b03d735b
CL
743 decode_fs_locations_maxsz + \
744 decode_renew_maxsz)
5a5ea0d4
BS
745#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
746 encode_sequence_maxsz + \
747 encode_putfh_maxsz + \
748 encode_secinfo_maxsz)
749#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
750 decode_sequence_maxsz + \
751 decode_putfh_maxsz + \
752 decode_secinfo_maxsz)
44c99933
CL
753#define NFS4_enc_fsid_present_sz \
754 (compound_encode_hdr_maxsz + \
755 encode_sequence_maxsz + \
756 encode_putfh_maxsz + \
757 encode_getfh_maxsz + \
758 encode_renew_maxsz)
759#define NFS4_dec_fsid_present_sz \
760 (compound_decode_hdr_maxsz + \
761 decode_sequence_maxsz + \
762 decode_putfh_maxsz + \
763 decode_getfh_maxsz + \
764 decode_renew_maxsz)
99fe60d0 765#if defined(CONFIG_NFS_V4_1)
7c44f1ae
WAA
766#define NFS4_enc_bind_conn_to_session_sz \
767 (compound_encode_hdr_maxsz + \
768 encode_bind_conn_to_session_maxsz)
769#define NFS4_dec_bind_conn_to_session_sz \
770 (compound_decode_hdr_maxsz + \
771 decode_bind_conn_to_session_maxsz)
99fe60d0
BH
772#define NFS4_enc_exchange_id_sz \
773 (compound_encode_hdr_maxsz + \
774 encode_exchange_id_maxsz)
775#define NFS4_dec_exchange_id_sz \
776 (compound_decode_hdr_maxsz + \
777 decode_exchange_id_maxsz)
fc931582
AA
778#define NFS4_enc_create_session_sz \
779 (compound_encode_hdr_maxsz + \
780 encode_create_session_maxsz)
781#define NFS4_dec_create_session_sz \
782 (compound_decode_hdr_maxsz + \
783 decode_create_session_maxsz)
0f3e66c6
AA
784#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
785 encode_destroy_session_maxsz)
786#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
787 decode_destroy_session_maxsz)
66245539
TM
788#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
789 encode_destroy_clientid_maxsz)
790#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
791 decode_destroy_clientid_maxsz)
fc01cea9
AA
792#define NFS4_enc_sequence_sz \
793 (compound_decode_hdr_maxsz + \
794 encode_sequence_maxsz)
795#define NFS4_dec_sequence_sz \
796 (compound_decode_hdr_maxsz + \
797 decode_sequence_maxsz)
2050f0cc
AA
798#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putrootfh_maxsz + \
801 encode_fsinfo_maxsz)
802#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
803 decode_sequence_maxsz + \
804 decode_putrootfh_maxsz + \
805 decode_fsinfo_maxsz)
18019753
RL
806#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_reclaim_complete_maxsz)
809#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
810 decode_sequence_maxsz + \
811 decode_reclaim_complete_maxsz)
b1f69b75
AA
812#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
813 encode_sequence_maxsz +\
814 encode_getdeviceinfo_maxsz)
815#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_getdeviceinfo_maxsz)
818#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
819 encode_sequence_maxsz + \
820 encode_putfh_maxsz + \
821 encode_layoutget_maxsz)
822#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz + \
824 decode_putfh_maxsz + \
825 decode_layoutget_maxsz)
863a3c6c
AA
826#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
827 encode_sequence_maxsz +\
828 encode_putfh_maxsz + \
829 encode_layoutcommit_maxsz + \
830 encode_getattr_maxsz)
831#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
832 decode_sequence_maxsz + \
833 decode_putfh_maxsz + \
834 decode_layoutcommit_maxsz + \
835 decode_getattr_maxsz)
cbe82603
BH
836#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
837 encode_sequence_maxsz + \
838 encode_putfh_maxsz + \
839 encode_layoutreturn_maxsz)
840#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_putfh_maxsz + \
843 decode_layoutreturn_maxsz)
fca78d6d
BS
844#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_putrootfh_maxsz +\
847 encode_secinfo_no_name_maxsz)
848#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_putrootfh_maxsz + \
851 decode_secinfo_no_name_maxsz)
7d974794
BS
852#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz + \
854 encode_test_stateid_maxsz)
855#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
856 decode_sequence_maxsz + \
857 decode_test_stateid_maxsz)
9aeda35f
BS
858#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
859 encode_sequence_maxsz + \
860 encode_free_stateid_maxsz)
861#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
862 decode_sequence_maxsz + \
863 decode_free_stateid_maxsz)
2449ea2e
AB
864
865const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
866 compound_encode_hdr_maxsz +
867 encode_sequence_maxsz +
868 encode_putfh_maxsz +
869 encode_getattr_maxsz) *
870 XDR_UNIT);
871
872const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
873 compound_decode_hdr_maxsz +
874 decode_sequence_maxsz +
875 decode_putfh_maxsz) *
876 XDR_UNIT);
f1c097be
AA
877
878const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
879 compound_decode_hdr_maxsz +
880 decode_sequence_maxsz) *
881 XDR_UNIT);
882EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
99fe60d0 883#endif /* CONFIG_NFS_V4_1 */
1da177e4 884
bca79478
TM
885static const umode_t nfs_type2fmt[] = {
886 [NF4BAD] = 0,
887 [NF4REG] = S_IFREG,
888 [NF4DIR] = S_IFDIR,
889 [NF4BLK] = S_IFBLK,
890 [NF4CHR] = S_IFCHR,
891 [NF4LNK] = S_IFLNK,
892 [NF4SOCK] = S_IFSOCK,
893 [NF4FIFO] = S_IFIFO,
894 [NF4ATTRDIR] = 0,
895 [NF4NAMEDATTR] = 0,
1da177e4
LT
896};
897
898struct compound_hdr {
899 int32_t status;
900 uint32_t nops;
d017931c 901 __be32 * nops_p;
1da177e4
LT
902 uint32_t taglen;
903 char * tag;
0c4e8c18 904 uint32_t replen; /* expected reply words */
66cc0429 905 u32 minorversion;
1da177e4
LT
906};
907
13c65ce9
BH
908static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
909{
910 __be32 *p = xdr_reserve_space(xdr, nbytes);
911 BUG_ON(!p);
912 return p;
913}
1da177e4 914
cb17e556
TM
915static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
916{
917 __be32 *p;
918
919 p = xdr_reserve_space(xdr, len);
920 xdr_encode_opaque_fixed(p, buf, len);
921}
922
1da177e4
LT
923static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
924{
8687b63a 925 __be32 *p;
1da177e4 926
6fdfb0bc 927 p = reserve_space(xdr, 4 + len);
1da177e4
LT
928 xdr_encode_opaque(p, str, len);
929}
930
4ade9821
TM
931static void encode_uint32(struct xdr_stream *xdr, u32 n)
932{
933 __be32 *p;
934
935 p = reserve_space(xdr, 4);
936 *p = cpu_to_be32(n);
937}
938
ff2eb681
TM
939static void encode_uint64(struct xdr_stream *xdr, u64 n)
940{
941 __be32 *p;
942
943 p = reserve_space(xdr, 8);
944 xdr_encode_hyper(p, n);
945}
946
4ade9821
TM
947static void encode_nfs4_seqid(struct xdr_stream *xdr,
948 const struct nfs_seqid *seqid)
949{
a6796419
TM
950 if (seqid != NULL)
951 encode_uint32(xdr, seqid->sequence->counter);
952 else
953 encode_uint32(xdr, 0);
4ade9821
TM
954}
955
0c4e8c18
BH
956static void encode_compound_hdr(struct xdr_stream *xdr,
957 struct rpc_rqst *req,
958 struct compound_hdr *hdr)
1da177e4 959{
8687b63a 960 __be32 *p;
a17c2153 961 struct rpc_auth *auth = req->rq_cred->cr_auth;
0c4e8c18
BH
962
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;
1da177e4 967
7fc38846 968 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
6fdfb0bc
TM
969 encode_string(xdr, hdr->taglen, hdr->tag);
970 p = reserve_space(xdr, 8);
e75bc1c8 971 *p++ = cpu_to_be32(hdr->minorversion);
d017931c 972 hdr->nops_p = p;
34558513 973 *p = cpu_to_be32(hdr->nops);
d017931c
AA
974}
975
ab19b481
TM
976static 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
d017931c
AA
985static void encode_nops(struct compound_hdr *hdr)
986{
7fc38846 987 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
d017931c 988 *hdr->nops_p = htonl(hdr->nops);
1da177e4
LT
989}
990
ea9d23f5
TM
991static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
992{
2d2f24ad 993 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
ea9d23f5
TM
994}
995
1da177e4
LT
996static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
997{
cb17e556 998 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1da177e4
LT
999}
1000
aa9c2669
DQ
1001static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1002 const struct nfs4_label *label,
5334c5bd
KM
1003 const struct nfs_server *server,
1004 bool excl_check)
1da177e4
LT
1005{
1006 char owner_name[IDMAP_NAMESZ];
1007 char owner_group[IDMAP_NAMESZ];
1008 int owner_namelen = 0;
1009 int owner_grouplen = 0;
8687b63a 1010 __be32 *p;
d7067b2d
TM
1011 unsigned i;
1012 uint32_t len = 0;
1013 uint32_t bmval_len;
1014 uint32_t bmval[3] = { 0 };
1da177e4
LT
1015
1016 /*
1017 * We reserve enough space to write the entire attribute buffer at once.
1018 * In the worst-case, this would be
a09df2ca
DQ
1019 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1020 * = 40 bytes, plus any contribution from variable-length fields
23ec6965 1021 * such as owner/group.
1da177e4 1022 */
d7067b2d
TM
1023 if (iap->ia_valid & ATTR_SIZE) {
1024 bmval[0] |= FATTR4_WORD0_SIZE;
1da177e4 1025 len += 8;
d7067b2d
TM
1026 }
1027 if (iap->ia_valid & ATTR_MODE) {
1028 bmval[1] |= FATTR4_WORD1_MODE;
1da177e4 1029 len += 4;
d7067b2d 1030 }
1da177e4 1031 if (iap->ia_valid & ATTR_UID) {
e4fd72a1 1032 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1da177e4 1033 if (owner_namelen < 0) {
fe82a183 1034 dprintk("nfs: couldn't resolve uid %d to string\n",
e5782076 1035 from_kuid(&init_user_ns, iap->ia_uid));
1da177e4
LT
1036 /* XXX */
1037 strcpy(owner_name, "nobody");
1038 owner_namelen = sizeof("nobody") - 1;
1039 /* goto out; */
1040 }
d7067b2d 1041 bmval[1] |= FATTR4_WORD1_OWNER;
1da177e4
LT
1042 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1043 }
1044 if (iap->ia_valid & ATTR_GID) {
e4fd72a1 1045 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1da177e4 1046 if (owner_grouplen < 0) {
fe82a183 1047 dprintk("nfs: couldn't resolve gid %d to string\n",
e5782076 1048 from_kgid(&init_user_ns, iap->ia_gid));
1da177e4
LT
1049 strcpy(owner_group, "nobody");
1050 owner_grouplen = sizeof("nobody") - 1;
1051 /* goto out; */
1052 }
d7067b2d 1053 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1da177e4
LT
1054 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1055 }
d7067b2d
TM
1056 if (iap->ia_valid & ATTR_ATIME_SET) {
1057 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1da177e4 1058 len += 16;
d7067b2d
TM
1059 } else if (iap->ia_valid & ATTR_ATIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1da177e4 1061 len += 4;
d7067b2d
TM
1062 }
1063 if (iap->ia_valid & ATTR_MTIME_SET) {
1064 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1da177e4 1065 len += 16;
d7067b2d
TM
1066 } else if (iap->ia_valid & ATTR_MTIME) {
1067 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1da177e4 1068 len += 4;
d7067b2d 1069 }
5334c5bd
KM
1070
1071 if (excl_check) {
1072 const u32 *excl_bmval = server->exclcreat_bitmask;
1073 bmval[0] &= excl_bmval[0];
1074 bmval[1] &= excl_bmval[1];
1075 bmval[2] &= excl_bmval[2];
1076
1077 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1078 label = NULL;
1079 }
1080
b4a2cf76
TM
1081 if (label) {
1082 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
d7067b2d 1083 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
b4a2cf76
TM
1084 }
1085
d7067b2d
TM
1086 if (bmval[2] != 0)
1087 bmval_len = 3;
1088 else if (bmval[1] != 0)
1089 bmval_len = 2;
1090 else
1091 bmval_len = 1;
1092
1093 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1da177e4 1094
b4a2cf76 1095 *p++ = cpu_to_be32(bmval_len);
d7067b2d
TM
1096 for (i = 0; i < bmval_len; i++)
1097 *p++ = cpu_to_be32(bmval[i]);
1098 *p++ = cpu_to_be32(len);
1da177e4 1099
d7067b2d 1100 if (bmval[0] & FATTR4_WORD0_SIZE)
b95be5a9 1101 p = xdr_encode_hyper(p, iap->ia_size);
d7067b2d 1102 if (bmval[1] & FATTR4_WORD1_MODE)
e75bc1c8 1103 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
d7067b2d 1104 if (bmval[1] & FATTR4_WORD1_OWNER)
811652bd 1105 p = xdr_encode_opaque(p, owner_name, owner_namelen);
d7067b2d 1106 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
811652bd 1107 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
d7067b2d
TM
1108 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1109 if (iap->ia_valid & ATTR_ATIME_SET) {
1110 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1111 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1112 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1113 } else
1114 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1da177e4 1115 }
d7067b2d
TM
1116 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1117 if (iap->ia_valid & ATTR_MTIME_SET) {
1118 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1119 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1120 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1121 } else
1122 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1da177e4 1123 }
d7067b2d 1124 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
aa9c2669
DQ
1125 *p++ = cpu_to_be32(label->lfs);
1126 *p++ = cpu_to_be32(label->pi);
1127 *p++ = cpu_to_be32(label->len);
1128 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1129 }
6c0195a4 1130
1da177e4 1131/* out: */
1da177e4
LT
1132}
1133
cf8cdbe5 1134static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1da177e4 1135{
475d4ba0
TM
1136 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1137 encode_uint32(xdr, access);
1da177e4
LT
1138}
1139
cf8cdbe5 1140static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1da177e4 1141{
ab19b481 1142 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
4ade9821 1143 encode_nfs4_seqid(xdr, arg->seqid);
566fcec6 1144 encode_nfs4_stateid(xdr, &arg->stateid);
1da177e4
LT
1145}
1146
0b7c0153 1147static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1da177e4 1148{
8687b63a 1149 __be32 *p;
6c0195a4 1150
475d4ba0
TM
1151 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1152 p = reserve_space(xdr, 12);
b95be5a9 1153 p = xdr_encode_hyper(p, args->offset);
34558513 1154 *p = cpu_to_be32(args->count);
1da177e4
LT
1155}
1156
cf8cdbe5 1157static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1da177e4 1158{
8687b63a 1159 __be32 *p;
6c0195a4 1160
475d4ba0
TM
1161 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1162 encode_uint32(xdr, create->ftype);
1da177e4
LT
1163
1164 switch (create->ftype) {
1165 case NF4LNK:
13c65ce9 1166 p = reserve_space(xdr, 4);
34558513 1167 *p = cpu_to_be32(create->u.symlink.len);
2fcc213a
CL
1168 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1169 create->u.symlink.len);
1170 xdr->buf->flags |= XDRBUF_WRITE;
1da177e4
LT
1171 break;
1172
1173 case NF4BLK: case NF4CHR:
13c65ce9 1174 p = reserve_space(xdr, 8);
e75bc1c8 1175 *p++ = cpu_to_be32(create->u.device.specdata1);
34558513 1176 *p = cpu_to_be32(create->u.device.specdata2);
1da177e4
LT
1177 break;
1178
1179 default:
1180 break;
1181 }
1182
811652bd 1183 encode_string(xdr, create->name->len, create->name->name);
5334c5bd 1184 encode_attrs(xdr, create->attrs, create->label, create->server, false);
1da177e4
LT
1185}
1186
cf8cdbe5 1187static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1da177e4 1188{
05d564fe 1189 __be32 *p;
1da177e4 1190
475d4ba0
TM
1191 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1192 p = reserve_space(xdr, 8);
e75bc1c8 1193 *p++ = cpu_to_be32(1);
34558513 1194 *p = cpu_to_be32(bitmap);
1da177e4
LT
1195}
1196
cf8cdbe5 1197static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1da177e4 1198{
05d564fe 1199 __be32 *p;
1da177e4 1200
475d4ba0
TM
1201 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1202 p = reserve_space(xdr, 12);
e75bc1c8
BH
1203 *p++ = cpu_to_be32(2);
1204 *p++ = cpu_to_be32(bm0);
34558513 1205 *p = cpu_to_be32(bm1);
1da177e4
LT
1206}
1207
dae100c2
FI
1208static void
1209encode_getattr_three(struct xdr_stream *xdr,
1210 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1211 struct compound_hdr *hdr)
1212{
1213 __be32 *p;
1214
ab19b481 1215 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
dae100c2
FI
1216 if (bm2) {
1217 p = reserve_space(xdr, 16);
1218 *p++ = cpu_to_be32(3);
1219 *p++ = cpu_to_be32(bm0);
1220 *p++ = cpu_to_be32(bm1);
1221 *p = cpu_to_be32(bm2);
1222 } else if (bm1) {
1223 p = reserve_space(xdr, 12);
1224 *p++ = cpu_to_be32(2);
1225 *p++ = cpu_to_be32(bm0);
1226 *p = cpu_to_be32(bm1);
1227 } else {
1228 p = reserve_space(xdr, 8);
1229 *p++ = cpu_to_be32(1);
1230 *p = cpu_to_be32(bm0);
1231 }
dae100c2
FI
1232}
1233
cf8cdbe5 1234static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1da177e4 1235{
a09df2ca
DQ
1236 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1237 bitmask[1] & nfs4_fattr_bitmap[1],
1238 bitmask[2] & nfs4_fattr_bitmap[2],
1239 hdr);
1da177e4
LT
1240}
1241
88034c3d 1242static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1549210f 1243 const u32 *open_bitmap,
88034c3d
AA
1244 struct compound_hdr *hdr)
1245{
1246 encode_getattr_three(xdr,
1549210f
TM
1247 bitmask[0] & open_bitmap[0],
1248 bitmask[1] & open_bitmap[1],
1249 bitmask[2] & open_bitmap[2],
88034c3d
AA
1250 hdr);
1251}
1252
cf8cdbe5 1253static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1da177e4 1254{
dae100c2
FI
1255 encode_getattr_three(xdr,
1256 bitmask[0] & nfs4_fsinfo_bitmap[0],
1257 bitmask[1] & nfs4_fsinfo_bitmap[1],
1258 bitmask[2] & nfs4_fsinfo_bitmap[2],
1259 hdr);
1da177e4
LT
1260}
1261
cf8cdbe5 1262static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
830b8e33 1263{
cf8cdbe5
AA
1264 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1265 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
830b8e33
MN
1266}
1267
cf8cdbe5 1268static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1269{
ab19b481 1270 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1da177e4
LT
1271}
1272
cf8cdbe5 1273static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1274{
ab19b481 1275 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
6fdfb0bc 1276 encode_string(xdr, name->len, name->name);
1da177e4
LT
1277}
1278
911d1aaf
TM
1279static inline int nfs4_lock_type(struct file_lock *fl, int block)
1280{
f44106e2 1281 if (fl->fl_type == F_RDLCK)
911d1aaf
TM
1282 return block ? NFS4_READW_LT : NFS4_READ_LT;
1283 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1284}
1285
1286static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1287{
1288 if (fl->fl_end == OFFSET_MAX)
1289 return ~(uint64_t)0;
1290 return fl->fl_end - fl->fl_start + 1;
1291}
1292
daccbded
TM
1293static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1294{
1295 __be32 *p;
1296
d035c36c 1297 p = reserve_space(xdr, 32);
daccbded 1298 p = xdr_encode_hyper(p, lowner->clientid);
d035c36c 1299 *p++ = cpu_to_be32(20);
daccbded 1300 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
d035c36c 1301 *p++ = cpu_to_be32(lowner->s_dev);
daccbded
TM
1302 xdr_encode_hyper(p, lowner->id);
1303}
1304
1da177e4
LT
1305/*
1306 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1307 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1308 */
cf8cdbe5 1309static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1da177e4 1310{
8687b63a 1311 __be32 *p;
1da177e4 1312
475d4ba0
TM
1313 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1314 p = reserve_space(xdr, 28);
e75bc1c8
BH
1315 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1316 *p++ = cpu_to_be32(args->reclaim);
b95be5a9
BH
1317 p = xdr_encode_hyper(p, args->fl->fl_start);
1318 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
34558513 1319 *p = cpu_to_be32(args->new_lock_owner);
911d1aaf 1320 if (args->new_lock_owner){
4ade9821 1321 encode_nfs4_seqid(xdr, args->open_seqid);
425c1d4e 1322 encode_nfs4_stateid(xdr, &args->open_stateid);
4ade9821 1323 encode_nfs4_seqid(xdr, args->lock_seqid);
daccbded 1324 encode_lockowner(xdr, &args->lock_owner);
1da177e4
LT
1325 }
1326 else {
425c1d4e 1327 encode_nfs4_stateid(xdr, &args->lock_stateid);
4ade9821 1328 encode_nfs4_seqid(xdr, args->lock_seqid);
1da177e4 1329 }
1da177e4
LT
1330}
1331
cf8cdbe5 1332static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1da177e4 1333{
8687b63a 1334 __be32 *p;
1da177e4 1335
475d4ba0
TM
1336 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1337 p = reserve_space(xdr, 20);
e75bc1c8 1338 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
b95be5a9
BH
1339 p = xdr_encode_hyper(p, args->fl->fl_start);
1340 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
daccbded 1341 encode_lockowner(xdr, &args->lock_owner);
1da177e4
LT
1342}
1343
cf8cdbe5 1344static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1da177e4 1345{
8687b63a 1346 __be32 *p;
1da177e4 1347
475d4ba0
TM
1348 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1349 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
4ade9821 1350 encode_nfs4_seqid(xdr, args->seqid);
425c1d4e 1351 encode_nfs4_stateid(xdr, &args->stateid);
ea9d23f5 1352 p = reserve_space(xdr, 16);
b95be5a9 1353 p = xdr_encode_hyper(p, args->fl->fl_start);
34558513 1354 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1da177e4
LT
1355}
1356
d3c7b7cc
TM
1357static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1358{
ab19b481 1359 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
d3c7b7cc 1360 encode_lockowner(xdr, lowner);
d3c7b7cc
TM
1361}
1362
cf8cdbe5 1363static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1364{
ab19b481 1365 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
6fdfb0bc 1366 encode_string(xdr, name->len, name->name);
1da177e4
LT
1367}
1368
6ae37339 1369static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1da177e4 1370{
8687b63a 1371 __be32 *p;
1da177e4 1372
13c65ce9 1373 p = reserve_space(xdr, 8);
6ae37339 1374 *p++ = cpu_to_be32(share_access);
34558513 1375 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1da177e4
LT
1376}
1377
1378static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1379{
8687b63a 1380 __be32 *p;
1da177e4
LT
1381 /*
1382 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1383 * owner 4 = 32
1384 */
4ade9821 1385 encode_nfs4_seqid(xdr, arg->seqid);
6ae37339 1386 encode_share_access(xdr, arg->share_access);
95b72eb0 1387 p = reserve_space(xdr, 36);
b95be5a9 1388 p = xdr_encode_hyper(p, arg->clientid);
95b72eb0 1389 *p++ = cpu_to_be32(24);
93f0cf25 1390 p = xdr_encode_opaque_fixed(p, "open id:", 8);
d035c36c 1391 *p++ = cpu_to_be32(arg->server->s_dev);
95b72eb0
TM
1392 *p++ = cpu_to_be32(arg->id.uniquifier);
1393 xdr_encode_hyper(p, arg->id.create_time);
1da177e4
LT
1394}
1395
1396static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1397{
8687b63a 1398 __be32 *p;
1da177e4 1399
13c65ce9 1400 p = reserve_space(xdr, 4);
549b19cc
TM
1401 switch(arg->createmode) {
1402 case NFS4_CREATE_UNCHECKED:
34558513 1403 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
5334c5bd 1404 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
05d564fe 1405 break;
549b19cc
TM
1406 case NFS4_CREATE_GUARDED:
1407 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
5334c5bd 1408 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
549b19cc
TM
1409 break;
1410 case NFS4_CREATE_EXCLUSIVE:
1411 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1412 encode_nfs4_verifier(xdr, &arg->u.verifier);
1413 break;
1414 case NFS4_CREATE_EXCLUSIVE4_1:
1415 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1416 encode_nfs4_verifier(xdr, &arg->u.verifier);
5334c5bd 1417 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true);
1da177e4
LT
1418 }
1419}
1420
1421static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1422{
8687b63a 1423 __be32 *p;
1da177e4 1424
13c65ce9 1425 p = reserve_space(xdr, 4);
1da177e4 1426 switch (arg->open_flags & O_CREAT) {
05d564fe 1427 case 0:
34558513 1428 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
05d564fe
AA
1429 break;
1430 default:
34558513 1431 *p = cpu_to_be32(NFS4_OPEN_CREATE);
05d564fe 1432 encode_createmode(xdr, arg);
1da177e4
LT
1433 }
1434}
1435
bd7bf9d5 1436static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1da177e4 1437{
8687b63a 1438 __be32 *p;
1da177e4 1439
13c65ce9 1440 p = reserve_space(xdr, 4);
1da177e4 1441 switch (delegation_type) {
05d564fe 1442 case 0:
34558513 1443 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
05d564fe
AA
1444 break;
1445 case FMODE_READ:
34558513 1446 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
05d564fe
AA
1447 break;
1448 case FMODE_WRITE|FMODE_READ:
34558513 1449 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
05d564fe
AA
1450 break;
1451 default:
1452 BUG();
1da177e4
LT
1453 }
1454}
1455
1456static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1457{
8687b63a 1458 __be32 *p;
1da177e4 1459
13c65ce9 1460 p = reserve_space(xdr, 4);
34558513 1461 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1da177e4
LT
1462 encode_string(xdr, name->len, name->name);
1463}
1464
bd7bf9d5 1465static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1da177e4 1466{
8687b63a 1467 __be32 *p;
1da177e4 1468
13c65ce9 1469 p = reserve_space(xdr, 4);
34558513 1470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1da177e4
LT
1471 encode_delegation_type(xdr, type);
1472}
1473
1474static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1475{
8687b63a 1476 __be32 *p;
1da177e4 1477
ea9d23f5
TM
1478 p = reserve_space(xdr, 4);
1479 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1480 encode_nfs4_stateid(xdr, stateid);
1da177e4
LT
1481 encode_string(xdr, name->len, name->name);
1482}
1483
d9fc6619
TM
1484static inline void encode_claim_fh(struct xdr_stream *xdr)
1485{
1486 __be32 *p;
1487
1488 p = reserve_space(xdr, 4);
1489 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1490}
1491
1492static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1493{
1494 __be32 *p;
1495
1496 p = reserve_space(xdr, 4);
1497 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1498 encode_nfs4_stateid(xdr, stateid);
1499}
1500
cf8cdbe5 1501static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1da177e4 1502{
ab19b481 1503 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1da177e4
LT
1504 encode_openhdr(xdr, arg);
1505 encode_opentype(xdr, arg);
1506 switch (arg->claim) {
05d564fe
AA
1507 case NFS4_OPEN_CLAIM_NULL:
1508 encode_claim_null(xdr, arg->name);
1509 break;
1510 case NFS4_OPEN_CLAIM_PREVIOUS:
1511 encode_claim_previous(xdr, arg->u.delegation_type);
1512 break;
1513 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1514 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1515 break;
d9fc6619
TM
1516 case NFS4_OPEN_CLAIM_FH:
1517 encode_claim_fh(xdr);
1518 break;
1519 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1520 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1521 break;
05d564fe
AA
1522 default:
1523 BUG();
1da177e4 1524 }
1da177e4
LT
1525}
1526
cf8cdbe5 1527static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1da177e4 1528{
ab19b481 1529 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
ea9d23f5 1530 encode_nfs4_stateid(xdr, arg->stateid);
4ade9821 1531 encode_nfs4_seqid(xdr, arg->seqid);
1da177e4
LT
1532}
1533
cf8cdbe5 1534static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1da177e4 1535{
ab19b481 1536 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
566fcec6 1537 encode_nfs4_stateid(xdr, &arg->stateid);
4ade9821 1538 encode_nfs4_seqid(xdr, arg->seqid);
6ae37339 1539 encode_share_access(xdr, arg->share_access);
1da177e4
LT
1540}
1541
cf8cdbe5 1542static void
d017931c 1543encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1da177e4 1544{
ab19b481 1545 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
6fdfb0bc 1546 encode_string(xdr, fh->size, fh->data);
1da177e4
LT
1547}
1548
cf8cdbe5 1549static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1550{
ab19b481 1551 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1da177e4
LT
1552}
1553
3c6b899c
AS
1554static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1555 struct compound_hdr *hdr)
1da177e4 1556{
8687b63a 1557 __be32 *p;
1da177e4 1558
ab19b481 1559 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
9b206149 1560 encode_nfs4_stateid(xdr, &args->stateid);
1da177e4 1561
13c65ce9 1562 p = reserve_space(xdr, 12);
b95be5a9 1563 p = xdr_encode_hyper(p, args->offset);
34558513 1564 *p = cpu_to_be32(args->count);
1da177e4
LT
1565}
1566
cf8cdbe5 1567static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1da177e4 1568{
aa9c2669 1569 uint32_t attrs[3] = {
28331a46
TM
1570 FATTR4_WORD0_RDATTR_ERROR,
1571 FATTR4_WORD1_MOUNTED_ON_FILEID,
1572 };
6f7a35bd 1573 uint32_t dircount = readdir->count >> 1;
cd93710e 1574 __be32 *p, verf[2];
d204c5d2
TM
1575 uint32_t attrlen = 0;
1576 unsigned int i;
1da177e4 1577
82f2e547
BS
1578 if (readdir->plus) {
1579 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
28331a46 1580 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
82f2e547
BS
1581 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1582 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1583 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1584 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
d204c5d2 1585 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
6f7a35bd 1586 dircount >>= 1;
82f2e547 1587 }
28331a46
TM
1588 /* Use mounted_on_fileid only if the server supports it */
1589 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1590 attrs[0] |= FATTR4_WORD0_FILEID;
d204c5d2
TM
1591 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1592 attrs[i] &= readdir->bitmask[i];
1593 if (attrs[i] != 0)
1594 attrlen = i+1;
1595 }
82f2e547 1596
475d4ba0 1597 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
ff2eb681 1598 encode_uint64(xdr, readdir->cookie);
cd93710e 1599 encode_nfs4_verifier(xdr, &readdir->verifier);
d204c5d2 1600 p = reserve_space(xdr, 12 + (attrlen << 2));
6f7a35bd 1601 *p++ = cpu_to_be32(dircount);
e75bc1c8 1602 *p++ = cpu_to_be32(readdir->count);
d204c5d2
TM
1603 *p++ = cpu_to_be32(attrlen);
1604 for (i = 0; i < attrlen; i++)
1605 *p++ = cpu_to_be32(attrs[i]);
cd93710e 1606 memcpy(verf, readdir->verifier.data, sizeof(verf));
aa9c2669
DQ
1607
1608 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
44109241 1609 __func__,
eadf4598 1610 (unsigned long long)readdir->cookie,
cd93710e 1611 verf[0], verf[1],
eadf4598 1612 attrs[0] & readdir->bitmask[0],
aa9c2669
DQ
1613 attrs[1] & readdir->bitmask[1],
1614 attrs[2] & readdir->bitmask[2]);
1da177e4
LT
1615}
1616
cf8cdbe5 1617static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1da177e4 1618{
ab19b481 1619 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1da177e4
LT
1620}
1621
cf8cdbe5 1622static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1623{
ab19b481 1624 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
6fdfb0bc 1625 encode_string(xdr, name->len, name->name);
1da177e4
LT
1626}
1627
cf8cdbe5 1628static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1da177e4 1629{
ab19b481 1630 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
811652bd
BH
1631 encode_string(xdr, oldname->len, oldname->name);
1632 encode_string(xdr, newname->len, newname->name);
1da177e4
LT
1633}
1634
bb4dae5e
CL
1635static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1636 struct compound_hdr *hdr)
1da177e4 1637{
475d4ba0 1638 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
ff2eb681 1639 encode_uint64(xdr, clid);
1da177e4
LT
1640}
1641
cf8cdbe5 1642static void
d017931c 1643encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
56ae19f3 1644{
ab19b481 1645 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
56ae19f3
TM
1646}
1647
9f06c719 1648static void
d017931c 1649encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
23ec6965 1650{
8687b63a 1651 __be32 *p;
23ec6965 1652
ab19b481 1653 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
ea9d23f5 1654 encode_nfs4_stateid(xdr, &zero_stateid);
13c65ce9 1655 p = reserve_space(xdr, 2*4);
e75bc1c8 1656 *p++ = cpu_to_be32(1);
34558513 1657 *p = cpu_to_be32(FATTR4_WORD0_ACL);
13c65ce9 1658 p = reserve_space(xdr, 4);
34558513 1659 *p = cpu_to_be32(arg->acl_len);
8fbcf237 1660 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
23ec6965
BF
1661}
1662
cf8cdbe5 1663static void
d017931c 1664encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1665{
ab19b481 1666 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1da177e4
LT
1667}
1668
cf8cdbe5 1669static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1da177e4 1670{
ab19b481 1671 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
ea9d23f5 1672 encode_nfs4_stateid(xdr, &arg->stateid);
5334c5bd 1673 encode_attrs(xdr, arg->iap, arg->label, server, false);
1da177e4
LT
1674}
1675
cf8cdbe5 1676static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1da177e4 1677{
8687b63a 1678 __be32 *p;
1da177e4 1679
70019514 1680 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
cd93710e 1681 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1da177e4 1682
3a6bb738
JL
1683 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1684 setclientid->sc_clnt->cl_owner_id);
13c65ce9 1685 p = reserve_space(xdr, 4);
34558513 1686 *p = cpu_to_be32(setclientid->sc_prog);
1da177e4
LT
1687 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1688 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
13c65ce9 1689 p = reserve_space(xdr, 4);
3a6bb738 1690 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1da177e4
LT
1691}
1692
bb8b27e5 1693static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1da177e4 1694{
475d4ba0
TM
1695 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1696 decode_setclientid_confirm_maxsz, hdr);
ff2eb681 1697 encode_uint64(xdr, arg->clientid);
cd93710e 1698 encode_nfs4_verifier(xdr, &arg->confirm);
1da177e4
LT
1699}
1700
3c6b899c
AS
1701static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1702 struct compound_hdr *hdr)
1da177e4 1703{
8687b63a 1704 __be32 *p;
1da177e4 1705
ab19b481 1706 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
9b206149 1707 encode_nfs4_stateid(xdr, &args->stateid);
1da177e4 1708
13c65ce9 1709 p = reserve_space(xdr, 16);
b95be5a9 1710 p = xdr_encode_hyper(p, args->offset);
e75bc1c8 1711 *p++ = cpu_to_be32(args->stable);
34558513 1712 *p = cpu_to_be32(args->count);
1da177e4
LT
1713
1714 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1da177e4
LT
1715}
1716
cf8cdbe5 1717static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1da177e4 1718{
ab19b481 1719 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
ea9d23f5 1720 encode_nfs4_stateid(xdr, stateid);
1da177e4 1721}
9b7b9fcc 1722
5a5ea0d4
BS
1723static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1724{
ab19b481 1725 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
6fdfb0bc 1726 encode_string(xdr, name->len, name->name);
5a5ea0d4
BS
1727}
1728
99fe60d0 1729#if defined(CONFIG_NFS_V4_1)
9b7b9fcc 1730/* NFSv4.1 operations */
7c44f1ae 1731static void encode_bind_conn_to_session(struct xdr_stream *xdr,
71a097c6 1732 struct nfs41_bind_conn_to_session_args *args,
7c44f1ae
WAA
1733 struct compound_hdr *hdr)
1734{
1735 __be32 *p;
1736
1737 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1738 decode_bind_conn_to_session_maxsz, hdr);
71a097c6 1739 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
7c44f1ae 1740 p = xdr_reserve_space(xdr, 8);
71a097c6
TM
1741 *p++ = cpu_to_be32(args->dir);
1742 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
7c44f1ae
WAA
1743}
1744
2031cd1a
WAA
1745static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1746{
1747 unsigned int i;
1748 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1749 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1750 encode_uint32(xdr, op_map->u.words[i]);
1751}
1752
99fe60d0
BH
1753static void encode_exchange_id(struct xdr_stream *xdr,
1754 struct nfs41_exchange_id_args *args,
1755 struct compound_hdr *hdr)
1756{
1757 __be32 *p;
d751f748 1758 char impl_name[IMPL_NAME_LIMIT];
db8ac8ba 1759 int len = 0;
99fe60d0 1760
70019514 1761 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
cd93710e 1762 encode_nfs4_verifier(xdr, args->verifier);
99fe60d0 1763
3a6bb738
JL
1764 encode_string(xdr, strlen(args->client->cl_owner_id),
1765 args->client->cl_owner_id);
99fe60d0 1766
2031cd1a
WAA
1767 encode_uint32(xdr, args->flags);
1768 encode_uint32(xdr, args->state_protect.how);
1769
1770 switch (args->state_protect.how) {
1771 case SP4_NONE:
1772 break;
1773 case SP4_MACH_CRED:
1774 encode_op_map(xdr, &args->state_protect.enforce);
1775 encode_op_map(xdr, &args->state_protect.allow);
1776 break;
1777 default:
1778 WARN_ON_ONCE(1);
1779 break;
1780 }
db8ac8ba
WAA
1781
1782 if (send_implementation_id &&
1783 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1784 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
d751f748 1785 <= sizeof(impl_name) + 1)
db8ac8ba
WAA
1786 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1787 utsname()->sysname, utsname()->release,
1788 utsname()->version, utsname()->machine);
1789
1790 if (len > 0) {
2031cd1a 1791 encode_uint32(xdr, 1); /* implementation id array length=1 */
db8ac8ba
WAA
1792
1793 encode_string(xdr,
1794 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1795 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1796 encode_string(xdr, len, impl_name);
1797 /* just send zeros for nii_date - the date is in nii_name */
1798 p = reserve_space(xdr, 12);
1799 p = xdr_encode_hyper(p, 0);
1800 *p = cpu_to_be32(0);
1801 } else
2031cd1a 1802 encode_uint32(xdr, 0); /* implementation id array length=0 */
99fe60d0 1803}
fc931582
AA
1804
1805static void encode_create_session(struct xdr_stream *xdr,
1806 struct nfs41_create_session_args *args,
1807 struct compound_hdr *hdr)
1808{
1809 __be32 *p;
fc931582 1810 struct nfs_client *clp = args->client;
89f0ff38 1811 struct rpc_clnt *clnt = clp->cl_rpcclient;
f092075d 1812 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
8e0d46e1
MS
1813 u32 max_resp_sz_cached;
1814
1815 /*
1816 * Assumes OPEN is the biggest non-idempotent compound.
1817 * 2 is the verifier.
1818 */
1819 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1820 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
fc931582 1821
475d4ba0 1822 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
89f0ff38 1823 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
79969dd1
TM
1824 p = xdr_encode_hyper(p, args->clientid);
1825 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
e75bc1c8 1826 *p++ = cpu_to_be32(args->flags); /*flags */
fc931582 1827
fc931582 1828 /* Fore Channel */
c9c30dd5 1829 *p++ = cpu_to_be32(0); /* header padding size */
e75bc1c8
BH
1830 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1831 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
8e0d46e1 1832 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
e75bc1c8
BH
1833 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1834 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1835 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
fc931582
AA
1836
1837 /* Back Channel */
c9c30dd5 1838 *p++ = cpu_to_be32(0); /* header padding size */
e75bc1c8
BH
1839 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1840 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1841 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1842 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1843 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1844 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
fc931582 1845
e75bc1c8 1846 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
e75bc1c8 1847 *p++ = cpu_to_be32(1);
e75bc1c8 1848 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
fc931582
AA
1849
1850 /* authsys_parms rfc1831 */
2f86e091 1851 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
89f0ff38 1852 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
e75bc1c8
BH
1853 *p++ = cpu_to_be32(0); /* UID */
1854 *p++ = cpu_to_be32(0); /* GID */
34558513 1855 *p = cpu_to_be32(0); /* No more gids */
fc931582 1856}
0f3e66c6
AA
1857
1858static void encode_destroy_session(struct xdr_stream *xdr,
1859 struct nfs4_session *session,
1860 struct compound_hdr *hdr)
1861{
475d4ba0
TM
1862 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1863 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
0f3e66c6 1864}
18019753 1865
66245539
TM
1866static void encode_destroy_clientid(struct xdr_stream *xdr,
1867 uint64_t clientid,
1868 struct compound_hdr *hdr)
1869{
1870 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1871 encode_uint64(xdr, clientid);
1872}
1873
18019753
RL
1874static void encode_reclaim_complete(struct xdr_stream *xdr,
1875 struct nfs41_reclaim_complete_args *args,
1876 struct compound_hdr *hdr)
1877{
475d4ba0
TM
1878 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1879 encode_uint32(xdr, args->one_fs);
18019753 1880}
99fe60d0
BH
1881#endif /* CONFIG_NFS_V4_1 */
1882
9b7b9fcc
AA
1883static void encode_sequence(struct xdr_stream *xdr,
1884 const struct nfs4_sequence_args *args,
1885 struct compound_hdr *hdr)
1886{
1887#if defined(CONFIG_NFS_V4_1)
2b2fa717 1888 struct nfs4_session *session;
fc01cea9 1889 struct nfs4_slot_table *tp;
2b2fa717 1890 struct nfs4_slot *slot = args->sa_slot;
fc01cea9 1891 __be32 *p;
9b7b9fcc 1892
2b2fa717
TM
1893 tp = slot->table;
1894 session = tp->session;
3bd2384a
CL
1895 if (!session)
1896 return;
fc01cea9 1897
475d4ba0 1898 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
fc01cea9
AA
1899
1900 /*
1901 * Sessionid + seqid + slotid + max slotid + cache_this
1902 */
1903 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1904 "max_slotid=%d cache_this=%d\n",
1905 __func__,
1906 ((u32 *)session->sess_id.data)[0],
1907 ((u32 *)session->sess_id.data)[1],
1908 ((u32 *)session->sess_id.data)[2],
1909 ((u32 *)session->sess_id.data)[3],
2b2fa717 1910 slot->seq_nr, slot->slot_nr,
fc01cea9 1911 tp->highest_used_slotid, args->sa_cache_this);
475d4ba0 1912 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
93f0cf25 1913 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
e75bc1c8 1914 *p++ = cpu_to_be32(slot->seq_nr);
2b2fa717 1915 *p++ = cpu_to_be32(slot->slot_nr);
e75bc1c8 1916 *p++ = cpu_to_be32(tp->highest_used_slotid);
34558513 1917 *p = cpu_to_be32(args->sa_cache_this);
9b7b9fcc
AA
1918#endif /* CONFIG_NFS_V4_1 */
1919}
1920
b1f69b75
AA
1921#ifdef CONFIG_NFS_V4_1
1922static void
1923encode_getdeviceinfo(struct xdr_stream *xdr,
1924 const struct nfs4_getdeviceinfo_args *args,
1925 struct compound_hdr *hdr)
1926{
1927 __be32 *p;
1928
475d4ba0 1929 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
84c9dee3 1930 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
b1f69b75
AA
1931 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1932 NFS4_DEVICEID4_SIZE);
1933 *p++ = cpu_to_be32(args->pdev->layout_type);
f1c097be 1934 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
84c9dee3
CH
1935
1936 p = reserve_space(xdr, 4 + 4);
1937 *p++ = cpu_to_be32(1); /* bitmap length */
4e590803 1938 *p++ = cpu_to_be32(args->notify_types);
b1f69b75
AA
1939}
1940
1941static void
1942encode_layoutget(struct xdr_stream *xdr,
1943 const struct nfs4_layoutget_args *args,
1944 struct compound_hdr *hdr)
1945{
b1f69b75
AA
1946 __be32 *p;
1947
475d4ba0
TM
1948 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1949 p = reserve_space(xdr, 36);
b1f69b75
AA
1950 *p++ = cpu_to_be32(0); /* Signal layout available */
1951 *p++ = cpu_to_be32(args->type);
1952 *p++ = cpu_to_be32(args->range.iomode);
1953 p = xdr_encode_hyper(p, args->range.offset);
1954 p = xdr_encode_hyper(p, args->range.length);
1955 p = xdr_encode_hyper(p, args->minlength);
ea9d23f5 1956 encode_nfs4_stateid(xdr, &args->stateid);
475d4ba0 1957 encode_uint32(xdr, args->maxcount);
b1f69b75
AA
1958
1959 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1960 __func__,
1961 args->type,
1962 args->range.iomode,
1963 (unsigned long)args->range.offset,
1964 (unsigned long)args->range.length,
1965 args->maxcount);
b1f69b75 1966}
863a3c6c
AA
1967
1968static int
1969encode_layoutcommit(struct xdr_stream *xdr,
ac7db726 1970 struct inode *inode,
5f919c9f 1971 struct nfs4_layoutcommit_args *args,
863a3c6c
AA
1972 struct compound_hdr *hdr)
1973{
1974 __be32 *p;
1975
1976 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1977 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1978
475d4ba0
TM
1979 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1980 p = reserve_space(xdr, 20);
863a3c6c
AA
1981 /* Only whole file layouts */
1982 p = xdr_encode_hyper(p, 0); /* offset */
3557c6c3 1983 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
ea9d23f5
TM
1984 *p = cpu_to_be32(0); /* reclaim */
1985 encode_nfs4_stateid(xdr, &args->stateid);
2e18d4d8
TM
1986 if (args->lastbytewritten != U64_MAX) {
1987 p = reserve_space(xdr, 20);
1988 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1989 p = xdr_encode_hyper(p, args->lastbytewritten);
1990 } else {
1991 p = reserve_space(xdr, 12);
1992 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
1993 }
863a3c6c
AA
1994 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1995 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
ac7db726 1996
5f919c9f 1997 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
ac7db726
BH
1998 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1999 NFS_I(inode)->layout, xdr, args);
5f919c9f
CH
2000 } else {
2001 encode_uint32(xdr, args->layoutupdate_len);
2002 if (args->layoutupdate_pages) {
2003 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2004 args->layoutupdate_len);
2005 }
2006 }
863a3c6c 2007
863a3c6c
AA
2008 return 0;
2009}
cbe82603
BH
2010
2011static void
2012encode_layoutreturn(struct xdr_stream *xdr,
2013 const struct nfs4_layoutreturn_args *args,
2014 struct compound_hdr *hdr)
2015{
2016 __be32 *p;
2017
475d4ba0
TM
2018 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2019 p = reserve_space(xdr, 16);
cbe82603
BH
2020 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2021 *p++ = cpu_to_be32(args->layout_type);
15eb67c1 2022 *p++ = cpu_to_be32(args->range.iomode);
cbe82603 2023 *p = cpu_to_be32(RETURN_FILE);
ea9d23f5 2024 p = reserve_space(xdr, 16);
15eb67c1
PT
2025 p = xdr_encode_hyper(p, args->range.offset);
2026 p = xdr_encode_hyper(p, args->range.length);
cbe82603 2027 spin_lock(&args->inode->i_lock);
ea9d23f5 2028 encode_nfs4_stateid(xdr, &args->stateid);
cbe82603 2029 spin_unlock(&args->inode->i_lock);
04a55549
AA
2030 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2031 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2032 NFS_I(args->inode)->layout, xdr, args);
475d4ba0
TM
2033 } else
2034 encode_uint32(xdr, 0);
cbe82603 2035}
fca78d6d
BS
2036
2037static int
2038encode_secinfo_no_name(struct xdr_stream *xdr,
2039 const struct nfs41_secinfo_no_name_args *args,
2040 struct compound_hdr *hdr)
2041{
475d4ba0
TM
2042 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2043 encode_uint32(xdr, args->style);
fca78d6d
BS
2044 return 0;
2045}
7d974794
BS
2046
2047static void encode_test_stateid(struct xdr_stream *xdr,
2048 struct nfs41_test_stateid_args *args,
2049 struct compound_hdr *hdr)
2050{
475d4ba0
TM
2051 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2052 encode_uint32(xdr, 1);
ea9d23f5 2053 encode_nfs4_stateid(xdr, args->stateid);
7d974794 2054}
9aeda35f
BS
2055
2056static void encode_free_stateid(struct xdr_stream *xdr,
2057 struct nfs41_free_stateid_args *args,
2058 struct compound_hdr *hdr)
2059{
ab19b481 2060 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
7c1d5fae 2061 encode_nfs4_stateid(xdr, &args->stateid);
9aeda35f 2062}
b1f69b75
AA
2063#endif /* CONFIG_NFS_V4_1 */
2064
1da177e4
LT
2065/*
2066 * END OF "GENERIC" ENCODE ROUTINES.
2067 */
2068
66cc0429
BH
2069static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2070{
2071#if defined(CONFIG_NFS_V4_1)
3bd2384a
CL
2072 struct nfs4_session *session = args->sa_slot->table->session;
2073 if (session)
2074 return session->clp->cl_mvops->minor_version;
66cc0429
BH
2075#endif /* CONFIG_NFS_V4_1 */
2076 return 0;
2077}
2078
1da177e4
LT
2079/*
2080 * Encode an ACCESS request
2081 */
9f06c719
CL
2082static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2083 const struct nfs4_accessargs *args)
1da177e4 2084{
1da177e4 2085 struct compound_hdr hdr = {
66cc0429 2086 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2087 };
1da177e4 2088
9f06c719
CL
2089 encode_compound_hdr(xdr, req, &hdr);
2090 encode_sequence(xdr, &args->seq_args, &hdr);
2091 encode_putfh(xdr, args->fh, &hdr);
2092 encode_access(xdr, args->access, &hdr);
2093 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2094 encode_nops(&hdr);
1da177e4
LT
2095}
2096
2097/*
2098 * Encode LOOKUP request
2099 */
9f06c719
CL
2100static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2101 const struct nfs4_lookup_arg *args)
1da177e4 2102{
1da177e4 2103 struct compound_hdr hdr = {
66cc0429 2104 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2105 };
1da177e4 2106
9f06c719
CL
2107 encode_compound_hdr(xdr, req, &hdr);
2108 encode_sequence(xdr, &args->seq_args, &hdr);
2109 encode_putfh(xdr, args->dir_fh, &hdr);
2110 encode_lookup(xdr, args->name, &hdr);
2111 encode_getfh(xdr, &hdr);
2112 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2113 encode_nops(&hdr);
1da177e4
LT
2114}
2115
2116/*
2117 * Encode LOOKUP_ROOT request
2118 */
9f06c719
CL
2119static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2120 struct xdr_stream *xdr,
2121 const struct nfs4_lookup_root_arg *args)
1da177e4 2122{
1da177e4 2123 struct compound_hdr hdr = {
66cc0429 2124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2125 };
1da177e4 2126
9f06c719
CL
2127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putrootfh(xdr, &hdr);
2130 encode_getfh(xdr, &hdr);
2131 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2132 encode_nops(&hdr);
1da177e4
LT
2133}
2134
2135/*
2136 * Encode REMOVE request
2137 */
9f06c719
CL
2138static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2139 const struct nfs_removeargs *args)
1da177e4 2140{
1da177e4 2141 struct compound_hdr hdr = {
66cc0429 2142 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2143 };
1da177e4 2144
9f06c719
CL
2145 encode_compound_hdr(xdr, req, &hdr);
2146 encode_sequence(xdr, &args->seq_args, &hdr);
2147 encode_putfh(xdr, args->fh, &hdr);
2148 encode_remove(xdr, &args->name, &hdr);
d017931c 2149 encode_nops(&hdr);
1da177e4
LT
2150}
2151
2152/*
2153 * Encode RENAME request
2154 */
9f06c719
CL
2155static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 const struct nfs_renameargs *args)
1da177e4 2157{
1da177e4 2158 struct compound_hdr hdr = {
66cc0429 2159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2160 };
1da177e4 2161
9f06c719
CL
2162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->old_dir, &hdr);
2165 encode_savefh(xdr, &hdr);
2166 encode_putfh(xdr, args->new_dir, &hdr);
2167 encode_rename(xdr, args->old_name, args->new_name, &hdr);
d017931c 2168 encode_nops(&hdr);
1da177e4
LT
2169}
2170
2171/*
2172 * Encode LINK request
2173 */
9f06c719
CL
2174static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2175 const struct nfs4_link_arg *args)
1da177e4 2176{
1da177e4 2177 struct compound_hdr hdr = {
66cc0429 2178 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2179 };
1da177e4 2180
9f06c719
CL
2181 encode_compound_hdr(xdr, req, &hdr);
2182 encode_sequence(xdr, &args->seq_args, &hdr);
2183 encode_putfh(xdr, args->fh, &hdr);
2184 encode_savefh(xdr, &hdr);
2185 encode_putfh(xdr, args->dir_fh, &hdr);
2186 encode_link(xdr, args->name, &hdr);
9f06c719
CL
2187 encode_restorefh(xdr, &hdr);
2188 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2189 encode_nops(&hdr);
1da177e4
LT
2190}
2191
2192/*
2193 * Encode CREATE request
2194 */
9f06c719
CL
2195static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2196 const struct nfs4_create_arg *args)
1da177e4 2197{
1da177e4 2198 struct compound_hdr hdr = {
66cc0429 2199 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2200 };
1da177e4 2201
9f06c719
CL
2202 encode_compound_hdr(xdr, req, &hdr);
2203 encode_sequence(xdr, &args->seq_args, &hdr);
2204 encode_putfh(xdr, args->dir_fh, &hdr);
9f06c719
CL
2205 encode_create(xdr, args, &hdr);
2206 encode_getfh(xdr, &hdr);
2207 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2208 encode_nops(&hdr);
1da177e4
LT
2209}
2210
2211/*
2212 * Encode SYMLINK request
2213 */
9f06c719
CL
2214static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 const struct nfs4_create_arg *args)
1da177e4 2216{
9f06c719 2217 nfs4_xdr_enc_create(req, xdr, args);
1da177e4
LT
2218}
2219
2220/*
2221 * Encode GETATTR request
2222 */
9f06c719
CL
2223static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2224 const struct nfs4_getattr_arg *args)
1da177e4 2225{
1da177e4 2226 struct compound_hdr hdr = {
66cc0429 2227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2228 };
1da177e4 2229
9f06c719
CL
2230 encode_compound_hdr(xdr, req, &hdr);
2231 encode_sequence(xdr, &args->seq_args, &hdr);
2232 encode_putfh(xdr, args->fh, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2234 encode_nops(&hdr);
1da177e4
LT
2235}
2236
2237/*
2238 * Encode a CLOSE request
2239 */
9f06c719
CL
2240static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2241 struct nfs_closeargs *args)
1da177e4 2242{
05d564fe 2243 struct compound_hdr hdr = {
66cc0429 2244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 2245 };
05d564fe 2246
9f06c719
CL
2247 encode_compound_hdr(xdr, req, &hdr);
2248 encode_sequence(xdr, &args->seq_args, &hdr);
2249 encode_putfh(xdr, args->fh, &hdr);
2250 encode_close(xdr, args, &hdr);
3ecefc92
TM
2251 if (args->bitmask != NULL)
2252 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2253 encode_nops(&hdr);
1da177e4
LT
2254}
2255
2256/*
2257 * Encode an OPEN request
2258 */
9f06c719
CL
2259static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2260 struct nfs_openargs *args)
1da177e4 2261{
1da177e4 2262 struct compound_hdr hdr = {
66cc0429 2263 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2264 };
1da177e4 2265
9f06c719
CL
2266 encode_compound_hdr(xdr, req, &hdr);
2267 encode_sequence(xdr, &args->seq_args, &hdr);
2268 encode_putfh(xdr, args->fh, &hdr);
9f06c719
CL
2269 encode_open(xdr, args, &hdr);
2270 encode_getfh(xdr, &hdr);
ae2bb032
WAA
2271 if (args->access)
2272 encode_access(xdr, args->access, &hdr);
1549210f 2273 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
d017931c 2274 encode_nops(&hdr);
1da177e4
LT
2275}
2276
2277/*
2278 * Encode an OPEN_CONFIRM request
2279 */
9f06c719
CL
2280static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2281 struct xdr_stream *xdr,
2282 struct nfs_open_confirmargs *args)
1da177e4 2283{
1da177e4 2284 struct compound_hdr hdr = {
d017931c 2285 .nops = 0,
1da177e4 2286 };
1da177e4 2287
9f06c719
CL
2288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_putfh(xdr, args->fh, &hdr);
2290 encode_open_confirm(xdr, args, &hdr);
d017931c 2291 encode_nops(&hdr);
1da177e4
LT
2292}
2293
2294/*
2295 * Encode an OPEN request with no attributes.
2296 */
9f06c719
CL
2297static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2298 struct xdr_stream *xdr,
2299 struct nfs_openargs *args)
1da177e4 2300{
1da177e4 2301 struct compound_hdr hdr = {
66cc0429 2302 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2303 };
1da177e4 2304
9f06c719
CL
2305 encode_compound_hdr(xdr, req, &hdr);
2306 encode_sequence(xdr, &args->seq_args, &hdr);
2307 encode_putfh(xdr, args->fh, &hdr);
2308 encode_open(xdr, args, &hdr);
ae2bb032
WAA
2309 if (args->access)
2310 encode_access(xdr, args->access, &hdr);
e23008ec 2311 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
d017931c 2312 encode_nops(&hdr);
1da177e4
LT
2313}
2314
2315/*
2316 * Encode an OPEN_DOWNGRADE request
2317 */
9f06c719
CL
2318static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2319 struct xdr_stream *xdr,
2320 struct nfs_closeargs *args)
1da177e4 2321{
1da177e4 2322 struct compound_hdr hdr = {
66cc0429 2323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2324 };
1da177e4 2325
9f06c719
CL
2326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_open_downgrade(xdr, args, &hdr);
d017931c 2330 encode_nops(&hdr);
1da177e4
LT
2331}
2332
2333/*
2334 * Encode a LOCK request
2335 */
9f06c719
CL
2336static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 struct nfs_lock_args *args)
1da177e4 2338{
1da177e4 2339 struct compound_hdr hdr = {
66cc0429 2340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2341 };
1da177e4 2342
9f06c719
CL
2343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_lock(xdr, args, &hdr);
d017931c 2347 encode_nops(&hdr);
1da177e4
LT
2348}
2349
2350/*
2351 * Encode a LOCKT request
2352 */
9f06c719
CL
2353static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2354 struct nfs_lockt_args *args)
1da177e4 2355{
1da177e4 2356 struct compound_hdr hdr = {
66cc0429 2357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2358 };
1da177e4 2359
9f06c719
CL
2360 encode_compound_hdr(xdr, req, &hdr);
2361 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_putfh(xdr, args->fh, &hdr);
2363 encode_lockt(xdr, args, &hdr);
d017931c 2364 encode_nops(&hdr);
1da177e4
LT
2365}
2366
2367/*
2368 * Encode a LOCKU request
2369 */
9f06c719
CL
2370static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2371 struct nfs_locku_args *args)
1da177e4 2372{
1da177e4 2373 struct compound_hdr hdr = {
66cc0429 2374 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2375 };
1da177e4 2376
9f06c719
CL
2377 encode_compound_hdr(xdr, req, &hdr);
2378 encode_sequence(xdr, &args->seq_args, &hdr);
2379 encode_putfh(xdr, args->fh, &hdr);
2380 encode_locku(xdr, args, &hdr);
d017931c 2381 encode_nops(&hdr);
1da177e4
LT
2382}
2383
9f06c719
CL
2384static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2385 struct xdr_stream *xdr,
2386 struct nfs_release_lockowner_args *args)
d3c7b7cc 2387{
d3c7b7cc
TM
2388 struct compound_hdr hdr = {
2389 .minorversion = 0,
2390 };
2391
9f06c719
CL
2392 encode_compound_hdr(xdr, req, &hdr);
2393 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
d3c7b7cc 2394 encode_nops(&hdr);
d3c7b7cc
TM
2395}
2396
1da177e4
LT
2397/*
2398 * Encode a READLINK request
2399 */
9f06c719
CL
2400static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 const struct nfs4_readlink *args)
1da177e4 2402{
1da177e4 2403 struct compound_hdr hdr = {
66cc0429 2404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2405 };
1da177e4 2406
9f06c719
CL
2407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_readlink(xdr, args, req, &hdr);
e3a535e1 2411
28f56694 2412 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
e3a535e1 2413 args->pgbase, args->pglen);
d017931c 2414 encode_nops(&hdr);
1da177e4
LT
2415}
2416
2417/*
2418 * Encode a READDIR request
2419 */
9f06c719
CL
2420static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2421 const struct nfs4_readdir_arg *args)
1da177e4 2422{
1da177e4 2423 struct compound_hdr hdr = {
66cc0429 2424 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2425 };
1da177e4 2426
9f06c719
CL
2427 encode_compound_hdr(xdr, req, &hdr);
2428 encode_sequence(xdr, &args->seq_args, &hdr);
2429 encode_putfh(xdr, args->fh, &hdr);
2430 encode_readdir(xdr, args, req, &hdr);
d6ac02df 2431
28f56694 2432 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
d6ac02df
TM
2433 args->pgbase, args->count);
2434 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
28f56694 2435 __func__, hdr.replen << 2, args->pages,
d6ac02df 2436 args->pgbase, args->count);
d017931c 2437 encode_nops(&hdr);
1da177e4
LT
2438}
2439
2440/*
2441 * Encode a READ request
2442 */
9f06c719 2443static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
3c6b899c 2444 struct nfs_pgio_args *args)
1da177e4 2445{
1da177e4 2446 struct compound_hdr hdr = {
66cc0429 2447 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2448 };
1da177e4 2449
9f06c719
CL
2450 encode_compound_hdr(xdr, req, &hdr);
2451 encode_sequence(xdr, &args->seq_args, &hdr);
2452 encode_putfh(xdr, args->fh, &hdr);
2453 encode_read(xdr, args, &hdr);
1da177e4 2454
28f56694 2455 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
1da177e4 2456 args->pages, args->pgbase, args->count);
4f22ccc3 2457 req->rq_rcv_buf.flags |= XDRBUF_READ;
d017931c 2458 encode_nops(&hdr);
1da177e4
LT
2459}
2460
2461/*
2462 * Encode an SETATTR request
2463 */
9f06c719
CL
2464static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2465 struct nfs_setattrargs *args)
1da177e4 2466{
05d564fe 2467 struct compound_hdr hdr = {
66cc0429 2468 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 2469 };
05d564fe 2470
9f06c719
CL
2471 encode_compound_hdr(xdr, req, &hdr);
2472 encode_sequence(xdr, &args->seq_args, &hdr);
2473 encode_putfh(xdr, args->fh, &hdr);
2474 encode_setattr(xdr, args, args->server, &hdr);
2475 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2476 encode_nops(&hdr);
1da177e4
LT
2477}
2478
029d105e
BF
2479/*
2480 * Encode a GETACL request
2481 */
9f06c719
CL
2482static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2483 struct nfs_getaclargs *args)
029d105e 2484{
029d105e 2485 struct compound_hdr hdr = {
66cc0429 2486 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
029d105e 2487 };
28f56694 2488 uint32_t replen;
029d105e 2489
9f06c719
CL
2490 encode_compound_hdr(xdr, req, &hdr);
2491 encode_sequence(xdr, &args->seq_args, &hdr);
2492 encode_putfh(xdr, args->fh, &hdr);
bf118a34 2493 replen = hdr.replen + op_decode_hdr_maxsz + 1;
9f06c719 2494 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
cf8cdbe5 2495
28f56694 2496 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
8fbcf237 2497 args->acl_pages, 0, args->acl_len);
bf118a34 2498
d017931c 2499 encode_nops(&hdr);
029d105e
BF
2500}
2501
1da177e4
LT
2502/*
2503 * Encode a WRITE request
2504 */
9f06c719 2505static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
3c6b899c 2506 struct nfs_pgio_args *args)
1da177e4 2507{
1da177e4 2508 struct compound_hdr hdr = {
66cc0429 2509 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2510 };
1da177e4 2511
9f06c719
CL
2512 encode_compound_hdr(xdr, req, &hdr);
2513 encode_sequence(xdr, &args->seq_args, &hdr);
2514 encode_putfh(xdr, args->fh, &hdr);
2515 encode_write(xdr, args, &hdr);
4f22ccc3 2516 req->rq_snd_buf.flags |= XDRBUF_WRITE;
7ffd1064
FI
2517 if (args->bitmask)
2518 encode_getfattr(xdr, args->bitmask, &hdr);
d017931c 2519 encode_nops(&hdr);
1da177e4
LT
2520}
2521
2522/*
2523 * a COMMIT request
2524 */
9f06c719 2525static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
0b7c0153 2526 struct nfs_commitargs *args)
1da177e4 2527{
1da177e4 2528 struct compound_hdr hdr = {
66cc0429 2529 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2530 };
1da177e4 2531
9f06c719
CL
2532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_sequence(xdr, &args->seq_args, &hdr);
2534 encode_putfh(xdr, args->fh, &hdr);
2535 encode_commit(xdr, args, &hdr);
d017931c 2536 encode_nops(&hdr);
1da177e4
LT
2537}
2538
2539/*
2540 * FSINFO request
2541 */
9f06c719
CL
2542static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2543 struct nfs4_fsinfo_arg *args)
1da177e4 2544{
1da177e4 2545 struct compound_hdr hdr = {
66cc0429 2546 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2547 };
1da177e4 2548
9f06c719
CL
2549 encode_compound_hdr(xdr, req, &hdr);
2550 encode_sequence(xdr, &args->seq_args, &hdr);
2551 encode_putfh(xdr, args->fh, &hdr);
2552 encode_fsinfo(xdr, args->bitmask, &hdr);
d017931c 2553 encode_nops(&hdr);
1da177e4
LT
2554}
2555
2556/*
2557 * a PATHCONF request
2558 */
9f06c719
CL
2559static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2560 const struct nfs4_pathconf_arg *args)
1da177e4 2561{
1da177e4 2562 struct compound_hdr hdr = {
66cc0429 2563 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2564 };
1da177e4 2565
9f06c719
CL
2566 encode_compound_hdr(xdr, req, &hdr);
2567 encode_sequence(xdr, &args->seq_args, &hdr);
2568 encode_putfh(xdr, args->fh, &hdr);
2569 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
cf8cdbe5 2570 &hdr);
d017931c 2571 encode_nops(&hdr);
1da177e4
LT
2572}
2573
2574/*
2575 * a STATFS request
2576 */
9f06c719
CL
2577static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2578 const struct nfs4_statfs_arg *args)
1da177e4 2579{
1da177e4 2580 struct compound_hdr hdr = {
66cc0429 2581 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2582 };
1da177e4 2583
9f06c719
CL
2584 encode_compound_hdr(xdr, req, &hdr);
2585 encode_sequence(xdr, &args->seq_args, &hdr);
2586 encode_putfh(xdr, args->fh, &hdr);
2587 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
cf8cdbe5 2588 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
d017931c 2589 encode_nops(&hdr);
1da177e4
LT
2590}
2591
2592/*
2593 * GETATTR_BITMAP request
2594 */
9f06c719
CL
2595static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2596 struct xdr_stream *xdr,
2597 struct nfs4_server_caps_arg *args)
1da177e4 2598{
8c61282f 2599 const u32 *bitmask = args->bitmask;
1da177e4 2600 struct compound_hdr hdr = {
66cc0429 2601 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2602 };
1da177e4 2603
9f06c719
CL
2604 encode_compound_hdr(xdr, req, &hdr);
2605 encode_sequence(xdr, &args->seq_args, &hdr);
2606 encode_putfh(xdr, args->fhandle, &hdr);
8c61282f 2607 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
d017931c 2608 encode_nops(&hdr);
1da177e4
LT
2609}
2610
2611/*
2612 * a RENEW request
2613 */
9f06c719
CL
2614static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2615 struct nfs_client *clp)
1da177e4 2616{
1da177e4 2617 struct compound_hdr hdr = {
d017931c 2618 .nops = 0,
1da177e4
LT
2619 };
2620
9f06c719 2621 encode_compound_hdr(xdr, req, &hdr);
bb4dae5e 2622 encode_renew(xdr, clp->cl_clientid, &hdr);
d017931c 2623 encode_nops(&hdr);
1da177e4
LT
2624}
2625
2626/*
2627 * a SETCLIENTID request
2628 */
9f06c719
CL
2629static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2630 struct xdr_stream *xdr,
2631 struct nfs4_setclientid *sc)
1da177e4 2632{
1da177e4 2633 struct compound_hdr hdr = {
d017931c 2634 .nops = 0,
1da177e4
LT
2635 };
2636
9f06c719
CL
2637 encode_compound_hdr(xdr, req, &hdr);
2638 encode_setclientid(xdr, sc, &hdr);
d017931c 2639 encode_nops(&hdr);
1da177e4
LT
2640}
2641
2642/*
2643 * a SETCLIENTID_CONFIRM request
2644 */
9f06c719
CL
2645static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2646 struct xdr_stream *xdr,
2647 struct nfs4_setclientid_res *arg)
1da177e4 2648{
1da177e4 2649 struct compound_hdr hdr = {
d017931c 2650 .nops = 0,
1da177e4 2651 };
1da177e4 2652
9f06c719
CL
2653 encode_compound_hdr(xdr, req, &hdr);
2654 encode_setclientid_confirm(xdr, arg, &hdr);
d017931c 2655 encode_nops(&hdr);
1da177e4
LT
2656}
2657
2658/*
2659 * DELEGRETURN request
2660 */
9f06c719
CL
2661static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2662 struct xdr_stream *xdr,
2663 const struct nfs4_delegreturnargs *args)
1da177e4 2664{
1da177e4 2665 struct compound_hdr hdr = {
66cc0429 2666 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2667 };
1da177e4 2668
9f06c719
CL
2669 encode_compound_hdr(xdr, req, &hdr);
2670 encode_sequence(xdr, &args->seq_args, &hdr);
2671 encode_putfh(xdr, args->fhandle, &hdr);
9f06c719 2672 encode_getfattr(xdr, args->bitmask, &hdr);
e144cbcc 2673 encode_delegreturn(xdr, args->stateid, &hdr);
d017931c 2674 encode_nops(&hdr);
1da177e4
LT
2675}
2676
683b57b4
TM
2677/*
2678 * Encode FS_LOCATIONS request
2679 */
9f06c719
CL
2680static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2681 struct xdr_stream *xdr,
2682 struct nfs4_fs_locations_arg *args)
683b57b4 2683{
683b57b4 2684 struct compound_hdr hdr = {
66cc0429 2685 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
683b57b4 2686 };
28f56694 2687 uint32_t replen;
683b57b4 2688
9f06c719
CL
2689 encode_compound_hdr(xdr, req, &hdr);
2690 encode_sequence(xdr, &args->seq_args, &hdr);
b03d735b
CL
2691 if (args->migration) {
2692 encode_putfh(xdr, args->fh, &hdr);
2693 replen = hdr.replen;
2694 encode_fs_locations(xdr, args->bitmask, &hdr);
2695 if (args->renew)
2696 encode_renew(xdr, args->clientid, &hdr);
2697 } else {
2698 encode_putfh(xdr, args->dir_fh, &hdr);
2699 encode_lookup(xdr, args->name, &hdr);
2700 replen = hdr.replen;
2701 encode_fs_locations(xdr, args->bitmask, &hdr);
2702 }
cf8cdbe5 2703
b03d735b 2704 /* Set up reply kvec to capture returned fs_locations array. */
28f56694 2705 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
683b57b4 2706 0, PAGE_SIZE);
d017931c 2707 encode_nops(&hdr);
683b57b4
TM
2708}
2709
5a5ea0d4
BS
2710/*
2711 * Encode SECINFO request
2712 */
2713static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2714 struct xdr_stream *xdr,
2715 struct nfs4_secinfo_arg *args)
2716{
2717 struct compound_hdr hdr = {
2718 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2719 };
2720
2721 encode_compound_hdr(xdr, req, &hdr);
2722 encode_sequence(xdr, &args->seq_args, &hdr);
2723 encode_putfh(xdr, args->dir_fh, &hdr);
2724 encode_secinfo(xdr, args->name, &hdr);
2725 encode_nops(&hdr);
2726}
2727
44c99933
CL
2728/*
2729 * Encode FSID_PRESENT request
2730 */
2731static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
2733 struct nfs4_fsid_present_arg *args)
2734{
2735 struct compound_hdr hdr = {
2736 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2737 };
2738
2739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_sequence(xdr, &args->seq_args, &hdr);
2741 encode_putfh(xdr, args->fh, &hdr);
2742 encode_getfh(xdr, &hdr);
2743 if (args->renew)
2744 encode_renew(xdr, args->clientid, &hdr);
2745 encode_nops(&hdr);
2746}
2747
99fe60d0 2748#if defined(CONFIG_NFS_V4_1)
7c44f1ae
WAA
2749/*
2750 * BIND_CONN_TO_SESSION request
2751 */
2752static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2753 struct xdr_stream *xdr,
71a097c6 2754 struct nfs41_bind_conn_to_session_args *args)
7c44f1ae
WAA
2755{
2756 struct compound_hdr hdr = {
71a097c6 2757 .minorversion = args->client->cl_mvops->minor_version,
7c44f1ae
WAA
2758 };
2759
2760 encode_compound_hdr(xdr, req, &hdr);
71a097c6 2761 encode_bind_conn_to_session(xdr, args, &hdr);
7c44f1ae
WAA
2762 encode_nops(&hdr);
2763}
2764
99fe60d0
BH
2765/*
2766 * EXCHANGE_ID request
2767 */
9f06c719
CL
2768static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2769 struct xdr_stream *xdr,
2770 struct nfs41_exchange_id_args *args)
99fe60d0 2771{
99fe60d0 2772 struct compound_hdr hdr = {
a4432345 2773 .minorversion = args->client->cl_mvops->minor_version,
99fe60d0
BH
2774 };
2775
9f06c719
CL
2776 encode_compound_hdr(xdr, req, &hdr);
2777 encode_exchange_id(xdr, args, &hdr);
99fe60d0 2778 encode_nops(&hdr);
99fe60d0 2779}
2050f0cc 2780
fc931582
AA
2781/*
2782 * a CREATE_SESSION request
2783 */
9f06c719
CL
2784static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2785 struct xdr_stream *xdr,
2786 struct nfs41_create_session_args *args)
fc931582 2787{
fc931582 2788 struct compound_hdr hdr = {
a4432345 2789 .minorversion = args->client->cl_mvops->minor_version,
fc931582
AA
2790 };
2791
9f06c719
CL
2792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_create_session(xdr, args, &hdr);
fc931582 2794 encode_nops(&hdr);
fc931582
AA
2795}
2796
0f3e66c6
AA
2797/*
2798 * a DESTROY_SESSION request
2799 */
9f06c719
CL
2800static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2801 struct xdr_stream *xdr,
2802 struct nfs4_session *session)
0f3e66c6 2803{
0f3e66c6 2804 struct compound_hdr hdr = {
a4432345 2805 .minorversion = session->clp->cl_mvops->minor_version,
0f3e66c6
AA
2806 };
2807
9f06c719
CL
2808 encode_compound_hdr(xdr, req, &hdr);
2809 encode_destroy_session(xdr, session, &hdr);
0f3e66c6 2810 encode_nops(&hdr);
0f3e66c6
AA
2811}
2812
66245539
TM
2813/*
2814 * a DESTROY_CLIENTID request
2815 */
2816static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2817 struct xdr_stream *xdr,
2818 struct nfs_client *clp)
2819{
2820 struct compound_hdr hdr = {
2821 .minorversion = clp->cl_mvops->minor_version,
2822 };
2823
2824 encode_compound_hdr(xdr, req, &hdr);
2825 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2826 encode_nops(&hdr);
2827}
2828
fc01cea9
AA
2829/*
2830 * a SEQUENCE request
2831 */
9f06c719
CL
2832static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2833 struct nfs4_sequence_args *args)
fc01cea9 2834{
fc01cea9
AA
2835 struct compound_hdr hdr = {
2836 .minorversion = nfs4_xdr_minorversion(args),
2837 };
2838
9f06c719
CL
2839 encode_compound_hdr(xdr, req, &hdr);
2840 encode_sequence(xdr, args, &hdr);
fc01cea9 2841 encode_nops(&hdr);
fc01cea9
AA
2842}
2843
2050f0cc
AA
2844/*
2845 * a GET_LEASE_TIME request
2846 */
9f06c719
CL
2847static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2848 struct xdr_stream *xdr,
2849 struct nfs4_get_lease_time_args *args)
2050f0cc 2850{
2050f0cc
AA
2851 struct compound_hdr hdr = {
2852 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2853 };
dae100c2 2854 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2050f0cc 2855
9f06c719
CL
2856 encode_compound_hdr(xdr, req, &hdr);
2857 encode_sequence(xdr, &args->la_seq_args, &hdr);
2858 encode_putrootfh(xdr, &hdr);
2859 encode_fsinfo(xdr, lease_bitmap, &hdr);
2050f0cc 2860 encode_nops(&hdr);
2050f0cc 2861}
18019753
RL
2862
2863/*
2864 * a RECLAIM_COMPLETE request
2865 */
9f06c719
CL
2866static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2867 struct xdr_stream *xdr,
2868 struct nfs41_reclaim_complete_args *args)
18019753 2869{
18019753
RL
2870 struct compound_hdr hdr = {
2871 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2872 };
2873
9f06c719
CL
2874 encode_compound_hdr(xdr, req, &hdr);
2875 encode_sequence(xdr, &args->seq_args, &hdr);
2876 encode_reclaim_complete(xdr, args, &hdr);
18019753 2877 encode_nops(&hdr);
18019753
RL
2878}
2879
b1f69b75
AA
2880/*
2881 * Encode GETDEVICEINFO request
2882 */
9f06c719
CL
2883static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2884 struct xdr_stream *xdr,
2885 struct nfs4_getdeviceinfo_args *args)
b1f69b75 2886{
b1f69b75
AA
2887 struct compound_hdr hdr = {
2888 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2889 };
2890
9f06c719
CL
2891 encode_compound_hdr(xdr, req, &hdr);
2892 encode_sequence(xdr, &args->seq_args, &hdr);
2893 encode_getdeviceinfo(xdr, args, &hdr);
b1f69b75
AA
2894
2895 /* set up reply kvec. Subtract notification bitmap max size (2)
2896 * so that notification bitmap is put in xdr_buf tail */
2897 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2898 args->pdev->pages, args->pdev->pgbase,
2899 args->pdev->pglen);
2900
2901 encode_nops(&hdr);
b1f69b75
AA
2902}
2903
2904/*
2905 * Encode LAYOUTGET request
2906 */
9f06c719
CL
2907static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2908 struct xdr_stream *xdr,
2909 struct nfs4_layoutget_args *args)
b1f69b75 2910{
b1f69b75
AA
2911 struct compound_hdr hdr = {
2912 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2913 };
2914
9f06c719
CL
2915 encode_compound_hdr(xdr, req, &hdr);
2916 encode_sequence(xdr, &args->seq_args, &hdr);
2917 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2918 encode_layoutget(xdr, args, &hdr);
35124a09
WAA
2919
2920 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2921 args->layout.pages, 0, args->layout.pglen);
2922
b1f69b75 2923 encode_nops(&hdr);
b1f69b75 2924}
863a3c6c
AA
2925
2926/*
2927 * Encode LAYOUTCOMMIT request
2928 */
cbe82603
BH
2929static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2930 struct xdr_stream *xdr,
2931 struct nfs4_layoutcommit_args *args)
863a3c6c 2932{
ac7db726
BH
2933 struct nfs4_layoutcommit_data *data =
2934 container_of(args, struct nfs4_layoutcommit_data, args);
863a3c6c
AA
2935 struct compound_hdr hdr = {
2936 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2937 };
2938
2939 encode_compound_hdr(xdr, req, &hdr);
2940 encode_sequence(xdr, &args->seq_args, &hdr);
2941 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
ac7db726 2942 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
863a3c6c 2943 encode_getfattr(xdr, args->bitmask, &hdr);
b1f69b75 2944 encode_nops(&hdr);
cbe82603
BH
2945}
2946
2947/*
2948 * Encode LAYOUTRETURN request
2949 */
2950static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2951 struct xdr_stream *xdr,
2952 struct nfs4_layoutreturn_args *args)
2953{
2954 struct compound_hdr hdr = {
2955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2956 };
2957
2958 encode_compound_hdr(xdr, req, &hdr);
2959 encode_sequence(xdr, &args->seq_args, &hdr);
2960 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2961 encode_layoutreturn(xdr, args, &hdr);
2962 encode_nops(&hdr);
b1f69b75 2963}
fca78d6d
BS
2964
2965/*
2966 * Encode SECINFO_NO_NAME request
2967 */
2968static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2969 struct xdr_stream *xdr,
2970 struct nfs41_secinfo_no_name_args *args)
2971{
2972 struct compound_hdr hdr = {
2973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2974 };
2975
2976 encode_compound_hdr(xdr, req, &hdr);
2977 encode_sequence(xdr, &args->seq_args, &hdr);
2978 encode_putrootfh(xdr, &hdr);
2979 encode_secinfo_no_name(xdr, args, &hdr);
2980 encode_nops(&hdr);
2981 return 0;
2982}
7d974794
BS
2983
2984/*
2985 * Encode TEST_STATEID request
2986 */
2987static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2988 struct xdr_stream *xdr,
2989 struct nfs41_test_stateid_args *args)
2990{
2991 struct compound_hdr hdr = {
2992 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2993 };
2994
2995 encode_compound_hdr(xdr, req, &hdr);
2996 encode_sequence(xdr, &args->seq_args, &hdr);
2997 encode_test_stateid(xdr, args, &hdr);
2998 encode_nops(&hdr);
2999}
9aeda35f
BS
3000
3001/*
3002 * Encode FREE_STATEID request
3003 */
3004static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3005 struct xdr_stream *xdr,
3006 struct nfs41_free_stateid_args *args)
3007{
3008 struct compound_hdr hdr = {
3009 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3010 };
3011
3012 encode_compound_hdr(xdr, req, &hdr);
3013 encode_sequence(xdr, &args->seq_args, &hdr);
3014 encode_free_stateid(xdr, args, &hdr);
3015 encode_nops(&hdr);
3016}
99fe60d0
BH
3017#endif /* CONFIG_NFS_V4_1 */
3018
686841b3
BH
3019static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3020{
3021 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3022 "Remaining buffer length is %tu words.\n",
3023 func, xdr->end - xdr->p);
3024}
1da177e4 3025
683b57b4 3026static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
1da177e4 3027{
8687b63a 3028 __be32 *p;
1da177e4 3029
c0eae66e
BH
3030 p = xdr_inline_decode(xdr, 4);
3031 if (unlikely(!p))
3032 goto out_overflow;
cccddf4f 3033 *len = be32_to_cpup(p);
c0eae66e
BH
3034 p = xdr_inline_decode(xdr, *len);
3035 if (unlikely(!p))
3036 goto out_overflow;
1da177e4
LT
3037 *string = (char *)p;
3038 return 0;
c0eae66e
BH
3039out_overflow:
3040 print_overflow_msg(__func__, xdr);
3041 return -EIO;
1da177e4
LT
3042}
3043
3044static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3045{
8687b63a 3046 __be32 *p;
1da177e4 3047
c0eae66e
BH
3048 p = xdr_inline_decode(xdr, 8);
3049 if (unlikely(!p))
3050 goto out_overflow;
6f723f77 3051 hdr->status = be32_to_cpup(p++);
cccddf4f 3052 hdr->taglen = be32_to_cpup(p);
6c0195a4 3053
c0eae66e
BH
3054 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3055 if (unlikely(!p))
3056 goto out_overflow;
1da177e4
LT
3057 hdr->tag = (char *)p;
3058 p += XDR_QUADLEN(hdr->taglen);
cccddf4f 3059 hdr->nops = be32_to_cpup(p);
aadf6152
BH
3060 if (unlikely(hdr->nops < 1))
3061 return nfs4_stat_to_errno(hdr->status);
1da177e4 3062 return 0;
c0eae66e
BH
3063out_overflow:
3064 print_overflow_msg(__func__, xdr);
3065 return -EIO;
1da177e4
LT
3066}
3067
c7848f69
TM
3068static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3069 int *nfs_retval)
1da177e4 3070{
8687b63a 3071 __be32 *p;
1da177e4
LT
3072 uint32_t opnum;
3073 int32_t nfserr;
3074
c0eae66e
BH
3075 p = xdr_inline_decode(xdr, 8);
3076 if (unlikely(!p))
3077 goto out_overflow;
6f723f77 3078 opnum = be32_to_cpup(p++);
c7848f69
TM
3079 if (unlikely(opnum != expected))
3080 goto out_bad_operation;
cccddf4f 3081 nfserr = be32_to_cpup(p);
c7848f69
TM
3082 if (nfserr == NFS_OK)
3083 *nfs_retval = 0;
3084 else
3085 *nfs_retval = nfs4_stat_to_errno(nfserr);
3086 return true;
3087out_bad_operation:
3088 dprintk("nfs: Server returned operation"
3089 " %d but we issued a request for %d\n",
3090 opnum, expected);
3091 *nfs_retval = -EREMOTEIO;
3092 return false;
c0eae66e
BH
3093out_overflow:
3094 print_overflow_msg(__func__, xdr);
c7848f69
TM
3095 *nfs_retval = -EIO;
3096 return false;
3097}
3098
3099static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3100{
3101 int retval;
3102
3103 __decode_op_hdr(xdr, expected, &retval);
3104 return retval;
1da177e4
LT
3105}
3106
3107/* Dummy routine */
adfa6f98 3108static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
1da177e4 3109{
8687b63a 3110 __be32 *p;
683b57b4 3111 unsigned int strlen;
1da177e4
LT
3112 char *str;
3113
c0eae66e
BH
3114 p = xdr_inline_decode(xdr, 12);
3115 if (likely(p))
3116 return decode_opaque_inline(xdr, &strlen, &str);
3117 print_overflow_msg(__func__, xdr);
3118 return -EIO;
1da177e4
LT
3119}
3120
3121static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3122{
8687b63a
AV
3123 uint32_t bmlen;
3124 __be32 *p;
1da177e4 3125
c0eae66e
BH
3126 p = xdr_inline_decode(xdr, 4);
3127 if (unlikely(!p))
3128 goto out_overflow;
cccddf4f 3129 bmlen = be32_to_cpup(p);
1da177e4 3130
dae100c2 3131 bitmap[0] = bitmap[1] = bitmap[2] = 0;
c0eae66e
BH
3132 p = xdr_inline_decode(xdr, (bmlen << 2));
3133 if (unlikely(!p))
3134 goto out_overflow;
1da177e4 3135 if (bmlen > 0) {
6f723f77 3136 bitmap[0] = be32_to_cpup(p++);
dae100c2
FI
3137 if (bmlen > 1) {
3138 bitmap[1] = be32_to_cpup(p++);
3139 if (bmlen > 2)
3140 bitmap[2] = be32_to_cpup(p);
3141 }
1da177e4
LT
3142 }
3143 return 0;
c0eae66e
BH
3144out_overflow:
3145 print_overflow_msg(__func__, xdr);
3146 return -EIO;
1da177e4
LT
3147}
3148
256e48bb 3149static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
1da177e4 3150{
8687b63a 3151 __be32 *p;
1da177e4 3152
c0eae66e
BH
3153 p = xdr_inline_decode(xdr, 4);
3154 if (unlikely(!p))
3155 goto out_overflow;
cccddf4f 3156 *attrlen = be32_to_cpup(p);
256e48bb 3157 *savep = xdr_stream_pos(xdr);
1da177e4 3158 return 0;
c0eae66e
BH
3159out_overflow:
3160 print_overflow_msg(__func__, xdr);
3161 return -EIO;
1da177e4
LT
3162}
3163
3164static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3165{
3166 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3388bff5
RB
3167 int ret;
3168 ret = decode_attr_bitmap(xdr, bitmask);
3169 if (unlikely(ret < 0))
3170 return ret;
1da177e4
LT
3171 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3172 } else
dae100c2
FI
3173 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3174 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3175 bitmask[0], bitmask[1], bitmask[2]);
1da177e4
LT
3176 return 0;
3177}
3178
3179static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3180{
8687b63a 3181 __be32 *p;
409924e4 3182 int ret = 0;
1da177e4
LT
3183
3184 *type = 0;
3185 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3186 return -EIO;
3187 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
c0eae66e
BH
3188 p = xdr_inline_decode(xdr, 4);
3189 if (unlikely(!p))
3190 goto out_overflow;
cccddf4f 3191 *type = be32_to_cpup(p);
1da177e4 3192 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3110ff80 3193 dprintk("%s: bad type %d\n", __func__, *type);
1da177e4
LT
3194 return -EIO;
3195 }
3196 bitmap[0] &= ~FATTR4_WORD0_TYPE;
409924e4 3197 ret = NFS_ATTR_FATTR_TYPE;
1da177e4 3198 }
bca79478 3199 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
409924e4 3200 return ret;
c0eae66e
BH
3201out_overflow:
3202 print_overflow_msg(__func__, xdr);
3203 return -EIO;
1da177e4
LT
3204}
3205
264e6351
CL
3206static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3207 uint32_t *bitmap, uint32_t *type)
3208{
3209 __be32 *p;
3210
3211 *type = 0;
3212 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3213 return -EIO;
3214 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3215 p = xdr_inline_decode(xdr, 4);
3216 if (unlikely(!p))
3217 goto out_overflow;
3218 *type = be32_to_cpup(p);
3219 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3220 }
3221 dprintk("%s: expire type=0x%x\n", __func__, *type);
3222 return 0;
3223out_overflow:
3224 print_overflow_msg(__func__, xdr);
3225 return -EIO;
3226}
3227
1da177e4
LT
3228static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3229{
8687b63a 3230 __be32 *p;
409924e4 3231 int ret = 0;
1da177e4
LT
3232
3233 *change = 0;
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3235 return -EIO;
3236 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
c0eae66e
BH
3237 p = xdr_inline_decode(xdr, 8);
3238 if (unlikely(!p))
3239 goto out_overflow;
cccddf4f 3240 xdr_decode_hyper(p, change);
1da177e4 3241 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
409924e4 3242 ret = NFS_ATTR_FATTR_CHANGE;
1da177e4 3243 }
3110ff80 3244 dprintk("%s: change attribute=%Lu\n", __func__,
1da177e4 3245 (unsigned long long)*change);
409924e4 3246 return ret;
c0eae66e
BH
3247out_overflow:
3248 print_overflow_msg(__func__, xdr);
3249 return -EIO;
1da177e4
LT
3250}
3251
3252static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3253{
8687b63a 3254 __be32 *p;
409924e4 3255 int ret = 0;
1da177e4
LT
3256
3257 *size = 0;
3258 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3259 return -EIO;
3260 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
c0eae66e
BH
3261 p = xdr_inline_decode(xdr, 8);
3262 if (unlikely(!p))
3263 goto out_overflow;
cccddf4f 3264 xdr_decode_hyper(p, size);
1da177e4 3265 bitmap[0] &= ~FATTR4_WORD0_SIZE;
409924e4 3266 ret = NFS_ATTR_FATTR_SIZE;
1da177e4 3267 }
3110ff80 3268 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
409924e4 3269 return ret;
c0eae66e
BH
3270out_overflow:
3271 print_overflow_msg(__func__, xdr);
3272 return -EIO;
1da177e4
LT
3273}
3274
3275static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3276{
8687b63a 3277 __be32 *p;
1da177e4
LT
3278
3279 *res = 0;
3280 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3281 return -EIO;
3282 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
c0eae66e
BH
3283 p = xdr_inline_decode(xdr, 4);
3284 if (unlikely(!p))
3285 goto out_overflow;
cccddf4f 3286 *res = be32_to_cpup(p);
1da177e4
LT
3287 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3288 }
3110ff80 3289 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
1da177e4 3290 return 0;
c0eae66e
BH
3291out_overflow:
3292 print_overflow_msg(__func__, xdr);
3293 return -EIO;
1da177e4
LT
3294}
3295
3296static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3297{
8687b63a 3298 __be32 *p;
1da177e4
LT
3299
3300 *res = 0;
3301 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3302 return -EIO;
3303 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
c0eae66e
BH
3304 p = xdr_inline_decode(xdr, 4);
3305 if (unlikely(!p))
3306 goto out_overflow;
cccddf4f 3307 *res = be32_to_cpup(p);
1da177e4
LT
3308 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3309 }
3110ff80 3310 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
1da177e4 3311 return 0;
c0eae66e
BH
3312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
1da177e4
LT
3315}
3316
8b4bdcf8 3317static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
1da177e4 3318{
8687b63a 3319 __be32 *p;
409924e4 3320 int ret = 0;
1da177e4
LT
3321
3322 fsid->major = 0;
3323 fsid->minor = 0;
3324 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3325 return -EIO;
3326 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
c0eae66e
BH
3327 p = xdr_inline_decode(xdr, 16);
3328 if (unlikely(!p))
3329 goto out_overflow;
3ceb4dbb 3330 p = xdr_decode_hyper(p, &fsid->major);
cccddf4f 3331 xdr_decode_hyper(p, &fsid->minor);
1da177e4 3332 bitmap[0] &= ~FATTR4_WORD0_FSID;
409924e4 3333 ret = NFS_ATTR_FATTR_FSID;
1da177e4 3334 }
3110ff80 3335 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
1da177e4
LT
3336 (unsigned long long)fsid->major,
3337 (unsigned long long)fsid->minor);
409924e4 3338 return ret;
c0eae66e
BH
3339out_overflow:
3340 print_overflow_msg(__func__, xdr);
3341 return -EIO;
1da177e4
LT
3342}
3343
3344static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3345{
8687b63a 3346 __be32 *p;
1da177e4
LT
3347
3348 *res = 60;
3349 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3350 return -EIO;
3351 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
c0eae66e
BH
3352 p = xdr_inline_decode(xdr, 4);
3353 if (unlikely(!p))
3354 goto out_overflow;
cccddf4f 3355 *res = be32_to_cpup(p);
1da177e4
LT
3356 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3357 }
3110ff80 3358 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
1da177e4 3359 return 0;
c0eae66e
BH
3360out_overflow:
3361 print_overflow_msg(__func__, xdr);
3362 return -EIO;
1da177e4
LT
3363}
3364
ee7b75fc 3365static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
ae42c70a
BS
3366{
3367 __be32 *p;
3368
3369 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3370 return -EIO;
3371 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3372 p = xdr_inline_decode(xdr, 4);
3373 if (unlikely(!p))
3374 goto out_overflow;
3375 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
ee7b75fc 3376 *res = -be32_to_cpup(p);
ae42c70a
BS
3377 }
3378 return 0;
3379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
3382}
3383
8c61282f
KM
3384static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3385 uint32_t *bitmap, uint32_t *bitmask)
3386{
3387 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3388 int ret;
3389 ret = decode_attr_bitmap(xdr, bitmask);
3390 if (unlikely(ret < 0))
3391 return ret;
3392 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3393 } else
3394 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3395 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3396 bitmask[0], bitmask[1], bitmask[2]);
3397 return 0;
3398}
3399
ae42c70a
BS
3400static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3401{
3402 __be32 *p;
3403 int len;
3404
7ad07353
TM
3405 if (fh != NULL)
3406 memset(fh, 0, sizeof(*fh));
ae42c70a
BS
3407
3408 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3409 return -EIO;
3410 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3411 p = xdr_inline_decode(xdr, 4);
3412 if (unlikely(!p))
3413 goto out_overflow;
3414 len = be32_to_cpup(p);
3415 if (len > NFS4_FHSIZE)
3416 return -EIO;
ae42c70a
BS
3417 p = xdr_inline_decode(xdr, len);
3418 if (unlikely(!p))
3419 goto out_overflow;
7ad07353
TM
3420 if (fh != NULL) {
3421 memcpy(fh->data, p, len);
3422 fh->size = len;
3423 }
ae42c70a
BS
3424 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3425 }
3426 return 0;
3427out_overflow:
3428 print_overflow_msg(__func__, xdr);
3429 return -EIO;
3430}
3431
1da177e4
LT
3432static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3433{
8687b63a 3434 __be32 *p;
1da177e4 3435
a1800aca 3436 *res = 0;
1da177e4
LT
3437 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3438 return -EIO;
3439 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
c0eae66e
BH
3440 p = xdr_inline_decode(xdr, 4);
3441 if (unlikely(!p))
3442 goto out_overflow;
cccddf4f 3443 *res = be32_to_cpup(p);
1da177e4
LT
3444 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3445 }
3110ff80 3446 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
1da177e4 3447 return 0;
c0eae66e
BH
3448out_overflow:
3449 print_overflow_msg(__func__, xdr);
3450 return -EIO;
1da177e4
LT
3451}
3452
3453static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3454{
8687b63a 3455 __be32 *p;
409924e4 3456 int ret = 0;
1da177e4
LT
3457
3458 *fileid = 0;
3459 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3460 return -EIO;
3461 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
c0eae66e
BH
3462 p = xdr_inline_decode(xdr, 8);
3463 if (unlikely(!p))
3464 goto out_overflow;
cccddf4f 3465 xdr_decode_hyper(p, fileid);
1da177e4 3466 bitmap[0] &= ~FATTR4_WORD0_FILEID;
409924e4 3467 ret = NFS_ATTR_FATTR_FILEID;
1da177e4 3468 }
3110ff80 3469 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
409924e4 3470 return ret;
c0eae66e
BH
3471out_overflow:
3472 print_overflow_msg(__func__, xdr);
3473 return -EIO;
1da177e4
LT
3474}
3475
99baf625
MN
3476static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3477{
8687b63a 3478 __be32 *p;
409924e4 3479 int ret = 0;
99baf625
MN
3480
3481 *fileid = 0;
3482 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3483 return -EIO;
3484 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
c0eae66e
BH
3485 p = xdr_inline_decode(xdr, 8);
3486 if (unlikely(!p))
3487 goto out_overflow;
cccddf4f 3488 xdr_decode_hyper(p, fileid);
99baf625 3489 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
28331a46 3490 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
99baf625 3491 }
3110ff80 3492 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
409924e4 3493 return ret;
c0eae66e
BH
3494out_overflow:
3495 print_overflow_msg(__func__, xdr);
3496 return -EIO;
99baf625
MN
3497}
3498
1da177e4
LT
3499static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3500{
8687b63a 3501 __be32 *p;
1da177e4
LT
3502 int status = 0;
3503
3504 *res = 0;
3505 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3506 return -EIO;
3507 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
c0eae66e
BH
3508 p = xdr_inline_decode(xdr, 8);
3509 if (unlikely(!p))
3510 goto out_overflow;
cccddf4f 3511 xdr_decode_hyper(p, res);
1da177e4
LT
3512 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3513 }
3110ff80 3514 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3515 return status;
c0eae66e
BH
3516out_overflow:
3517 print_overflow_msg(__func__, xdr);
3518 return -EIO;
1da177e4
LT
3519}
3520
3521static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3522{
8687b63a 3523 __be32 *p;
1da177e4
LT
3524 int status = 0;
3525
3526 *res = 0;
3527 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3528 return -EIO;
3529 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
c0eae66e
BH
3530 p = xdr_inline_decode(xdr, 8);
3531 if (unlikely(!p))
3532 goto out_overflow;
cccddf4f 3533 xdr_decode_hyper(p, res);
1da177e4
LT
3534 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3535 }
3110ff80 3536 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3537 return status;
c0eae66e
BH
3538out_overflow:
3539 print_overflow_msg(__func__, xdr);
3540 return -EIO;
1da177e4
LT
3541}
3542
3543static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3544{
8687b63a 3545 __be32 *p;
1da177e4
LT
3546 int status = 0;
3547
3548 *res = 0;
3549 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3550 return -EIO;
3551 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
c0eae66e
BH
3552 p = xdr_inline_decode(xdr, 8);
3553 if (unlikely(!p))
3554 goto out_overflow;
cccddf4f 3555 xdr_decode_hyper(p, res);
1da177e4
LT
3556 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3557 }
3110ff80 3558 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3559 return status;
c0eae66e
BH
3560out_overflow:
3561 print_overflow_msg(__func__, xdr);
3562 return -EIO;
1da177e4
LT
3563}
3564
7aaa0b3b
MN
3565static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3566{
464ad6b1 3567 u32 n;
8687b63a 3568 __be32 *p;
7aaa0b3b
MN
3569 int status = 0;
3570
c0eae66e
BH
3571 p = xdr_inline_decode(xdr, 4);
3572 if (unlikely(!p))
3573 goto out_overflow;
cccddf4f 3574 n = be32_to_cpup(p);
33a43f28
AA
3575 if (n == 0)
3576 goto root_path;
02a2976c 3577 dprintk("pathname4: ");
809b426c
TM
3578 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3579 dprintk("cannot parse %d components in path\n", n);
3580 goto out_eio;
3581 }
3582 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
7aaa0b3b
MN
3583 struct nfs4_string *component = &path->components[path->ncomponents];
3584 status = decode_opaque_inline(xdr, &component->len, &component->data);
3585 if (unlikely(status != 0))
3586 goto out_eio;
95a13f7b 3587 ifdebug (XDR)
02a2976c
CL
3588 pr_cont("%s%.*s ",
3589 (path->ncomponents != n ? "/ " : ""),
3590 component->len, component->data);
7aaa0b3b
MN
3591 }
3592out:
7aaa0b3b 3593 return status;
33a43f28
AA
3594root_path:
3595/* a root pathname is sent as a zero component4 */
3596 path->ncomponents = 1;
3597 path->components[0].len=0;
3598 path->components[0].data=NULL;
02a2976c 3599 dprintk("pathname4: /\n");
33a43f28 3600 goto out;
7aaa0b3b
MN
3601out_eio:
3602 dprintk(" status %d", status);
3603 status = -EIO;
3604 goto out;
c0eae66e
BH
3605out_overflow:
3606 print_overflow_msg(__func__, xdr);
3607 return -EIO;
7aaa0b3b
MN
3608}
3609
3610static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
683b57b4
TM
3611{
3612 int n;
8687b63a 3613 __be32 *p;
683b57b4
TM
3614 int status = -EIO;
3615
3616 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3617 goto out;
3618 status = 0;
3619 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3620 goto out;
f54423a1 3621 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
8b7e3f49
TM
3622 status = -EIO;
3623 /* Ignore borken servers that return unrequested attrs */
3624 if (unlikely(res == NULL))
3625 goto out;
02a2976c 3626 dprintk("%s: fsroot:\n", __func__);
7aaa0b3b 3627 status = decode_pathname(xdr, &res->fs_path);
683b57b4
TM
3628 if (unlikely(status != 0))
3629 goto out;
c0eae66e
BH
3630 p = xdr_inline_decode(xdr, 4);
3631 if (unlikely(!p))
3632 goto out_overflow;
cccddf4f 3633 n = be32_to_cpup(p);
683b57b4
TM
3634 if (n <= 0)
3635 goto out_eio;
809b426c 3636 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
464ad6b1 3637 u32 m;
809b426c 3638 struct nfs4_fs_location *loc;
683b57b4 3639
809b426c
TM
3640 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3641 break;
3642 loc = &res->locations[res->nlocations];
c0eae66e
BH
3643 p = xdr_inline_decode(xdr, 4);
3644 if (unlikely(!p))
3645 goto out_overflow;
cccddf4f 3646 m = be32_to_cpup(p);
7aaa0b3b 3647
02a2976c 3648 dprintk("%s: servers:\n", __func__);
809b426c
TM
3649 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3650 struct nfs4_string *server;
3651
3652 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
464ad6b1
CL
3653 unsigned int i;
3654 dprintk("%s: using first %u of %u servers "
3655 "returned for location %u\n",
3110ff80 3656 __func__,
464ad6b1
CL
3657 NFS4_FS_LOCATION_MAXSERVERS,
3658 m, res->nlocations);
7aaa0b3b 3659 for (i = loc->nservers; i < m; i++) {
2e42c3e2 3660 unsigned int len;
7aaa0b3b
MN
3661 char *data;
3662 status = decode_opaque_inline(xdr, &len, &data);
3663 if (unlikely(status != 0))
3664 goto out_eio;
3665 }
809b426c 3666 break;
7aaa0b3b 3667 }
809b426c
TM
3668 server = &loc->servers[loc->nservers];
3669 status = decode_opaque_inline(xdr, &server->len, &server->data);
3670 if (unlikely(status != 0))
3671 goto out_eio;
3672 dprintk("%s ", server->data);
7aaa0b3b
MN
3673 }
3674 status = decode_pathname(xdr, &loc->rootpath);
683b57b4
TM
3675 if (unlikely(status != 0))
3676 goto out_eio;
683b57b4 3677 }
409924e4 3678 if (res->nlocations != 0)
81934ddb 3679 status = NFS_ATTR_FATTR_V4_LOCATIONS;
683b57b4 3680out:
3110ff80 3681 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
683b57b4 3682 return status;
c0eae66e
BH
3683out_overflow:
3684 print_overflow_msg(__func__, xdr);
683b57b4
TM
3685out_eio:
3686 status = -EIO;
3687 goto out;
3688}
3689
1da177e4
LT
3690static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3691{
8687b63a 3692 __be32 *p;
1da177e4
LT
3693 int status = 0;
3694
3695 *res = 0;
3696 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3697 return -EIO;
3698 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
c0eae66e
BH
3699 p = xdr_inline_decode(xdr, 8);
3700 if (unlikely(!p))
3701 goto out_overflow;
cccddf4f 3702 xdr_decode_hyper(p, res);
1da177e4
LT
3703 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3704 }
3110ff80 3705 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3706 return status;
c0eae66e
BH
3707out_overflow:
3708 print_overflow_msg(__func__, xdr);
3709 return -EIO;
1da177e4
LT
3710}
3711
3712static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3713{
8687b63a 3714 __be32 *p;
1da177e4
LT
3715 int status = 0;
3716
3717 *maxlink = 1;
3718 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3719 return -EIO;
3720 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
c0eae66e
BH
3721 p = xdr_inline_decode(xdr, 4);
3722 if (unlikely(!p))
3723 goto out_overflow;
cccddf4f 3724 *maxlink = be32_to_cpup(p);
1da177e4
LT
3725 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3726 }
3110ff80 3727 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
1da177e4 3728 return status;
c0eae66e
BH
3729out_overflow:
3730 print_overflow_msg(__func__, xdr);
3731 return -EIO;
1da177e4
LT
3732}
3733
3734static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3735{
8687b63a 3736 __be32 *p;
1da177e4
LT
3737 int status = 0;
3738
3739 *maxname = 1024;
3740 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3741 return -EIO;
3742 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
c0eae66e
BH
3743 p = xdr_inline_decode(xdr, 4);
3744 if (unlikely(!p))
3745 goto out_overflow;
cccddf4f 3746 *maxname = be32_to_cpup(p);
1da177e4
LT
3747 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3748 }
3110ff80 3749 dprintk("%s: maxname=%u\n", __func__, *maxname);
1da177e4 3750 return status;
c0eae66e
BH
3751out_overflow:
3752 print_overflow_msg(__func__, xdr);
3753 return -EIO;
1da177e4
LT
3754}
3755
3756static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3757{
8687b63a 3758 __be32 *p;
1da177e4
LT
3759 int status = 0;
3760
3761 *res = 1024;
3762 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3763 return -EIO;
3764 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3765 uint64_t maxread;
c0eae66e
BH
3766 p = xdr_inline_decode(xdr, 8);
3767 if (unlikely(!p))
3768 goto out_overflow;
cccddf4f 3769 xdr_decode_hyper(p, &maxread);
1da177e4
LT
3770 if (maxread > 0x7FFFFFFF)
3771 maxread = 0x7FFFFFFF;
3772 *res = (uint32_t)maxread;
3773 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3774 }
3110ff80 3775 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
1da177e4 3776 return status;
c0eae66e
BH
3777out_overflow:
3778 print_overflow_msg(__func__, xdr);
3779 return -EIO;
1da177e4
LT
3780}
3781
3782static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3783{
8687b63a 3784 __be32 *p;
1da177e4
LT
3785 int status = 0;
3786
3787 *res = 1024;
3788 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3789 return -EIO;
3790 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3791 uint64_t maxwrite;
c0eae66e
BH
3792 p = xdr_inline_decode(xdr, 8);
3793 if (unlikely(!p))
3794 goto out_overflow;
cccddf4f 3795 xdr_decode_hyper(p, &maxwrite);
1da177e4
LT
3796 if (maxwrite > 0x7FFFFFFF)
3797 maxwrite = 0x7FFFFFFF;
3798 *res = (uint32_t)maxwrite;
3799 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3800 }
3110ff80 3801 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
1da177e4 3802 return status;
c0eae66e
BH
3803out_overflow:
3804 print_overflow_msg(__func__, xdr);
3805 return -EIO;
1da177e4
LT
3806}
3807
bca79478 3808static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
1da177e4 3809{
bca79478 3810 uint32_t tmp;
8687b63a 3811 __be32 *p;
409924e4 3812 int ret = 0;
1da177e4
LT
3813
3814 *mode = 0;
3815 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3816 return -EIO;
3817 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
c0eae66e
BH
3818 p = xdr_inline_decode(xdr, 4);
3819 if (unlikely(!p))
3820 goto out_overflow;
cccddf4f 3821 tmp = be32_to_cpup(p);
bca79478 3822 *mode = tmp & ~S_IFMT;
1da177e4 3823 bitmap[1] &= ~FATTR4_WORD1_MODE;
409924e4 3824 ret = NFS_ATTR_FATTR_MODE;
1da177e4 3825 }
3110ff80 3826 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
409924e4 3827 return ret;
c0eae66e
BH
3828out_overflow:
3829 print_overflow_msg(__func__, xdr);
3830 return -EIO;
1da177e4
LT
3831}
3832
3833static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3834{
8687b63a 3835 __be32 *p;
409924e4 3836 int ret = 0;
1da177e4
LT
3837
3838 *nlink = 1;
3839 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3840 return -EIO;
3841 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
c0eae66e
BH
3842 p = xdr_inline_decode(xdr, 4);
3843 if (unlikely(!p))
3844 goto out_overflow;
cccddf4f 3845 *nlink = be32_to_cpup(p);
1da177e4 3846 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
409924e4 3847 ret = NFS_ATTR_FATTR_NLINK;
1da177e4 3848 }
3110ff80 3849 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
409924e4 3850 return ret;
c0eae66e
BH
3851out_overflow:
3852 print_overflow_msg(__func__, xdr);
3853 return -EIO;
1da177e4
LT
3854}
3855
80e52ace 3856static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
e5782076 3857 const struct nfs_server *server, kuid_t *uid,
6926afd1 3858 struct nfs4_string *owner_name)
1da177e4 3859{
8687b63a
AV
3860 uint32_t len;
3861 __be32 *p;
409924e4 3862 int ret = 0;
1da177e4 3863
e5782076 3864 *uid = make_kuid(&init_user_ns, -2);
1da177e4
LT
3865 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3866 return -EIO;
3867 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
c0eae66e
BH
3868 p = xdr_inline_decode(xdr, 4);
3869 if (unlikely(!p))
3870 goto out_overflow;
cccddf4f 3871 len = be32_to_cpup(p);
c0eae66e
BH
3872 p = xdr_inline_decode(xdr, len);
3873 if (unlikely(!p))
3874 goto out_overflow;
6926afd1
TM
3875 if (owner_name != NULL) {
3876 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3877 if (owner_name->data != NULL) {
3878 owner_name->len = len;
3879 ret = NFS_ATTR_FATTR_OWNER_NAME;
3880 }
80e52ace 3881 } else if (len < XDR_MAX_NETOBJ) {
e4fd72a1 3882 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
409924e4
TM
3883 ret = NFS_ATTR_FATTR_OWNER;
3884 else
1da177e4 3885 dprintk("%s: nfs_map_name_to_uid failed!\n",
3110ff80 3886 __func__);
1da177e4 3887 } else
fe82a183 3888 dprintk("%s: name too long (%u)!\n",
3110ff80 3889 __func__, len);
1da177e4
LT
3890 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3891 }
e5782076 3892 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
409924e4 3893 return ret;
c0eae66e
BH
3894out_overflow:
3895 print_overflow_msg(__func__, xdr);
3896 return -EIO;
1da177e4
LT
3897}
3898
80e52ace 3899static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
e5782076 3900 const struct nfs_server *server, kgid_t *gid,
6926afd1 3901 struct nfs4_string *group_name)
1da177e4 3902{
8687b63a
AV
3903 uint32_t len;
3904 __be32 *p;
409924e4 3905 int ret = 0;
1da177e4 3906
e5782076 3907 *gid = make_kgid(&init_user_ns, -2);
1da177e4
LT
3908 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3909 return -EIO;
3910 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
c0eae66e
BH
3911 p = xdr_inline_decode(xdr, 4);
3912 if (unlikely(!p))
3913 goto out_overflow;
cccddf4f 3914 len = be32_to_cpup(p);
c0eae66e
BH
3915 p = xdr_inline_decode(xdr, len);
3916 if (unlikely(!p))
3917 goto out_overflow;
6926afd1
TM
3918 if (group_name != NULL) {
3919 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3920 if (group_name->data != NULL) {
3921 group_name->len = len;
3922 ret = NFS_ATTR_FATTR_GROUP_NAME;
3923 }
80e52ace 3924 } else if (len < XDR_MAX_NETOBJ) {
e4fd72a1 3925 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
409924e4
TM
3926 ret = NFS_ATTR_FATTR_GROUP;
3927 else
1da177e4 3928 dprintk("%s: nfs_map_group_to_gid failed!\n",
3110ff80 3929 __func__);
1da177e4 3930 } else
fe82a183 3931 dprintk("%s: name too long (%u)!\n",
3110ff80 3932 __func__, len);
1da177e4
LT
3933 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3934 }
e5782076 3935 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
409924e4 3936 return ret;
c0eae66e
BH
3937out_overflow:
3938 print_overflow_msg(__func__, xdr);
3939 return -EIO;
1da177e4
LT
3940}
3941
3942static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3943{
8687b63a
AV
3944 uint32_t major = 0, minor = 0;
3945 __be32 *p;
409924e4 3946 int ret = 0;
1da177e4
LT
3947
3948 *rdev = MKDEV(0,0);
3949 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3950 return -EIO;
3951 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3952 dev_t tmp;
3953
c0eae66e
BH
3954 p = xdr_inline_decode(xdr, 8);
3955 if (unlikely(!p))
3956 goto out_overflow;
6f723f77 3957 major = be32_to_cpup(p++);
cccddf4f 3958 minor = be32_to_cpup(p);
1da177e4
LT
3959 tmp = MKDEV(major, minor);
3960 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3961 *rdev = tmp;
3962 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
409924e4 3963 ret = NFS_ATTR_FATTR_RDEV;
1da177e4 3964 }
3110ff80 3965 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
409924e4 3966 return ret;
c0eae66e
BH
3967out_overflow:
3968 print_overflow_msg(__func__, xdr);
3969 return -EIO;
1da177e4
LT
3970}
3971
3972static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3973{
8687b63a 3974 __be32 *p;
1da177e4
LT
3975 int status = 0;
3976
3977 *res = 0;
3978 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3979 return -EIO;
3980 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
c0eae66e
BH
3981 p = xdr_inline_decode(xdr, 8);
3982 if (unlikely(!p))
3983 goto out_overflow;
cccddf4f 3984 xdr_decode_hyper(p, res);
1da177e4
LT
3985 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3986 }
3110ff80 3987 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3988 return status;
c0eae66e
BH
3989out_overflow:
3990 print_overflow_msg(__func__, xdr);
3991 return -EIO;
1da177e4
LT
3992}
3993
3994static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3995{
8687b63a 3996 __be32 *p;
1da177e4
LT
3997 int status = 0;
3998
3999 *res = 0;
4000 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4001 return -EIO;
4002 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
c0eae66e
BH
4003 p = xdr_inline_decode(xdr, 8);
4004 if (unlikely(!p))
4005 goto out_overflow;
cccddf4f 4006 xdr_decode_hyper(p, res);
1da177e4
LT
4007 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4008 }
3110ff80 4009 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 4010 return status;
c0eae66e
BH
4011out_overflow:
4012 print_overflow_msg(__func__, xdr);
4013 return -EIO;
1da177e4
LT
4014}
4015
4016static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4017{
8687b63a 4018 __be32 *p;
1da177e4
LT
4019 int status = 0;
4020
4021 *res = 0;
4022 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4023 return -EIO;
4024 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
c0eae66e
BH
4025 p = xdr_inline_decode(xdr, 8);
4026 if (unlikely(!p))
4027 goto out_overflow;
cccddf4f 4028 xdr_decode_hyper(p, res);
1da177e4
LT
4029 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4030 }
3110ff80 4031 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 4032 return status;
c0eae66e
BH
4033out_overflow:
4034 print_overflow_msg(__func__, xdr);
4035 return -EIO;
1da177e4
LT
4036}
4037
4038static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4039{
8687b63a 4040 __be32 *p;
409924e4 4041 int ret = 0;
1da177e4
LT
4042
4043 *used = 0;
4044 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4045 return -EIO;
4046 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
c0eae66e
BH
4047 p = xdr_inline_decode(xdr, 8);
4048 if (unlikely(!p))
4049 goto out_overflow;
cccddf4f 4050 xdr_decode_hyper(p, used);
1da177e4 4051 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
409924e4 4052 ret = NFS_ATTR_FATTR_SPACE_USED;
1da177e4 4053 }
3110ff80 4054 dprintk("%s: space used=%Lu\n", __func__,
1da177e4 4055 (unsigned long long)*used);
409924e4 4056 return ret;
c0eae66e
BH
4057out_overflow:
4058 print_overflow_msg(__func__, xdr);
4059 return -EIO;
1da177e4
LT
4060}
4061
4062static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4063{
8687b63a 4064 __be32 *p;
1da177e4
LT
4065 uint64_t sec;
4066 uint32_t nsec;
4067
c0eae66e
BH
4068 p = xdr_inline_decode(xdr, 12);
4069 if (unlikely(!p))
4070 goto out_overflow;
3ceb4dbb 4071 p = xdr_decode_hyper(p, &sec);
cccddf4f 4072 nsec = be32_to_cpup(p);
1da177e4
LT
4073 time->tv_sec = (time_t)sec;
4074 time->tv_nsec = (long)nsec;
4075 return 0;
c0eae66e
BH
4076out_overflow:
4077 print_overflow_msg(__func__, xdr);
4078 return -EIO;
1da177e4
LT
4079}
4080
4081static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4082{
4083 int status = 0;
4084
4085 time->tv_sec = 0;
4086 time->tv_nsec = 0;
4087 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4088 return -EIO;
4089 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4090 status = decode_attr_time(xdr, time);
409924e4
TM
4091 if (status == 0)
4092 status = NFS_ATTR_FATTR_ATIME;
1da177e4
LT
4093 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4094 }
3110ff80 4095 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
4096 return status;
4097}
4098
4099static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4100{
4101 int status = 0;
4102
4103 time->tv_sec = 0;
4104 time->tv_nsec = 0;
4105 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4106 return -EIO;
4107 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4108 status = decode_attr_time(xdr, time);
409924e4
TM
4109 if (status == 0)
4110 status = NFS_ATTR_FATTR_CTIME;
1da177e4
LT
4111 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4112 }
3110ff80 4113 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
4114 return status;
4115}
4116
55b6e774
RL
4117static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4118 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_DELTA - 1U)))
4125 return -EIO;
4126 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4127 status = decode_attr_time(xdr, time);
4128 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4129 }
4130 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4131 (long)time->tv_nsec);
4132 return status;
4133}
4134
aa9c2669
DQ
4135static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4136 struct nfs4_label *label)
4137{
4138 uint32_t pi = 0;
4139 uint32_t lfs = 0;
4140 __u32 len;
4141 __be32 *p;
4142 int status = 0;
4143
4144 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4145 return -EIO;
4146 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4147 p = xdr_inline_decode(xdr, 4);
4148 if (unlikely(!p))
4149 goto out_overflow;
4150 lfs = be32_to_cpup(p++);
4151 p = xdr_inline_decode(xdr, 4);
4152 if (unlikely(!p))
4153 goto out_overflow;
4154 pi = be32_to_cpup(p++);
4155 p = xdr_inline_decode(xdr, 4);
4156 if (unlikely(!p))
4157 goto out_overflow;
4158 len = be32_to_cpup(p++);
4159 p = xdr_inline_decode(xdr, len);
4160 if (unlikely(!p))
4161 goto out_overflow;
4162 if (len < NFS4_MAXLABELLEN) {
4163 if (label) {
4164 memcpy(label->label, p, len);
4165 label->len = len;
4166 label->pi = pi;
4167 label->lfs = lfs;
4168 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4169 }
4170 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4171 } else
4172 printk(KERN_WARNING "%s: label too long (%u)!\n",
4173 __func__, len);
4174 }
4175 if (label && label->label)
4176 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4177 (char *)label->label, label->len, label->pi, label->lfs);
4178 return status;
4179
4180out_overflow:
4181 print_overflow_msg(__func__, xdr);
4182 return -EIO;
4183}
4184
1da177e4
LT
4185static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4186{
4187 int status = 0;
4188
4189 time->tv_sec = 0;
4190 time->tv_nsec = 0;
4191 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4192 return -EIO;
4193 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4194 status = decode_attr_time(xdr, time);
409924e4
TM
4195 if (status == 0)
4196 status = NFS_ATTR_FATTR_MTIME;
1da177e4
LT
4197 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4198 }
3110ff80 4199 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
4200 return status;
4201}
4202
256e48bb 4203static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
1da177e4
LT
4204{
4205 unsigned int attrwords = XDR_QUADLEN(attrlen);
256e48bb 4206 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
1da177e4
LT
4207
4208 if (unlikely(attrwords != nwords)) {
fe82a183
CL
4209 dprintk("%s: server returned incorrect attribute length: "
4210 "%u %c %u\n",
3110ff80 4211 __func__,
1da177e4
LT
4212 attrwords << 2,
4213 (attrwords < nwords) ? '<' : '>',
4214 nwords << 2);
4215 return -EIO;
4216 }
4217 return 0;
4218}
4219
4220static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4221{
8687b63a 4222 __be32 *p;
1da177e4 4223
c0eae66e
BH
4224 p = xdr_inline_decode(xdr, 20);
4225 if (unlikely(!p))
4226 goto out_overflow;
6f723f77 4227 cinfo->atomic = be32_to_cpup(p++);
3ceb4dbb 4228 p = xdr_decode_hyper(p, &cinfo->before);
cccddf4f 4229 xdr_decode_hyper(p, &cinfo->after);
1da177e4 4230 return 0;
c0eae66e
BH
4231out_overflow:
4232 print_overflow_msg(__func__, xdr);
4233 return -EIO;
1da177e4
LT
4234}
4235
6168f62c 4236static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
1da177e4 4237{
8687b63a 4238 __be32 *p;
1da177e4
LT
4239 uint32_t supp, acc;
4240 int status;
4241
4242 status = decode_op_hdr(xdr, OP_ACCESS);
4243 if (status)
4244 return status;
c0eae66e
BH
4245 p = xdr_inline_decode(xdr, 8);
4246 if (unlikely(!p))
4247 goto out_overflow;
6f723f77 4248 supp = be32_to_cpup(p++);
cccddf4f 4249 acc = be32_to_cpup(p);
6168f62c
WAA
4250 *supported = supp;
4251 *access = acc;
1da177e4 4252 return 0;
c0eae66e
BH
4253out_overflow:
4254 print_overflow_msg(__func__, xdr);
4255 return -EIO;
1da177e4
LT
4256}
4257
07d30434 4258static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
1da177e4 4259{
8687b63a 4260 __be32 *p;
07d30434
BH
4261
4262 p = xdr_inline_decode(xdr, len);
4263 if (likely(p)) {
4264 memcpy(buf, p, len);
4265 return 0;
4266 }
4267 print_overflow_msg(__func__, xdr);
4268 return -EIO;
4269}
4270
4271static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4272{
2d2f24ad 4273 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
07d30434
BH
4274}
4275
93b717fd
TM
4276static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4277{
4278 stateid->type = NFS4_OPEN_STATEID_TYPE;
4279 return decode_stateid(xdr, stateid);
4280}
4281
4282static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4283{
4284 stateid->type = NFS4_LOCK_STATEID_TYPE;
4285 return decode_stateid(xdr, stateid);
4286}
4287
4288static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4289{
4290 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4291 return decode_stateid(xdr, stateid);
4292}
4293
07d30434
BH
4294static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4295{
1da177e4
LT
4296 int status;
4297
4298 status = decode_op_hdr(xdr, OP_CLOSE);
c1d51931
TM
4299 if (status != -EIO)
4300 nfs_increment_open_seqid(status, res->seqid);
07d30434 4301 if (!status)
93b717fd 4302 status = decode_open_stateid(xdr, &res->stateid);
07d30434 4303 return status;
1da177e4
LT
4304}
4305
db942bbd
BH
4306static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4307{
cd93710e 4308 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
1da177e4
LT
4309}
4310
2f2c63bc
TM
4311static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4312{
4313 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4314}
4315
0b7c0153 4316static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
1da177e4 4317{
1da177e4
LT
4318 int status;
4319
4320 status = decode_op_hdr(xdr, OP_COMMIT);
db942bbd 4321 if (!status)
2f2c63bc 4322 status = decode_write_verifier(xdr, &res->verf->verifier);
db942bbd 4323 return status;
1da177e4
LT
4324}
4325
4326static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4327{
8687b63a 4328 __be32 *p;
1da177e4
LT
4329 uint32_t bmlen;
4330 int status;
4331
4332 status = decode_op_hdr(xdr, OP_CREATE);
4333 if (status)
4334 return status;
4335 if ((status = decode_change_info(xdr, cinfo)))
4336 return status;
c0eae66e
BH
4337 p = xdr_inline_decode(xdr, 4);
4338 if (unlikely(!p))
4339 goto out_overflow;
cccddf4f 4340 bmlen = be32_to_cpup(p);
c0eae66e
BH
4341 p = xdr_inline_decode(xdr, bmlen << 2);
4342 if (likely(p))
4343 return 0;
4344out_overflow:
4345 print_overflow_msg(__func__, xdr);
4346 return -EIO;
1da177e4
LT
4347}
4348
4349static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4350{
256e48bb 4351 unsigned int savep;
dae100c2 4352 uint32_t attrlen, bitmap[3] = {0};
1da177e4
LT
4353 int status;
4354
4355 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4356 goto xdr_error;
4357 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4358 goto xdr_error;
4359 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4360 goto xdr_error;
4361 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4362 goto xdr_error;
264e6351
CL
4363 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4364 &res->fh_expire_type)) != 0)
4365 goto xdr_error;
1da177e4
LT
4366 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4367 goto xdr_error;
4368 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4369 goto xdr_error;
4370 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4371 goto xdr_error;
8c61282f
KM
4372 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4373 res->exclcreat_bitmask)) != 0)
4374 goto xdr_error;
1da177e4
LT
4375 status = verify_attr_len(xdr, savep, attrlen);
4376xdr_error:
3110ff80 4377 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
4378 return status;
4379}
6c0195a4 4380
1da177e4
LT
4381static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4382{
256e48bb 4383 unsigned int savep;
dae100c2 4384 uint32_t attrlen, bitmap[3] = {0};
1da177e4 4385 int status;
6c0195a4 4386
1da177e4
LT
4387 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4388 goto xdr_error;
4389 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4390 goto xdr_error;
4391 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4392 goto xdr_error;
4393
4394 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4395 goto xdr_error;
4396 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4397 goto xdr_error;
4398 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4399 goto xdr_error;
1ca843a2
AG
4400
4401 status = -EIO;
4402 if (unlikely(bitmap[0]))
4403 goto xdr_error;
4404
1da177e4
LT
4405 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4406 goto xdr_error;
4407 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4408 goto xdr_error;
4409 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4410 goto xdr_error;
4411
4412 status = verify_attr_len(xdr, savep, attrlen);
4413xdr_error:
3110ff80 4414 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
4415 return status;
4416}
4417
4418static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4419{
256e48bb 4420 unsigned int savep;
dae100c2 4421 uint32_t attrlen, bitmap[3] = {0};
1da177e4 4422 int status;
6c0195a4 4423
1da177e4
LT
4424 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4425 goto xdr_error;
4426 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4427 goto xdr_error;
4428 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4429 goto xdr_error;
4430
4431 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4432 goto xdr_error;
4433 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4434 goto xdr_error;
4435
4436 status = verify_attr_len(xdr, savep, attrlen);
4437xdr_error:
3110ff80 4438 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
4439 return status;
4440}
4441
88034c3d
AA
4442static int decode_threshold_hint(struct xdr_stream *xdr,
4443 uint32_t *bitmap,
4444 uint64_t *res,
4445 uint32_t hint_bit)
4446{
4447 __be32 *p;
4448
4449 *res = 0;
4450 if (likely(bitmap[0] & hint_bit)) {
4451 p = xdr_inline_decode(xdr, 8);
4452 if (unlikely(!p))
4453 goto out_overflow;
4454 xdr_decode_hyper(p, res);
4455 }
4456 return 0;
4457out_overflow:
4458 print_overflow_msg(__func__, xdr);
4459 return -EIO;
4460}
4461
4462static int decode_first_threshold_item4(struct xdr_stream *xdr,
4463 struct nfs4_threshold *res)
4464{
256e48bb
TM
4465 __be32 *p;
4466 unsigned int savep;
88034c3d
AA
4467 uint32_t bitmap[3] = {0,}, attrlen;
4468 int status;
4469
4470 /* layout type */
4471 p = xdr_inline_decode(xdr, 4);
4472 if (unlikely(!p)) {
4473 print_overflow_msg(__func__, xdr);
4474 return -EIO;
4475 }
4476 res->l_type = be32_to_cpup(p);
4477
4478 /* thi_hintset bitmap */
4479 status = decode_attr_bitmap(xdr, bitmap);
4480 if (status < 0)
4481 goto xdr_error;
4482
4483 /* thi_hintlist length */
4484 status = decode_attr_length(xdr, &attrlen, &savep);
4485 if (status < 0)
4486 goto xdr_error;
4487 /* thi_hintlist */
4488 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4489 if (status < 0)
4490 goto xdr_error;
4491 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4492 if (status < 0)
4493 goto xdr_error;
4494 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4495 THRESHOLD_RD_IO);
4496 if (status < 0)
4497 goto xdr_error;
4498 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4499 THRESHOLD_WR_IO);
4500 if (status < 0)
4501 goto xdr_error;
4502
4503 status = verify_attr_len(xdr, savep, attrlen);
4504 res->bm = bitmap[0];
4505
4506 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4507 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4508 res->wr_io_sz);
4509xdr_error:
4510 dprintk("%s ret=%d!\n", __func__, status);
4511 return status;
4512}
4513
4514/*
4515 * Thresholds on pNFS direct I/O vrs MDS I/O
4516 */
4517static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4518 uint32_t *bitmap,
4519 struct nfs4_threshold *res)
4520{
4521 __be32 *p;
4522 int status = 0;
4523 uint32_t num;
4524
4525 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4526 return -EIO;
029c5347 4527 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
1549210f
TM
4528 /* Did the server return an unrequested attribute? */
4529 if (unlikely(res == NULL))
4530 return -EREMOTEIO;
88034c3d
AA
4531 p = xdr_inline_decode(xdr, 4);
4532 if (unlikely(!p))
4533 goto out_overflow;
4534 num = be32_to_cpup(p);
4535 if (num == 0)
4536 return 0;
4537 if (num > 1)
4538 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4539 "drivers per filesystem not supported\n",
4540 __func__);
4541
4542 status = decode_first_threshold_item4(xdr, res);
029c5347 4543 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
88034c3d
AA
4544 }
4545 return status;
4546out_overflow:
4547 print_overflow_msg(__func__, xdr);
4548 return -EIO;
4549}
4550
ae42c70a
BS
4551static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4552 struct nfs_fattr *fattr, struct nfs_fh *fh,
aa9c2669 4553 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
6926afd1 4554 const struct nfs_server *server)
1da177e4 4555{
bca79478
TM
4556 int status;
4557 umode_t fmode = 0;
ae42c70a 4558 uint32_t type;
ee7b75fc 4559 int32_t err;
1da177e4 4560
f26c7a78
TM
4561 status = decode_attr_type(xdr, bitmap, &type);
4562 if (status < 0)
1da177e4 4563 goto xdr_error;
409924e4
TM
4564 fattr->mode = 0;
4565 if (status != 0) {
4566 fattr->mode |= nfs_type2fmt[type];
4567 fattr->valid |= status;
4568 }
1da177e4 4569
f26c7a78
TM
4570 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4571 if (status < 0)
1da177e4 4572 goto xdr_error;
409924e4 4573 fattr->valid |= status;
f26c7a78
TM
4574
4575 status = decode_attr_size(xdr, bitmap, &fattr->size);
4576 if (status < 0)
1da177e4 4577 goto xdr_error;
409924e4 4578 fattr->valid |= status;
f26c7a78
TM
4579
4580 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4581 if (status < 0)
1da177e4 4582 goto xdr_error;
409924e4 4583 fattr->valid |= status;
f26c7a78 4584
ee7b75fc
TM
4585 err = 0;
4586 status = decode_attr_error(xdr, bitmap, &err);
ae42c70a
BS
4587 if (status < 0)
4588 goto xdr_error;
4589
4590 status = decode_attr_filehandle(xdr, bitmap, fh);
4591 if (status < 0)
4592 goto xdr_error;
4593
f26c7a78
TM
4594 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4595 if (status < 0)
1da177e4 4596 goto xdr_error;
409924e4 4597 fattr->valid |= status;
f26c7a78 4598
8b7e3f49 4599 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
f26c7a78 4600 if (status < 0)
683b57b4 4601 goto xdr_error;
409924e4 4602 fattr->valid |= status;
f26c7a78 4603
1ca843a2
AG
4604 status = -EIO;
4605 if (unlikely(bitmap[0]))
4606 goto xdr_error;
4607
f26c7a78
TM
4608 status = decode_attr_mode(xdr, bitmap, &fmode);
4609 if (status < 0)
1da177e4 4610 goto xdr_error;
409924e4
TM
4611 if (status != 0) {
4612 fattr->mode |= fmode;
4613 fattr->valid |= status;
4614 }
f26c7a78
TM
4615
4616 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4617 if (status < 0)
1da177e4 4618 goto xdr_error;
409924e4 4619 fattr->valid |= status;
f26c7a78 4620
6926afd1 4621 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
f26c7a78 4622 if (status < 0)
1da177e4 4623 goto xdr_error;
409924e4 4624 fattr->valid |= status;
f26c7a78 4625
6926afd1 4626 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
f26c7a78 4627 if (status < 0)
1da177e4 4628 goto xdr_error;
409924e4 4629 fattr->valid |= status;
f26c7a78
TM
4630
4631 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4632 if (status < 0)
1da177e4 4633 goto xdr_error;
409924e4 4634 fattr->valid |= status;
f26c7a78
TM
4635
4636 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4637 if (status < 0)
1da177e4 4638 goto xdr_error;
409924e4 4639 fattr->valid |= status;
f26c7a78
TM
4640
4641 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4642 if (status < 0)
1da177e4 4643 goto xdr_error;
409924e4 4644 fattr->valid |= status;
f26c7a78
TM
4645
4646 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4647 if (status < 0)
1da177e4 4648 goto xdr_error;
409924e4 4649 fattr->valid |= status;
f26c7a78
TM
4650
4651 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4652 if (status < 0)
1da177e4 4653 goto xdr_error;
409924e4 4654 fattr->valid |= status;
f26c7a78 4655
28331a46 4656 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
f26c7a78 4657 if (status < 0)
99baf625 4658 goto xdr_error;
28331a46 4659 fattr->valid |= status;
f26c7a78 4660
1ca843a2
AG
4661 status = -EIO;
4662 if (unlikely(bitmap[1]))
4663 goto xdr_error;
4664
88034c3d
AA
4665 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4666 if (status < 0)
4667 goto xdr_error;
4668
aa9c2669
DQ
4669 if (label) {
4670 status = decode_attr_security_label(xdr, bitmap, label);
4671 if (status < 0)
4672 goto xdr_error;
4673 fattr->valid |= status;
4674 }
4675
ae42c70a
BS
4676xdr_error:
4677 dprintk("%s: xdr returned %d\n", __func__, -status);
4678 return status;
4679}
4680
4681static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
8b7e3f49 4682 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
aa9c2669 4683 struct nfs4_label *label, const struct nfs_server *server)
ae42c70a 4684{
256e48bb 4685 unsigned int savep;
ae42c70a 4686 uint32_t attrlen,
dae100c2 4687 bitmap[3] = {0};
ae42c70a
BS
4688 int status;
4689
4690 status = decode_op_hdr(xdr, OP_GETATTR);
4691 if (status < 0)
4692 goto xdr_error;
4693
4694 status = decode_attr_bitmap(xdr, bitmap);
4695 if (status < 0)
4696 goto xdr_error;
4697
4698 status = decode_attr_length(xdr, &attrlen, &savep);
4699 if (status < 0)
4700 goto xdr_error;
4701
aa9c2669
DQ
4702 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4703 label, server);
ae42c70a
BS
4704 if (status < 0)
4705 goto xdr_error;
4706
f26c7a78 4707 status = verify_attr_len(xdr, savep, attrlen);
1da177e4 4708xdr_error:
3110ff80 4709 dprintk("%s: xdr returned %d\n", __func__, -status);
1da177e4
LT
4710 return status;
4711}
4712
aa9c2669
DQ
4713static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4714 struct nfs4_label *label, const struct nfs_server *server)
4715{
4716 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4717}
4718
ae42c70a 4719static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
6926afd1 4720 const struct nfs_server *server)
ae42c70a 4721{
aa9c2669 4722 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
ae42c70a 4723}
1da177e4 4724
504913fb 4725/*
3132e49e 4726 * Decode potentially multiple layout types.
504913fb 4727 */
3132e49e 4728static int decode_pnfs_layout_types(struct xdr_stream *xdr,
ca440c38 4729 struct nfs_fsinfo *fsinfo)
504913fb 4730{
b8a8a0dd 4731 __be32 *p;
ca440c38 4732 uint32_t i;
504913fb
AA
4733
4734 p = xdr_inline_decode(xdr, 4);
4735 if (unlikely(!p))
4736 goto out_overflow;
ca440c38 4737 fsinfo->nlayouttypes = be32_to_cpup(p);
504913fb
AA
4738
4739 /* pNFS is not supported by the underlying file system */
ca440c38 4740 if (fsinfo->nlayouttypes == 0)
504913fb 4741 return 0;
504913fb
AA
4742
4743 /* Decode and set first layout type, move xdr->p past unused types */
ca440c38 4744 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
504913fb
AA
4745 if (unlikely(!p))
4746 goto out_overflow;
ca440c38
JL
4747
4748 /* If we get too many, then just cap it at the max */
4749 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4750 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4751 __func__, fsinfo->nlayouttypes);
4752 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4753 }
4754
4755 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4756 fsinfo->layouttype[i] = be32_to_cpup(p++);
504913fb
AA
4757 return 0;
4758out_overflow:
4759 print_overflow_msg(__func__, xdr);
4760 return -EIO;
4761}
4762
4763/*
4764 * The type of file system exported.
4765 * Note we must ensure that layouttype is set in any non-error case.
4766 */
4767static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
ca440c38 4768 struct nfs_fsinfo *fsinfo)
504913fb
AA
4769{
4770 int status = 0;
4771
4772 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4773 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4774 return -EIO;
4775 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
ca440c38 4776 status = decode_pnfs_layout_types(xdr, fsinfo);
504913fb 4777 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
3132e49e 4778 }
504913fb
AA
4779 return status;
4780}
4781
dae100c2
FI
4782/*
4783 * The prefered block size for layout directed io
4784 */
4785static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4786 uint32_t *res)
4787{
4788 __be32 *p;
4789
4790 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4791 *res = 0;
4792 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4793 p = xdr_inline_decode(xdr, 4);
4794 if (unlikely(!p)) {
4795 print_overflow_msg(__func__, xdr);
4796 return -EIO;
4797 }
4798 *res = be32_to_cpup(p);
4799 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4800 }
4801 return 0;
4802}
4803
2a92ee92
PT
4804/*
4805 * The granularity of a CLONE operation.
4806 */
4807static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4808 uint32_t *res)
4809{
4810 __be32 *p;
4811
4812 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4813 *res = 0;
4814 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4815 p = xdr_inline_decode(xdr, 4);
4816 if (unlikely(!p)) {
4817 print_overflow_msg(__func__, xdr);
4818 return -EIO;
4819 }
4820 *res = be32_to_cpup(p);
4821 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4822 }
4823 return 0;
4824}
4825
1da177e4
LT
4826static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4827{
256e48bb 4828 unsigned int savep;
dae100c2 4829 uint32_t attrlen, bitmap[3];
1da177e4
LT
4830 int status;
4831
4832 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4833 goto xdr_error;
4834 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4835 goto xdr_error;
4836 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4837 goto xdr_error;
4838
4839 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4840
4841 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4842 goto xdr_error;
4843 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4844 goto xdr_error;
4845 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4846 goto xdr_error;
4847 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4848 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4849 goto xdr_error;
4850 fsinfo->wtpref = fsinfo->wtmax;
1ca843a2
AG
4851
4852 status = -EIO;
4853 if (unlikely(bitmap[0]))
4854 goto xdr_error;
4855
55b6e774 4856 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
504913fb
AA
4857 if (status != 0)
4858 goto xdr_error;
ca440c38 4859 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
55b6e774
RL
4860 if (status != 0)
4861 goto xdr_error;
1ca843a2
AG
4862
4863 status = -EIO;
4864 if (unlikely(bitmap[1]))
4865 goto xdr_error;
4866
dae100c2 4867 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
2a92ee92
PT
4868 if (status)
4869 goto xdr_error;
4870 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
dae100c2
FI
4871 if (status)
4872 goto xdr_error;
1da177e4
LT
4873
4874 status = verify_attr_len(xdr, savep, attrlen);
4875xdr_error:
3110ff80 4876 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
4877 return status;
4878}
4879
4880static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4881{
8687b63a 4882 __be32 *p;
1da177e4
LT
4883 uint32_t len;
4884 int status;
4885
9936781d
TM
4886 /* Zero handle first to allow comparisons */
4887 memset(fh, 0, sizeof(*fh));
4888
1da177e4
LT
4889 status = decode_op_hdr(xdr, OP_GETFH);
4890 if (status)
4891 return status;
1da177e4 4892
c0eae66e
BH
4893 p = xdr_inline_decode(xdr, 4);
4894 if (unlikely(!p))
4895 goto out_overflow;
cccddf4f 4896 len = be32_to_cpup(p);
1da177e4
LT
4897 if (len > NFS4_FHSIZE)
4898 return -EIO;
4899 fh->size = len;
c0eae66e
BH
4900 p = xdr_inline_decode(xdr, len);
4901 if (unlikely(!p))
4902 goto out_overflow;
99398d06 4903 memcpy(fh->data, p, len);
1da177e4 4904 return 0;
c0eae66e
BH
4905out_overflow:
4906 print_overflow_msg(__func__, xdr);
4907 return -EIO;
1da177e4
LT
4908}
4909
4910static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4911{
4912 int status;
6c0195a4 4913
1da177e4
LT
4914 status = decode_op_hdr(xdr, OP_LINK);
4915 if (status)
4916 return status;
4917 return decode_change_info(xdr, cinfo);
4918}
4919
4920/*
4921 * We create the owner, so we know a proper owner.id length is 4.
4922 */
911d1aaf 4923static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
1da177e4 4924{
911d1aaf 4925 uint64_t offset, length, clientid;
8687b63a 4926 __be32 *p;
911d1aaf 4927 uint32_t namelen, type;
1da177e4 4928
babddc72 4929 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
c0eae66e
BH
4930 if (unlikely(!p))
4931 goto out_overflow;
babddc72 4932 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
3ceb4dbb 4933 p = xdr_decode_hyper(p, &length);
babddc72
BS
4934 type = be32_to_cpup(p++); /* 4 byte read */
4935 if (fl != NULL) { /* manipulate file lock */
911d1aaf
TM
4936 fl->fl_start = (loff_t)offset;
4937 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4938 if (length == ~(uint64_t)0)
4939 fl->fl_end = OFFSET_MAX;
4940 fl->fl_type = F_WRLCK;
4941 if (type & 1)
4942 fl->fl_type = F_RDLCK;
4943 fl->fl_pid = 0;
4944 }
babddc72
BS
4945 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4946 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4947 p = xdr_inline_decode(xdr, namelen); /* variable size field */
c0eae66e
BH
4948 if (likely(p))
4949 return -NFS4ERR_DENIED;
4950out_overflow:
4951 print_overflow_msg(__func__, xdr);
4952 return -EIO;
1da177e4
LT
4953}
4954
911d1aaf 4955static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
1da177e4 4956{
1da177e4
LT
4957 int status;
4958
4959 status = decode_op_hdr(xdr, OP_LOCK);
c1d51931
TM
4960 if (status == -EIO)
4961 goto out;
1da177e4 4962 if (status == 0) {
93b717fd 4963 status = decode_lock_stateid(xdr, &res->stateid);
07d30434
BH
4964 if (unlikely(status))
4965 goto out;
1da177e4 4966 } else if (status == -NFS4ERR_DENIED)
c1d51931
TM
4967 status = decode_lock_denied(xdr, NULL);
4968 if (res->open_seqid != NULL)
4969 nfs_increment_open_seqid(status, res->open_seqid);
4970 nfs_increment_lock_seqid(status, res->lock_seqid);
4971out:
1da177e4
LT
4972 return status;
4973}
4974
911d1aaf 4975static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
1da177e4
LT
4976{
4977 int status;
4978 status = decode_op_hdr(xdr, OP_LOCKT);
4979 if (status == -NFS4ERR_DENIED)
911d1aaf 4980 return decode_lock_denied(xdr, res->denied);
1da177e4
LT
4981 return status;
4982}
4983
911d1aaf 4984static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
1da177e4 4985{
1da177e4
LT
4986 int status;
4987
4988 status = decode_op_hdr(xdr, OP_LOCKU);
c1d51931
TM
4989 if (status != -EIO)
4990 nfs_increment_lock_seqid(status, res->seqid);
07d30434 4991 if (status == 0)
93b717fd 4992 status = decode_lock_stateid(xdr, &res->stateid);
1da177e4
LT
4993 return status;
4994}
4995
d3c7b7cc
TM
4996static int decode_release_lockowner(struct xdr_stream *xdr)
4997{
4998 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4999}
5000
1da177e4
LT
5001static int decode_lookup(struct xdr_stream *xdr)
5002{
5003 return decode_op_hdr(xdr, OP_LOOKUP);
5004}
5005
5006/* This is too sick! */
7d160a6c
TM
5007static int decode_space_limit(struct xdr_stream *xdr,
5008 unsigned long *pagemod_limit)
1da177e4 5009{
05d564fe 5010 __be32 *p;
1da177e4 5011 uint32_t limit_type, nblocks, blocksize;
7d160a6c 5012 u64 maxsize = 0;
1da177e4 5013
c0eae66e
BH
5014 p = xdr_inline_decode(xdr, 12);
5015 if (unlikely(!p))
5016 goto out_overflow;
6f723f77 5017 limit_type = be32_to_cpup(p++);
1da177e4 5018 switch (limit_type) {
7d160a6c
TM
5019 case NFS4_LIMIT_SIZE:
5020 xdr_decode_hyper(p, &maxsize);
05d564fe 5021 break;
7d160a6c 5022 case NFS4_LIMIT_BLOCKS:
6f723f77 5023 nblocks = be32_to_cpup(p++);
cccddf4f 5024 blocksize = be32_to_cpup(p);
7d160a6c 5025 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
1da177e4 5026 }
09cbfeaf 5027 maxsize >>= PAGE_SHIFT;
7d160a6c 5028 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
1da177e4 5029 return 0;
c0eae66e
BH
5030out_overflow:
5031 print_overflow_msg(__func__, xdr);
5032 return -EIO;
1da177e4
LT
5033}
5034
6ae37339
TM
5035static int decode_rw_delegation(struct xdr_stream *xdr,
5036 uint32_t delegation_type,
5037 struct nfs_openres *res)
1da177e4 5038{
05d564fe 5039 __be32 *p;
07d30434 5040 int status;
1da177e4 5041
93b717fd 5042 status = decode_delegation_stateid(xdr, &res->delegation);
07d30434
BH
5043 if (unlikely(status))
5044 return status;
c0eae66e
BH
5045 p = xdr_inline_decode(xdr, 4);
5046 if (unlikely(!p))
5047 goto out_overflow;
cccddf4f 5048 res->do_recall = be32_to_cpup(p);
05d564fe 5049
1da177e4 5050 switch (delegation_type) {
05d564fe
AA
5051 case NFS4_OPEN_DELEGATE_READ:
5052 res->delegation_type = FMODE_READ;
5053 break;
5054 case NFS4_OPEN_DELEGATE_WRITE:
5055 res->delegation_type = FMODE_WRITE|FMODE_READ;
7d160a6c 5056 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
1da177e4
LT
5057 return -EIO;
5058 }
7539bbab 5059 return decode_ace(xdr, NULL, res->server->nfs_client);
c0eae66e
BH
5060out_overflow:
5061 print_overflow_msg(__func__, xdr);
5062 return -EIO;
1da177e4
LT
5063}
5064
6ae37339
TM
5065static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5066{
5067 __be32 *p;
5068 uint32_t why_no_delegation;
5069
5070 p = xdr_inline_decode(xdr, 4);
5071 if (unlikely(!p))
5072 goto out_overflow;
5073 why_no_delegation = be32_to_cpup(p);
5074 switch (why_no_delegation) {
5075 case WND4_CONTENTION:
5076 case WND4_RESOURCE:
5077 xdr_inline_decode(xdr, 4);
5078 /* Ignore for now */
5079 }
5080 return 0;
5081out_overflow:
5082 print_overflow_msg(__func__, xdr);
5083 return -EIO;
5084}
5085
5086static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5087{
5088 __be32 *p;
5089 uint32_t delegation_type;
5090
5091 p = xdr_inline_decode(xdr, 4);
5092 if (unlikely(!p))
5093 goto out_overflow;
5094 delegation_type = be32_to_cpup(p);
5095 res->delegation_type = 0;
5096 switch (delegation_type) {
5097 case NFS4_OPEN_DELEGATE_NONE:
5098 return 0;
5099 case NFS4_OPEN_DELEGATE_READ:
5100 case NFS4_OPEN_DELEGATE_WRITE:
5101 return decode_rw_delegation(xdr, delegation_type, res);
5102 case NFS4_OPEN_DELEGATE_NONE_EXT:
5103 return decode_no_delegation(xdr, res);
5104 }
5105 return -EIO;
5106out_overflow:
5107 print_overflow_msg(__func__, xdr);
5108 return -EIO;
5109}
5110
1da177e4
LT
5111static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5112{
05d564fe 5113 __be32 *p;
aa53ed54 5114 uint32_t savewords, bmlen, i;
05d564fe 5115 int status;
1da177e4 5116
c7848f69
TM
5117 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5118 return status;
5119 nfs_increment_open_seqid(status, res->seqid);
5120 if (status)
5121 return status;
93b717fd 5122 status = decode_open_stateid(xdr, &res->stateid);
07d30434 5123 if (unlikely(status))
05d564fe 5124 return status;
1da177e4 5125
05d564fe 5126 decode_change_info(xdr, &res->cinfo);
1da177e4 5127
c0eae66e
BH
5128 p = xdr_inline_decode(xdr, 8);
5129 if (unlikely(!p))
5130 goto out_overflow;
6f723f77 5131 res->rflags = be32_to_cpup(p++);
cccddf4f 5132 bmlen = be32_to_cpup(p);
05d564fe
AA
5133 if (bmlen > 10)
5134 goto xdr_error;
1da177e4 5135
c0eae66e
BH
5136 p = xdr_inline_decode(xdr, bmlen << 2);
5137 if (unlikely(!p))
5138 goto out_overflow;
aa53ed54
JL
5139 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5140 for (i = 0; i < savewords; ++i)
6f723f77 5141 res->attrset[i] = be32_to_cpup(p++);
aa53ed54
JL
5142 for (; i < NFS4_BITMAP_SIZE; i++)
5143 res->attrset[i] = 0;
5144
1da177e4
LT
5145 return decode_delegation(xdr, res);
5146xdr_error:
3110ff80 5147 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
1da177e4 5148 return -EIO;
c0eae66e
BH
5149out_overflow:
5150 print_overflow_msg(__func__, xdr);
5151 return -EIO;
1da177e4
LT
5152}
5153
5154static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5155{
1da177e4
LT
5156 int status;
5157
05d564fe 5158 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
c1d51931
TM
5159 if (status != -EIO)
5160 nfs_increment_open_seqid(status, res->seqid);
07d30434 5161 if (!status)
93b717fd 5162 status = decode_open_stateid(xdr, &res->stateid);
07d30434 5163 return status;
1da177e4
LT
5164}
5165
5166static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5167{
1da177e4
LT
5168 int status;
5169
5170 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
c1d51931
TM
5171 if (status != -EIO)
5172 nfs_increment_open_seqid(status, res->seqid);
07d30434 5173 if (!status)
93b717fd 5174 status = decode_open_stateid(xdr, &res->stateid);
07d30434 5175 return status;
1da177e4
LT
5176}
5177
5178static int decode_putfh(struct xdr_stream *xdr)
5179{
5180 return decode_op_hdr(xdr, OP_PUTFH);
5181}
5182
5183static int decode_putrootfh(struct xdr_stream *xdr)
5184{
5185 return decode_op_hdr(xdr, OP_PUTROOTFH);
5186}
5187
9137bdf3
AS
5188static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5189 struct nfs_pgio_res *res)
1da177e4 5190{
8687b63a 5191 __be32 *p;
64bd577e 5192 uint32_t count, eof, recvd;
1da177e4
LT
5193 int status;
5194
5195 status = decode_op_hdr(xdr, OP_READ);
5196 if (status)
5197 return status;
c0eae66e
BH
5198 p = xdr_inline_decode(xdr, 8);
5199 if (unlikely(!p))
5200 goto out_overflow;
6f723f77 5201 eof = be32_to_cpup(p++);
cccddf4f 5202 count = be32_to_cpup(p);
64bd577e 5203 recvd = xdr_read_pages(xdr, count);
1da177e4 5204 if (count > recvd) {
fe82a183 5205 dprintk("NFS: server cheating in read reply: "
1da177e4
LT
5206 "count %u > recvd %u\n", count, recvd);
5207 count = recvd;
5208 eof = 0;
5209 }
1da177e4
LT
5210 res->eof = eof;
5211 res->count = count;
5212 return 0;
c0eae66e
BH
5213out_overflow:
5214 print_overflow_msg(__func__, xdr);
5215 return -EIO;
1da177e4
LT
5216}
5217
5218static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5219{
bcecff77 5220 int status;
cd93710e 5221 __be32 verf[2];
1da177e4
LT
5222
5223 status = decode_op_hdr(xdr, OP_READDIR);
db942bbd
BH
5224 if (!status)
5225 status = decode_verifier(xdr, readdir->verifier.data);
5226 if (unlikely(status))
1da177e4 5227 return status;
cd93710e 5228 memcpy(verf, readdir->verifier.data, sizeof(verf));
44109241 5229 dprintk("%s: verifier = %08x:%08x\n",
cd93710e 5230 __func__, verf[0], verf[1]);
64bd577e 5231 return xdr_read_pages(xdr, xdr->buf->page_len);
1da177e4
LT
5232}
5233
5234static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5235{
5236 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
bcecff77 5237 u32 len, recvd;
8687b63a 5238 __be32 *p;
1da177e4
LT
5239 int status;
5240
5241 status = decode_op_hdr(xdr, OP_READLINK);
5242 if (status)
5243 return status;
5244
5245 /* Convert length of symlink */
c0eae66e
BH
5246 p = xdr_inline_decode(xdr, 4);
5247 if (unlikely(!p))
5248 goto out_overflow;
cccddf4f 5249 len = be32_to_cpup(p);
1da177e4 5250 if (len >= rcvbuf->page_len || len <= 0) {
fe82a183 5251 dprintk("nfs: server returned giant symlink!\n");
1da177e4
LT
5252 return -ENAMETOOLONG;
5253 }
64bd577e 5254 recvd = xdr_read_pages(xdr, len);
1da177e4 5255 if (recvd < len) {
fe82a183 5256 dprintk("NFS: server cheating in readlink reply: "
1da177e4
LT
5257 "count %u > recvd %u\n", len, recvd);
5258 return -EIO;
5259 }
1da177e4
LT
5260 /*
5261 * The XDR encode routine has set things up so that
5262 * the link text will be copied directly into the
5263 * buffer. We just have to do overflow-checking,
5264 * and and null-terminate the text (the VFS expects
5265 * null-termination).
5266 */
b4687da7 5267 xdr_terminate_string(rcvbuf, len);
1da177e4 5268 return 0;
c0eae66e
BH
5269out_overflow:
5270 print_overflow_msg(__func__, xdr);
5271 return -EIO;
1da177e4
LT
5272}
5273
5274static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5275{
5276 int status;
5277
5278 status = decode_op_hdr(xdr, OP_REMOVE);
5279 if (status)
5280 goto out;
5281 status = decode_change_info(xdr, cinfo);
5282out:
5283 return status;
5284}
5285
5286static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5287 struct nfs4_change_info *new_cinfo)
5288{
5289 int status;
5290
5291 status = decode_op_hdr(xdr, OP_RENAME);
5292 if (status)
5293 goto out;
5294 if ((status = decode_change_info(xdr, old_cinfo)))
5295 goto out;
5296 status = decode_change_info(xdr, new_cinfo);
5297out:
5298 return status;
5299}
5300
5301static int decode_renew(struct xdr_stream *xdr)
5302{
5303 return decode_op_hdr(xdr, OP_RENEW);
5304}
5305
56ae19f3
TM
5306static int
5307decode_restorefh(struct xdr_stream *xdr)
5308{
5309 return decode_op_hdr(xdr, OP_RESTOREFH);
5310}
5311
029d105e 5312static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
bf118a34 5313 struct nfs_getaclres *res)
029d105e 5314{
256e48bb 5315 unsigned int savep;
029d105e 5316 uint32_t attrlen,
dae100c2 5317 bitmap[3] = {0};
029d105e 5318 int status;
cff298c7 5319 unsigned int pg_offset;
029d105e 5320
bf118a34 5321 res->acl_len = 0;
029d105e
BF
5322 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5323 goto out;
5a006899 5324
519d3959
TM
5325 xdr_enter_page(xdr, xdr->buf->page_len);
5326
cff298c7
TM
5327 /* Calculate the offset of the page data */
5328 pg_offset = xdr->buf->head[0].iov_len;
5a006899 5329
029d105e
BF
5330 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5331 goto out;
5332 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5333 goto out;
5334
5335 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5336 return -EIO;
5337 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
029d105e 5338
bf118a34
AA
5339 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5340 * are stored with the acl data to handle the problem of
5341 * variable length bitmaps.*/
cff298c7 5342 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
519d3959 5343 res->acl_len = attrlen;
1f1ea6c2
TM
5344
5345 /* Check for receive buffer overflow */
5346 if (res->acl_len > (xdr->nwords << 2) ||
5347 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5348 res->acl_flags |= NFS4_ACL_TRUNC;
519d3959 5349 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
cff298c7 5350 attrlen, xdr->nwords << 2);
029d105e 5351 }
8c233cf9
BF
5352 } else
5353 status = -EOPNOTSUPP;
029d105e
BF
5354
5355out:
5356 return status;
5357}
5358
1da177e4
LT
5359static int
5360decode_savefh(struct xdr_stream *xdr)
5361{
5362 return decode_op_hdr(xdr, OP_SAVEFH);
5363}
5364
9e9ecc03 5365static int decode_setattr(struct xdr_stream *xdr)
1da177e4 5366{
8687b63a 5367 __be32 *p;
1da177e4
LT
5368 uint32_t bmlen;
5369 int status;
5370
1da177e4
LT
5371 status = decode_op_hdr(xdr, OP_SETATTR);
5372 if (status)
5373 return status;
c0eae66e
BH
5374 p = xdr_inline_decode(xdr, 4);
5375 if (unlikely(!p))
5376 goto out_overflow;
cccddf4f 5377 bmlen = be32_to_cpup(p);
c0eae66e
BH
5378 p = xdr_inline_decode(xdr, bmlen << 2);
5379 if (likely(p))
5380 return 0;
5381out_overflow:
5382 print_overflow_msg(__func__, xdr);
5383 return -EIO;
1da177e4
LT
5384}
5385
bb8b27e5 5386static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
1da177e4 5387{
8687b63a 5388 __be32 *p;
1da177e4
LT
5389 uint32_t opnum;
5390 int32_t nfserr;
5391
c0eae66e
BH
5392 p = xdr_inline_decode(xdr, 8);
5393 if (unlikely(!p))
5394 goto out_overflow;
6f723f77 5395 opnum = be32_to_cpup(p++);
1da177e4 5396 if (opnum != OP_SETCLIENTID) {
fe82a183 5397 dprintk("nfs: decode_setclientid: Server returned operation"
6c0195a4 5398 " %d\n", opnum);
1da177e4
LT
5399 return -EIO;
5400 }
cccddf4f 5401 nfserr = be32_to_cpup(p);
1da177e4 5402 if (nfserr == NFS_OK) {
c0eae66e
BH
5403 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5404 if (unlikely(!p))
5405 goto out_overflow;
bb8b27e5
TM
5406 p = xdr_decode_hyper(p, &res->clientid);
5407 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
1da177e4
LT
5408 } else if (nfserr == NFSERR_CLID_INUSE) {
5409 uint32_t len;
5410
5411 /* skip netid string */
c0eae66e
BH
5412 p = xdr_inline_decode(xdr, 4);
5413 if (unlikely(!p))
5414 goto out_overflow;
cccddf4f 5415 len = be32_to_cpup(p);
c0eae66e
BH
5416 p = xdr_inline_decode(xdr, len);
5417 if (unlikely(!p))
5418 goto out_overflow;
1da177e4
LT
5419
5420 /* skip uaddr string */
c0eae66e
BH
5421 p = xdr_inline_decode(xdr, 4);
5422 if (unlikely(!p))
5423 goto out_overflow;
cccddf4f 5424 len = be32_to_cpup(p);
c0eae66e
BH
5425 p = xdr_inline_decode(xdr, len);
5426 if (unlikely(!p))
5427 goto out_overflow;
1da177e4
LT
5428 return -NFSERR_CLID_INUSE;
5429 } else
856dff3d 5430 return nfs4_stat_to_errno(nfserr);
1da177e4
LT
5431
5432 return 0;
c0eae66e
BH
5433out_overflow:
5434 print_overflow_msg(__func__, xdr);
5435 return -EIO;
1da177e4
LT
5436}
5437
5438static int decode_setclientid_confirm(struct xdr_stream *xdr)
5439{
5440 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5441}
5442
9137bdf3 5443static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
1da177e4 5444{
8687b63a 5445 __be32 *p;
1da177e4
LT
5446 int status;
5447
5448 status = decode_op_hdr(xdr, OP_WRITE);
5449 if (status)
5450 return status;
5451
2f2c63bc 5452 p = xdr_inline_decode(xdr, 8);
c0eae66e
BH
5453 if (unlikely(!p))
5454 goto out_overflow;
6f723f77
BH
5455 res->count = be32_to_cpup(p++);
5456 res->verf->committed = be32_to_cpup(p++);
2f2c63bc 5457 return decode_write_verifier(xdr, &res->verf->verifier);
c0eae66e
BH
5458out_overflow:
5459 print_overflow_msg(__func__, xdr);
5460 return -EIO;
1da177e4
LT
5461}
5462
5463static int decode_delegreturn(struct xdr_stream *xdr)
5464{
5465 return decode_op_hdr(xdr, OP_DELEGRETURN);
5466}
5467
fb15b26f
CL
5468static int decode_secinfo_gss(struct xdr_stream *xdr,
5469 struct nfs4_secinfo4 *flavor)
5a5ea0d4 5470{
fb15b26f 5471 u32 oid_len;
5a5ea0d4
BS
5472 __be32 *p;
5473
5474 p = xdr_inline_decode(xdr, 4);
5475 if (unlikely(!p))
5476 goto out_overflow;
fb15b26f
CL
5477 oid_len = be32_to_cpup(p);
5478 if (oid_len > GSS_OID_MAX_LEN)
5a5ea0d4
BS
5479 goto out_err;
5480
fb15b26f 5481 p = xdr_inline_decode(xdr, oid_len);
5a5ea0d4
BS
5482 if (unlikely(!p))
5483 goto out_overflow;
fb15b26f
CL
5484 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5485 flavor->flavor_info.oid.len = oid_len;
5a5ea0d4
BS
5486
5487 p = xdr_inline_decode(xdr, 8);
5488 if (unlikely(!p))
5489 goto out_overflow;
fb15b26f
CL
5490 flavor->flavor_info.qop = be32_to_cpup(p++);
5491 flavor->flavor_info.service = be32_to_cpup(p);
5a5ea0d4
BS
5492
5493 return 0;
5494
5495out_overflow:
5496 print_overflow_msg(__func__, xdr);
5497 return -EIO;
5498out_err:
5499 return -EINVAL;
5500}
5501
31e4dda4 5502static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5a5ea0d4 5503{
fb15b26f
CL
5504 struct nfs4_secinfo4 *sec_flavor;
5505 unsigned int i, num_flavors;
5a5ea0d4
BS
5506 int status;
5507 __be32 *p;
5a5ea0d4 5508
5a5ea0d4
BS
5509 p = xdr_inline_decode(xdr, 4);
5510 if (unlikely(!p))
5511 goto out_overflow;
5a5ea0d4 5512
c3dfc280
BS
5513 res->flavors->num_flavors = 0;
5514 num_flavors = be32_to_cpup(p);
5515
5516 for (i = 0; i < num_flavors; i++) {
5a5ea0d4 5517 sec_flavor = &res->flavors->flavors[i];
c3dfc280 5518 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5a5ea0d4
BS
5519 break;
5520
5521 p = xdr_inline_decode(xdr, 4);
5522 if (unlikely(!p))
5523 goto out_overflow;
5524 sec_flavor->flavor = be32_to_cpup(p);
5525
5526 if (sec_flavor->flavor == RPC_AUTH_GSS) {
613e901e
BS
5527 status = decode_secinfo_gss(xdr, sec_flavor);
5528 if (status)
5529 goto out;
5a5ea0d4 5530 }
c3dfc280 5531 res->flavors->num_flavors++;
5a5ea0d4
BS
5532 }
5533
31e4dda4 5534 status = 0;
613e901e
BS
5535out:
5536 return status;
5a5ea0d4
BS
5537out_overflow:
5538 print_overflow_msg(__func__, xdr);
5539 return -EIO;
5540}
5541
31e4dda4
BS
5542static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5543{
5544 int status = decode_op_hdr(xdr, OP_SECINFO);
5545 if (status)
5546 return status;
5547 return decode_secinfo_common(xdr, res);
5548}
5549
99fe60d0 5550#if defined(CONFIG_NFS_V4_1)
31e4dda4
BS
5551static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5552{
5553 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5554 if (status)
5555 return status;
5556 return decode_secinfo_common(xdr, res);
5557}
5558
2031cd1a
WAA
5559static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5560{
5561 __be32 *p;
5562 uint32_t bitmap_words;
5563 unsigned int i;
5564
5565 p = xdr_inline_decode(xdr, 4);
5566 bitmap_words = be32_to_cpup(p++);
5567 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5568 return -EIO;
5569 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5570 for (i = 0; i < bitmap_words; i++)
5571 op_map->u.words[i] = be32_to_cpup(p++);
5572
5573 return 0;
5574}
5575
99fe60d0
BH
5576static int decode_exchange_id(struct xdr_stream *xdr,
5577 struct nfs41_exchange_id_res *res)
5578{
5579 __be32 *p;
5580 uint32_t dummy;
2460ba57 5581 char *dummy_str;
99fe60d0 5582 int status;
7d2ed9ac 5583 uint32_t impl_id_count;
99fe60d0
BH
5584
5585 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5586 if (status)
5587 return status;
5588
c0eae66e
BH
5589 p = xdr_inline_decode(xdr, 8);
5590 if (unlikely(!p))
5591 goto out_overflow;
32b01310 5592 xdr_decode_hyper(p, &res->clientid);
c0eae66e
BH
5593 p = xdr_inline_decode(xdr, 12);
5594 if (unlikely(!p))
5595 goto out_overflow;
32b01310
TM
5596 res->seqid = be32_to_cpup(p++);
5597 res->flags = be32_to_cpup(p++);
99fe60d0 5598
2031cd1a
WAA
5599 res->state_protect.how = be32_to_cpup(p);
5600 switch (res->state_protect.how) {
5601 case SP4_NONE:
5602 break;
5603 case SP4_MACH_CRED:
5604 status = decode_op_map(xdr, &res->state_protect.enforce);
5605 if (status)
5606 return status;
5607 status = decode_op_map(xdr, &res->state_protect.allow);
5608 if (status)
5609 return status;
5610 break;
5611 default:
5612 WARN_ON_ONCE(1);
99fe60d0 5613 return -EIO;
2031cd1a 5614 }
99fe60d0 5615
acdeb69d 5616 /* server_owner4.so_minor_id */
c0eae66e
BH
5617 p = xdr_inline_decode(xdr, 8);
5618 if (unlikely(!p))
5619 goto out_overflow;
acdeb69d 5620 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
99fe60d0 5621
acdeb69d 5622 /* server_owner4.so_major_id */
2460ba57
BH
5623 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5624 if (unlikely(status))
5625 return status;
acdeb69d
CL
5626 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5627 return -EIO;
5628 memcpy(res->server_owner->major_id, dummy_str, dummy);
5629 res->server_owner->major_id_sz = dummy;
99fe60d0 5630
acdeb69d 5631 /* server_scope4 */
2460ba57
BH
5632 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5633 if (unlikely(status))
5634 return status;
78fe0f41
WAA
5635 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5636 return -EIO;
78fe0f41
WAA
5637 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5638 res->server_scope->server_scope_sz = dummy;
5639
7d2ed9ac
WAA
5640 /* Implementation Id */
5641 p = xdr_inline_decode(xdr, 4);
5642 if (unlikely(!p))
5643 goto out_overflow;
5644 impl_id_count = be32_to_cpup(p++);
99fe60d0 5645
7d2ed9ac
WAA
5646 if (impl_id_count) {
5647 /* nii_domain */
5648 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5649 if (unlikely(status))
5650 return status;
5651 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5652 return -EIO;
5653 memcpy(res->impl_id->domain, dummy_str, dummy);
5654
5655 /* nii_name */
5656 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5657 if (unlikely(status))
5658 return status;
5659 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5660 return -EIO;
5661 memcpy(res->impl_id->name, dummy_str, dummy);
5662
5663 /* nii_date */
5664 p = xdr_inline_decode(xdr, 12);
5665 if (unlikely(!p))
5666 goto out_overflow;
5667 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5668 res->impl_id->date.nseconds = be32_to_cpup(p);
5669
5670 /* if there's more than one entry, ignore the rest */
5671 }
99fe60d0 5672 return 0;
c0eae66e
BH
5673out_overflow:
5674 print_overflow_msg(__func__, xdr);
5675 return -EIO;
99fe60d0 5676}
fc931582
AA
5677
5678static int decode_chan_attrs(struct xdr_stream *xdr,
5679 struct nfs4_channel_attrs *attrs)
5680{
5681 __be32 *p;
c9c30dd5 5682 u32 nr_attrs, val;
fc931582 5683
c0eae66e
BH
5684 p = xdr_inline_decode(xdr, 28);
5685 if (unlikely(!p))
5686 goto out_overflow;
c9c30dd5
BH
5687 val = be32_to_cpup(p++); /* headerpadsz */
5688 if (val)
5689 return -EINVAL; /* no support for header padding yet */
6f723f77
BH
5690 attrs->max_rqst_sz = be32_to_cpup(p++);
5691 attrs->max_resp_sz = be32_to_cpup(p++);
5692 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5693 attrs->max_ops = be32_to_cpup(p++);
5694 attrs->max_reqs = be32_to_cpup(p++);
cccddf4f 5695 nr_attrs = be32_to_cpup(p);
fc931582 5696 if (unlikely(nr_attrs > 1)) {
a030889a
WAA
5697 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5698 "count %u\n", __func__, nr_attrs);
fc931582
AA
5699 return -EINVAL;
5700 }
c0eae66e
BH
5701 if (nr_attrs == 1) {
5702 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5703 if (unlikely(!p))
5704 goto out_overflow;
5705 }
fc931582 5706 return 0;
c0eae66e
BH
5707out_overflow:
5708 print_overflow_msg(__func__, xdr);
5709 return -EIO;
fc931582
AA
5710}
5711
e78291e4
BH
5712static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5713{
5714 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
fc931582
AA
5715}
5716
7c44f1ae
WAA
5717static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5718 struct nfs41_bind_conn_to_session_res *res)
5719{
5720 __be32 *p;
5721 int status;
5722
5723 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5724 if (!status)
71a097c6 5725 status = decode_sessionid(xdr, &res->sessionid);
7c44f1ae
WAA
5726 if (unlikely(status))
5727 return status;
5728
5729 /* dir flags, rdma mode bool */
5730 p = xdr_inline_decode(xdr, 8);
5731 if (unlikely(!p))
5732 goto out_overflow;
5733
5734 res->dir = be32_to_cpup(p++);
5735 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5736 return -EIO;
5737 if (be32_to_cpup(p) == 0)
5738 res->use_conn_in_rdma_mode = false;
5739 else
5740 res->use_conn_in_rdma_mode = true;
5741
5742 return 0;
5743out_overflow:
5744 print_overflow_msg(__func__, xdr);
5745 return -EIO;
5746}
5747
fc931582
AA
5748static int decode_create_session(struct xdr_stream *xdr,
5749 struct nfs41_create_session_res *res)
5750{
5751 __be32 *p;
5752 int status;
fc931582
AA
5753
5754 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
e78291e4 5755 if (!status)
79969dd1 5756 status = decode_sessionid(xdr, &res->sessionid);
e78291e4 5757 if (unlikely(status))
fc931582
AA
5758 return status;
5759
fc931582 5760 /* seqid, flags */
c0eae66e
BH
5761 p = xdr_inline_decode(xdr, 8);
5762 if (unlikely(!p))
5763 goto out_overflow;
79969dd1
TM
5764 res->seqid = be32_to_cpup(p++);
5765 res->flags = be32_to_cpup(p);
fc931582
AA
5766
5767 /* Channel attributes */
79969dd1 5768 status = decode_chan_attrs(xdr, &res->fc_attrs);
fc931582 5769 if (!status)
79969dd1 5770 status = decode_chan_attrs(xdr, &res->bc_attrs);
fc931582 5771 return status;
c0eae66e
BH
5772out_overflow:
5773 print_overflow_msg(__func__, xdr);
5774 return -EIO;
fc931582 5775}
0f3e66c6
AA
5776
5777static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5778{
5779 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5780}
18019753 5781
66245539
TM
5782static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5783{
5784 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5785}
5786
18019753
RL
5787static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5788{
5789 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5790}
99fe60d0
BH
5791#endif /* CONFIG_NFS_V4_1 */
5792
9b7b9fcc
AA
5793static int decode_sequence(struct xdr_stream *xdr,
5794 struct nfs4_sequence_res *res,
5795 struct rpc_rqst *rqstp)
5796{
5797#if defined(CONFIG_NFS_V4_1)
e3725ec0 5798 struct nfs4_session *session;
fc01cea9
AA
5799 struct nfs4_sessionid id;
5800 u32 dummy;
5801 int status;
5802 __be32 *p;
5803
e3725ec0 5804 if (res->sr_slot == NULL)
9b7b9fcc 5805 return 0;
3bd2384a
CL
5806 if (!res->sr_slot->table->session)
5807 return 0;
9b7b9fcc 5808
fc01cea9 5809 status = decode_op_hdr(xdr, OP_SEQUENCE);
e78291e4
BH
5810 if (!status)
5811 status = decode_sessionid(xdr, &id);
5812 if (unlikely(status))
fc01cea9 5813 goto out_err;
9b7b9fcc 5814
fc01cea9
AA
5815 /*
5816 * If the server returns different values for sessionID, slotID or
5817 * sequence number, the server is looney tunes.
5818 */
fdcb4577 5819 status = -EREMOTEIO;
e3725ec0 5820 session = res->sr_slot->table->session;
fc01cea9 5821
e3725ec0 5822 if (memcmp(id.data, session->sess_id.data,
fc01cea9
AA
5823 NFS4_MAX_SESSIONID_LEN)) {
5824 dprintk("%s Invalid session id\n", __func__);
5825 goto out_err;
5826 }
e78291e4 5827
c0eae66e
BH
5828 p = xdr_inline_decode(xdr, 20);
5829 if (unlikely(!p))
5830 goto out_overflow;
e78291e4 5831
fc01cea9 5832 /* seqid */
6f723f77 5833 dummy = be32_to_cpup(p++);
dfb4f309 5834 if (dummy != res->sr_slot->seq_nr) {
fc01cea9
AA
5835 dprintk("%s Invalid sequence number\n", __func__);
5836 goto out_err;
5837 }
5838 /* slot id */
6f723f77 5839 dummy = be32_to_cpup(p++);
df2fabff 5840 if (dummy != res->sr_slot->slot_nr) {
fc01cea9
AA
5841 dprintk("%s Invalid slot id\n", __func__);
5842 goto out_err;
5843 }
da0507b7
TM
5844 /* highest slot id */
5845 res->sr_highest_slotid = be32_to_cpup(p++);
464ee9f9
TM
5846 /* target highest slot id */
5847 res->sr_target_highest_slotid = be32_to_cpup(p++);
0629e370
AB
5848 /* result flags */
5849 res->sr_status_flags = be32_to_cpup(p);
fc01cea9
AA
5850 status = 0;
5851out_err:
5852 res->sr_status = status;
5853 return status;
c0eae66e
BH
5854out_overflow:
5855 print_overflow_msg(__func__, xdr);
5856 status = -EIO;
5857 goto out_err;
fc01cea9 5858#else /* CONFIG_NFS_V4_1 */
9b7b9fcc 5859 return 0;
fc01cea9 5860#endif /* CONFIG_NFS_V4_1 */
9b7b9fcc
AA
5861}
5862
b1f69b75 5863#if defined(CONFIG_NFS_V4_1)
93b717fd
TM
5864static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5865{
5866 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5867 return decode_stateid(xdr, stateid);
5868}
5869
b1f69b75 5870static int decode_getdeviceinfo(struct xdr_stream *xdr,
4e590803 5871 struct nfs4_getdeviceinfo_res *res)
b1f69b75 5872{
4e590803 5873 struct pnfs_device *pdev = res->pdev;
b1f69b75
AA
5874 __be32 *p;
5875 uint32_t len, type;
5876 int status;
5877
5878 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5879 if (status) {
5880 if (status == -ETOOSMALL) {
5881 p = xdr_inline_decode(xdr, 4);
5882 if (unlikely(!p))
5883 goto out_overflow;
5884 pdev->mincount = be32_to_cpup(p);
5885 dprintk("%s: Min count too small. mincnt = %u\n",
5886 __func__, pdev->mincount);
5887 }
5888 return status;
5889 }
5890
5891 p = xdr_inline_decode(xdr, 8);
5892 if (unlikely(!p))
5893 goto out_overflow;
5894 type = be32_to_cpup(p++);
5895 if (type != pdev->layout_type) {
5896 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5897 __func__, pdev->layout_type, type);
5898 return -EINVAL;
5899 }
5900 /*
5901 * Get the length of the opaque device_addr4. xdr_read_pages places
5902 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5903 * and places the remaining xdr data in xdr_buf->tail
5904 */
5905 pdev->mincount = be32_to_cpup(p);
13fe4ba1
TM
5906 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5907 goto out_overflow;
b1f69b75
AA
5908
5909 /* Parse notification bitmap, verifying that it is zero. */
5910 p = xdr_inline_decode(xdr, 4);
5911 if (unlikely(!p))
5912 goto out_overflow;
5913 len = be32_to_cpup(p);
5914 if (len) {
ead00597 5915 uint32_t i;
b1f69b75
AA
5916
5917 p = xdr_inline_decode(xdr, 4 * len);
5918 if (unlikely(!p))
5919 goto out_overflow;
84c9dee3 5920
4e590803 5921 res->notification = be32_to_cpup(p++);
84c9dee3
CH
5922 for (i = 1; i < len; i++) {
5923 if (be32_to_cpup(p++)) {
5924 dprintk("%s: unsupported notification\n",
b1f69b75
AA
5925 __func__);
5926 return -EIO;
5927 }
5928 }
5929 }
5930 return 0;
5931out_overflow:
5932 print_overflow_msg(__func__, xdr);
5933 return -EIO;
5934}
5935
5936static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5937 struct nfs4_layoutget_res *res)
5938{
5939 __be32 *p;
5940 int status;
5941 u32 layout_count;
64bd577e 5942 u32 recvd;
b1f69b75
AA
5943
5944 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5945 if (status)
5946 return status;
ea9d23f5
TM
5947 p = xdr_inline_decode(xdr, 4);
5948 if (unlikely(!p))
5949 goto out_overflow;
5950 res->return_on_close = be32_to_cpup(p);
93b717fd 5951 decode_layout_stateid(xdr, &res->stateid);
ea9d23f5 5952 p = xdr_inline_decode(xdr, 4);
b1f69b75
AA
5953 if (unlikely(!p))
5954 goto out_overflow;
b1f69b75
AA
5955 layout_count = be32_to_cpup(p);
5956 if (!layout_count) {
5957 dprintk("%s: server responded with empty layout array\n",
5958 __func__);
5959 return -EINVAL;
5960 }
5961
35124a09 5962 p = xdr_inline_decode(xdr, 28);
b1f69b75
AA
5963 if (unlikely(!p))
5964 goto out_overflow;
5965 p = xdr_decode_hyper(p, &res->range.offset);
5966 p = xdr_decode_hyper(p, &res->range.length);
5967 res->range.iomode = be32_to_cpup(p++);
5968 res->type = be32_to_cpup(p++);
35124a09 5969 res->layoutp->len = be32_to_cpup(p);
b1f69b75
AA
5970
5971 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5972 __func__,
5973 (unsigned long)res->range.offset,
5974 (unsigned long)res->range.length,
5975 res->range.iomode,
5976 res->type,
35124a09
WAA
5977 res->layoutp->len);
5978
64bd577e 5979 recvd = xdr_read_pages(xdr, res->layoutp->len);
35124a09
WAA
5980 if (res->layoutp->len > recvd) {
5981 dprintk("NFS: server cheating in layoutget reply: "
5982 "layout len %u > recvd %u\n",
5983 res->layoutp->len, recvd);
5984 return -EINVAL;
5985 }
b1f69b75 5986
b1f69b75
AA
5987 if (layout_count > 1) {
5988 /* We only handle a length one array at the moment. Any
5989 * further entries are just ignored. Note that this means
5990 * the client may see a response that is less than the
5991 * minimum it requested.
5992 */
5993 dprintk("%s: server responded with %d layouts, dropping tail\n",
5994 __func__, layout_count);
5995 }
5996
5997 return 0;
5998out_overflow:
5999 print_overflow_msg(__func__, xdr);
6000 return -EIO;
6001}
863a3c6c 6002
cbe82603
BH
6003static int decode_layoutreturn(struct xdr_stream *xdr,
6004 struct nfs4_layoutreturn_res *res)
6005{
6006 __be32 *p;
6007 int status;
6008
6009 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6010 if (status)
6011 return status;
6012 p = xdr_inline_decode(xdr, 4);
6013 if (unlikely(!p))
6014 goto out_overflow;
6015 res->lrs_present = be32_to_cpup(p);
6016 if (res->lrs_present)
93b717fd 6017 status = decode_layout_stateid(xdr, &res->stateid);
cbe82603
BH
6018 return status;
6019out_overflow:
6020 print_overflow_msg(__func__, xdr);
6021 return -EIO;
6022}
6023
863a3c6c
AA
6024static int decode_layoutcommit(struct xdr_stream *xdr,
6025 struct rpc_rqst *req,
6026 struct nfs4_layoutcommit_res *res)
6027{
6028 __be32 *p;
6029 __u32 sizechanged;
6030 int status;
6031
6032 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
db29c089 6033 res->status = status;
863a3c6c
AA
6034 if (status)
6035 return status;
6036
6037 p = xdr_inline_decode(xdr, 4);
6038 if (unlikely(!p))
6039 goto out_overflow;
6040 sizechanged = be32_to_cpup(p);
6041
6042 if (sizechanged) {
6043 /* throw away new size */
6044 p = xdr_inline_decode(xdr, 8);
6045 if (unlikely(!p))
6046 goto out_overflow;
6047 }
6048 return 0;
6049out_overflow:
6050 print_overflow_msg(__func__, xdr);
6051 return -EIO;
6052}
7d974794
BS
6053
6054static int decode_test_stateid(struct xdr_stream *xdr,
6055 struct nfs41_test_stateid_res *res)
6056{
6057 __be32 *p;
6058 int status;
6059 int num_res;
6060
6061 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6062 if (status)
6063 return status;
6064
6065 p = xdr_inline_decode(xdr, 4);
6066 if (unlikely(!p))
6067 goto out_overflow;
6068 num_res = be32_to_cpup(p++);
6069 if (num_res != 1)
6070 goto out;
6071
6072 p = xdr_inline_decode(xdr, 4);
6073 if (unlikely(!p))
6074 goto out_overflow;
6075 res->status = be32_to_cpup(p++);
1cab0652
BS
6076
6077 return status;
7d974794
BS
6078out_overflow:
6079 print_overflow_msg(__func__, xdr);
6080out:
6081 return -EIO;
6082}
9aeda35f
BS
6083
6084static int decode_free_stateid(struct xdr_stream *xdr,
6085 struct nfs41_free_stateid_res *res)
6086{
9f79fb48 6087 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
9aeda35f 6088 return res->status;
9aeda35f 6089}
b1f69b75
AA
6090#endif /* CONFIG_NFS_V4_1 */
6091
49c2559e
BH
6092/*
6093 * END OF "GENERIC" DECODE ROUTINES.
6094 */
6095
1da177e4
LT
6096/*
6097 * Decode OPEN_DOWNGRADE response
6098 */
bf269551
CL
6099static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6100 struct xdr_stream *xdr,
6101 struct nfs_closeres *res)
1da177e4 6102{
05d564fe
AA
6103 struct compound_hdr hdr;
6104 int status;
6105
bf269551 6106 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6107 if (status)
6108 goto out;
bf269551 6109 status = decode_sequence(xdr, &res->seq_res, rqstp);
05d564fe
AA
6110 if (status)
6111 goto out;
bf269551 6112 status = decode_putfh(xdr);
05d564fe
AA
6113 if (status)
6114 goto out;
bf269551 6115 status = decode_open_downgrade(xdr, res);
1da177e4 6116out:
05d564fe 6117 return status;
1da177e4
LT
6118}
6119
1da177e4
LT
6120/*
6121 * Decode ACCESS response
6122 */
bf269551
CL
6123static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6124 struct nfs4_accessres *res)
1da177e4 6125{
1da177e4
LT
6126 struct compound_hdr hdr;
6127 int status;
6c0195a4 6128
bf269551 6129 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6130 if (status)
6131 goto out;
bf269551 6132 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6133 if (status)
1da177e4 6134 goto out;
bf269551 6135 status = decode_putfh(xdr);
76b32999
TM
6136 if (status != 0)
6137 goto out;
6168f62c 6138 status = decode_access(xdr, &res->supported, &res->access);
76b32999
TM
6139 if (status != 0)
6140 goto out;
6926afd1 6141 decode_getfattr(xdr, res->fattr, res->server);
1da177e4
LT
6142out:
6143 return status;
6144}
6145
6146/*
6147 * Decode LOOKUP response
6148 */
bf269551
CL
6149static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6150 struct nfs4_lookup_res *res)
1da177e4 6151{
1da177e4
LT
6152 struct compound_hdr hdr;
6153 int status;
6c0195a4 6154
bf269551 6155 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6156 if (status)
6157 goto out;
bf269551 6158 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6159 if (status)
1da177e4 6160 goto out;
bf269551
CL
6161 status = decode_putfh(xdr);
6162 if (status)
1da177e4 6163 goto out;
bf269551
CL
6164 status = decode_lookup(xdr);
6165 if (status)
1da177e4 6166 goto out;
bf269551
CL
6167 status = decode_getfh(xdr, res->fh);
6168 if (status)
1da177e4 6169 goto out;
aa9c2669 6170 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
1da177e4
LT
6171out:
6172 return status;
6173}
6174
6175/*
6176 * Decode LOOKUP_ROOT response
6177 */
bf269551
CL
6178static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6179 struct xdr_stream *xdr,
6180 struct nfs4_lookup_res *res)
1da177e4 6181{
1da177e4
LT
6182 struct compound_hdr hdr;
6183 int status;
6c0195a4 6184
bf269551 6185 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6186 if (status)
6187 goto out;
bf269551 6188 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6189 if (status)
1da177e4 6190 goto out;
bf269551
CL
6191 status = decode_putrootfh(xdr);
6192 if (status)
1da177e4 6193 goto out;
bf269551
CL
6194 status = decode_getfh(xdr, res->fh);
6195 if (status == 0)
aa9c2669
DQ
6196 status = decode_getfattr_label(xdr, res->fattr,
6197 res->label, res->server);
1da177e4
LT
6198out:
6199 return status;
6200}
6201
6202/*
6203 * Decode REMOVE response
6204 */
bf269551
CL
6205static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6206 struct nfs_removeres *res)
1da177e4 6207{
1da177e4
LT
6208 struct compound_hdr hdr;
6209 int status;
6c0195a4 6210
bf269551 6211 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6212 if (status)
6213 goto out;
bf269551 6214 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6215 if (status)
1da177e4 6216 goto out;
bf269551
CL
6217 status = decode_putfh(xdr);
6218 if (status)
16e42959 6219 goto out;
bf269551 6220 status = decode_remove(xdr, &res->cinfo);
1da177e4
LT
6221out:
6222 return status;
6223}
6224
6225/*
6226 * Decode RENAME response
6227 */
bf269551
CL
6228static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6229 struct nfs_renameres *res)
1da177e4 6230{
1da177e4
LT
6231 struct compound_hdr hdr;
6232 int status;
6c0195a4 6233
bf269551 6234 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6235 if (status)
6236 goto out;
bf269551 6237 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6238 if (status)
1da177e4 6239 goto out;
bf269551
CL
6240 status = decode_putfh(xdr);
6241 if (status)
1da177e4 6242 goto out;
bf269551
CL
6243 status = decode_savefh(xdr);
6244 if (status)
1da177e4 6245 goto out;
bf269551
CL
6246 status = decode_putfh(xdr);
6247 if (status)
1da177e4 6248 goto out;
bf269551 6249 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
1da177e4
LT
6250out:
6251 return status;
6252}
6253
6254/*
6255 * Decode LINK response
6256 */
bf269551
CL
6257static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6258 struct nfs4_link_res *res)
1da177e4 6259{
1da177e4
LT
6260 struct compound_hdr hdr;
6261 int status;
6c0195a4 6262
bf269551 6263 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6264 if (status)
6265 goto out;
bf269551 6266 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6267 if (status)
1da177e4 6268 goto out;
bf269551
CL
6269 status = decode_putfh(xdr);
6270 if (status)
1da177e4 6271 goto out;
bf269551
CL
6272 status = decode_savefh(xdr);
6273 if (status)
1da177e4 6274 goto out;
bf269551
CL
6275 status = decode_putfh(xdr);
6276 if (status)
1da177e4 6277 goto out;
bf269551
CL
6278 status = decode_link(xdr, &res->cinfo);
6279 if (status)
91ba2eee
TM
6280 goto out;
6281 /*
6282 * Note order: OP_LINK leaves the directory as the current
6283 * filehandle.
6284 */
bf269551
CL
6285 status = decode_restorefh(xdr);
6286 if (status)
91ba2eee 6287 goto out;
aa9c2669 6288 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
1da177e4
LT
6289out:
6290 return status;
6291}
6292
6293/*
6294 * Decode CREATE response
6295 */
bf269551
CL
6296static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6297 struct nfs4_create_res *res)
1da177e4 6298{
1da177e4
LT
6299 struct compound_hdr hdr;
6300 int status;
6c0195a4 6301
bf269551 6302 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6303 if (status)
6304 goto out;
bf269551 6305 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6306 if (status)
1da177e4 6307 goto out;
bf269551 6308 status = decode_putfh(xdr);
bf269551 6309 if (status)
56ae19f3 6310 goto out;
bf269551
CL
6311 status = decode_create(xdr, &res->dir_cinfo);
6312 if (status)
1da177e4 6313 goto out;
bf269551
CL
6314 status = decode_getfh(xdr, res->fh);
6315 if (status)
1da177e4 6316 goto out;
aa9c2669 6317 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
1da177e4
LT
6318out:
6319 return status;
6320}
6321
6322/*
6323 * Decode SYMLINK response
6324 */
bf269551
CL
6325static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6326 struct nfs4_create_res *res)
1da177e4 6327{
bf269551 6328 return nfs4_xdr_dec_create(rqstp, xdr, res);
1da177e4
LT
6329}
6330
6331/*
6332 * Decode GETATTR response
6333 */
bf269551
CL
6334static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6335 struct nfs4_getattr_res *res)
1da177e4 6336{
1da177e4
LT
6337 struct compound_hdr hdr;
6338 int status;
6c0195a4 6339
bf269551 6340 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6341 if (status)
6342 goto out;
bf269551 6343 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6344 if (status)
6345 goto out;
bf269551 6346 status = decode_putfh(xdr);
1da177e4
LT
6347 if (status)
6348 goto out;
aa9c2669 6349 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
1da177e4
LT
6350out:
6351 return status;
1da177e4
LT
6352}
6353
23ec6965
BF
6354/*
6355 * Encode an SETACL request
6356 */
9f06c719
CL
6357static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6358 struct nfs_setaclargs *args)
23ec6965 6359{
05d564fe 6360 struct compound_hdr hdr = {
66cc0429 6361 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 6362 };
05d564fe 6363
9f06c719
CL
6364 encode_compound_hdr(xdr, req, &hdr);
6365 encode_sequence(xdr, &args->seq_args, &hdr);
6366 encode_putfh(xdr, args->fh, &hdr);
6367 encode_setacl(xdr, args, &hdr);
d017931c 6368 encode_nops(&hdr);
23ec6965 6369}
05d564fe 6370
23ec6965
BF
6371/*
6372 * Decode SETACL response
6373 */
6374static int
bf269551 6375nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
73c403a9 6376 struct nfs_setaclres *res)
23ec6965 6377{
23ec6965
BF
6378 struct compound_hdr hdr;
6379 int status;
6380
bf269551 6381 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6382 if (status)
6383 goto out;
bf269551 6384 status = decode_sequence(xdr, &res->seq_res, rqstp);
23ec6965
BF
6385 if (status)
6386 goto out;
bf269551 6387 status = decode_putfh(xdr);
23ec6965
BF
6388 if (status)
6389 goto out;
bf269551 6390 status = decode_setattr(xdr);
23ec6965
BF
6391out:
6392 return status;
6393}
1da177e4 6394
029d105e
BF
6395/*
6396 * Decode GETACL response
6397 */
6398static int
bf269551 6399nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
663c79b3 6400 struct nfs_getaclres *res)
029d105e 6401{
029d105e
BF
6402 struct compound_hdr hdr;
6403 int status;
6404
331818f1
TM
6405 if (res->acl_scratch != NULL) {
6406 void *p = page_address(res->acl_scratch);
6407 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6408 }
bf269551 6409 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6410 if (status)
6411 goto out;
bf269551 6412 status = decode_sequence(xdr, &res->seq_res, rqstp);
029d105e
BF
6413 if (status)
6414 goto out;
bf269551 6415 status = decode_putfh(xdr);
029d105e
BF
6416 if (status)
6417 goto out;
bf118a34 6418 status = decode_getacl(xdr, rqstp, res);
029d105e
BF
6419
6420out:
6421 return status;
6422}
6423
1da177e4
LT
6424/*
6425 * Decode CLOSE response
6426 */
bf269551
CL
6427static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6428 struct nfs_closeres *res)
1da177e4 6429{
05d564fe
AA
6430 struct compound_hdr hdr;
6431 int status;
6432
bf269551 6433 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6434 if (status)
6435 goto out;
bf269551 6436 status = decode_sequence(xdr, &res->seq_res, rqstp);
05d564fe
AA
6437 if (status)
6438 goto out;
bf269551 6439 status = decode_putfh(xdr);
05d564fe
AA
6440 if (status)
6441 goto out;
bf269551 6442 status = decode_close(xdr, res);
516a6af6
TM
6443 if (status != 0)
6444 goto out;
6445 /*
6446 * Note: Server may do delete on close for this file
6447 * in which case the getattr call will fail with
6448 * an ESTALE error. Shouldn't be a problem,
6449 * though, since fattr->valid will remain unset.
6450 */
6926afd1 6451 decode_getfattr(xdr, res->fattr, res->server);
1da177e4 6452out:
05d564fe 6453 return status;
1da177e4
LT
6454}
6455
6456/*
6457 * Decode OPEN response
6458 */
bf269551
CL
6459static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6460 struct nfs_openres *res)
1da177e4 6461{
05d564fe
AA
6462 struct compound_hdr hdr;
6463 int status;
6464
bf269551 6465 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6466 if (status)
6467 goto out;
bf269551 6468 status = decode_sequence(xdr, &res->seq_res, rqstp);
05d564fe
AA
6469 if (status)
6470 goto out;
bf269551 6471 status = decode_putfh(xdr);
05d564fe
AA
6472 if (status)
6473 goto out;
bf269551 6474 status = decode_open(xdr, res);
56ae19f3
TM
6475 if (status)
6476 goto out;
01913b49
WAA
6477 status = decode_getfh(xdr, &res->fh);
6478 if (status)
1da177e4 6479 goto out;
ae2bb032
WAA
6480 if (res->access_request)
6481 decode_access(xdr, &res->access_supported, &res->access_result);
aa9c2669 6482 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
1da177e4 6483out:
05d564fe 6484 return status;
1da177e4
LT
6485}
6486
6487/*
6488 * Decode OPEN_CONFIRM response
6489 */
bf269551
CL
6490static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6491 struct xdr_stream *xdr,
6492 struct nfs_open_confirmres *res)
1da177e4 6493{
05d564fe
AA
6494 struct compound_hdr hdr;
6495 int status;
6496
bf269551 6497 status = decode_compound_hdr(xdr, &hdr);
05d564fe
AA
6498 if (status)
6499 goto out;
bf269551 6500 status = decode_putfh(xdr);
05d564fe
AA
6501 if (status)
6502 goto out;
bf269551 6503 status = decode_open_confirm(xdr, res);
1da177e4 6504out:
05d564fe 6505 return status;
1da177e4
LT
6506}
6507
6508/*
6509 * Decode OPEN response
6510 */
bf269551
CL
6511static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6512 struct xdr_stream *xdr,
6513 struct nfs_openres *res)
1da177e4 6514{
05d564fe
AA
6515 struct compound_hdr hdr;
6516 int status;
6517
bf269551 6518 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6519 if (status)
6520 goto out;
bf269551 6521 status = decode_sequence(xdr, &res->seq_res, rqstp);
05d564fe
AA
6522 if (status)
6523 goto out;
bf269551 6524 status = decode_putfh(xdr);
05d564fe
AA
6525 if (status)
6526 goto out;
bf269551 6527 status = decode_open(xdr, res);
05d564fe
AA
6528 if (status)
6529 goto out;
ae2bb032
WAA
6530 if (res->access_request)
6531 decode_access(xdr, &res->access_supported, &res->access_result);
6926afd1 6532 decode_getfattr(xdr, res->f_attr, res->server);
1da177e4 6533out:
05d564fe 6534 return status;
1da177e4
LT
6535}
6536
6537/*
6538 * Decode SETATTR response
6539 */
bf269551
CL
6540static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6541 struct xdr_stream *xdr,
6542 struct nfs_setattrres *res)
1da177e4 6543{
05d564fe
AA
6544 struct compound_hdr hdr;
6545 int status;
6546
bf269551 6547 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6548 if (status)
6549 goto out;
bf269551 6550 status = decode_sequence(xdr, &res->seq_res, rqstp);
05d564fe
AA
6551 if (status)
6552 goto out;
bf269551 6553 status = decode_putfh(xdr);
05d564fe
AA
6554 if (status)
6555 goto out;
bf269551 6556 status = decode_setattr(xdr);
05d564fe
AA
6557 if (status)
6558 goto out;
aa9c2669 6559 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
1da177e4 6560out:
05d564fe 6561 return status;
1da177e4
LT
6562}
6563
6564/*
6565 * Decode LOCK response
6566 */
bf269551
CL
6567static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6568 struct nfs_lock_res *res)
1da177e4 6569{
1da177e4
LT
6570 struct compound_hdr hdr;
6571 int status;
6572
bf269551 6573 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6574 if (status)
6575 goto out;
bf269551 6576 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6577 if (status)
6578 goto out;
bf269551 6579 status = decode_putfh(xdr);
1da177e4
LT
6580 if (status)
6581 goto out;
bf269551 6582 status = decode_lock(xdr, res);
1da177e4
LT
6583out:
6584 return status;
6585}
6586
6587/*
6588 * Decode LOCKT response
6589 */
bf269551
CL
6590static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6591 struct nfs_lockt_res *res)
1da177e4 6592{
1da177e4
LT
6593 struct compound_hdr hdr;
6594 int status;
6595
bf269551 6596 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6597 if (status)
6598 goto out;
bf269551 6599 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6600 if (status)
6601 goto out;
bf269551 6602 status = decode_putfh(xdr);
1da177e4
LT
6603 if (status)
6604 goto out;
bf269551 6605 status = decode_lockt(xdr, res);
1da177e4
LT
6606out:
6607 return status;
6608}
6609
6610/*
6611 * Decode LOCKU response
6612 */
bf269551
CL
6613static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6614 struct nfs_locku_res *res)
1da177e4 6615{
1da177e4
LT
6616 struct compound_hdr hdr;
6617 int status;
6618
bf269551 6619 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6620 if (status)
6621 goto out;
bf269551 6622 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6623 if (status)
6624 goto out;
bf269551 6625 status = decode_putfh(xdr);
1da177e4
LT
6626 if (status)
6627 goto out;
bf269551 6628 status = decode_locku(xdr, res);
1da177e4
LT
6629out:
6630 return status;
6631}
6632
bf269551
CL
6633static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6634 struct xdr_stream *xdr, void *dummy)
d3c7b7cc 6635{
d3c7b7cc
TM
6636 struct compound_hdr hdr;
6637 int status;
6638
bf269551 6639 status = decode_compound_hdr(xdr, &hdr);
d3c7b7cc 6640 if (!status)
bf269551 6641 status = decode_release_lockowner(xdr);
d3c7b7cc
TM
6642 return status;
6643}
6644
1da177e4
LT
6645/*
6646 * Decode READLINK response
6647 */
bf269551
CL
6648static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6649 struct xdr_stream *xdr,
f50c7000 6650 struct nfs4_readlink_res *res)
1da177e4 6651{
1da177e4
LT
6652 struct compound_hdr hdr;
6653 int status;
6654
bf269551 6655 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6656 if (status)
6657 goto out;
bf269551 6658 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6659 if (status)
6660 goto out;
bf269551 6661 status = decode_putfh(xdr);
1da177e4
LT
6662 if (status)
6663 goto out;
bf269551 6664 status = decode_readlink(xdr, rqstp);
1da177e4
LT
6665out:
6666 return status;
6667}
6668
6669/*
6670 * Decode READDIR response
6671 */
bf269551
CL
6672static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6673 struct nfs4_readdir_res *res)
1da177e4 6674{
1da177e4
LT
6675 struct compound_hdr hdr;
6676 int status;
6677
bf269551 6678 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6679 if (status)
6680 goto out;
bf269551 6681 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6682 if (status)
6683 goto out;
bf269551 6684 status = decode_putfh(xdr);
1da177e4
LT
6685 if (status)
6686 goto out;
bf269551 6687 status = decode_readdir(xdr, rqstp, res);
1da177e4
LT
6688out:
6689 return status;
6690}
6691
6692/*
6693 * Decode Read response
6694 */
bf269551 6695static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
9137bdf3 6696 struct nfs_pgio_res *res)
1da177e4 6697{
1da177e4
LT
6698 struct compound_hdr hdr;
6699 int status;
6700
bf269551 6701 status = decode_compound_hdr(xdr, &hdr);
aabff4dd 6702 res->op_status = hdr.status;
9b7b9fcc
AA
6703 if (status)
6704 goto out;
bf269551 6705 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6706 if (status)
6707 goto out;
bf269551 6708 status = decode_putfh(xdr);
1da177e4
LT
6709 if (status)
6710 goto out;
bf269551 6711 status = decode_read(xdr, rqstp, res);
1da177e4
LT
6712 if (!status)
6713 status = res->count;
6714out:
6715 return status;
6716}
6717
6718/*
6719 * Decode WRITE response
6720 */
bf269551 6721static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
9137bdf3 6722 struct nfs_pgio_res *res)
1da177e4 6723{
1da177e4
LT
6724 struct compound_hdr hdr;
6725 int status;
6726
bf269551 6727 status = decode_compound_hdr(xdr, &hdr);
aabff4dd 6728 res->op_status = hdr.status;
9b7b9fcc
AA
6729 if (status)
6730 goto out;
bf269551 6731 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6732 if (status)
6733 goto out;
bf269551 6734 status = decode_putfh(xdr);
1da177e4
LT
6735 if (status)
6736 goto out;
bf269551 6737 status = decode_write(xdr, res);
4f9838c7
TM
6738 if (status)
6739 goto out;
7ffd1064 6740 if (res->fattr)
6926afd1 6741 decode_getfattr(xdr, res->fattr, res->server);
1da177e4
LT
6742 if (!status)
6743 status = res->count;
6744out:
6745 return status;
6746}
6747
6748/*
6749 * Decode COMMIT response
6750 */
bf269551 6751static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
0b7c0153 6752 struct nfs_commitres *res)
1da177e4 6753{
1da177e4
LT
6754 struct compound_hdr hdr;
6755 int status;
6756
bf269551 6757 status = decode_compound_hdr(xdr, &hdr);
aabff4dd 6758 res->op_status = hdr.status;
9b7b9fcc
AA
6759 if (status)
6760 goto out;
bf269551 6761 status = decode_sequence(xdr, &res->seq_res, rqstp);
1da177e4
LT
6762 if (status)
6763 goto out;
bf269551 6764 status = decode_putfh(xdr);
1da177e4
LT
6765 if (status)
6766 goto out;
bf269551 6767 status = decode_commit(xdr, res);
1da177e4
LT
6768out:
6769 return status;
6770}
6771
6772/*
8b173218 6773 * Decode FSINFO response
1da177e4 6774 */
bf269551 6775static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
3dda5e43 6776 struct nfs4_fsinfo_res *res)
1da177e4 6777{
1da177e4
LT
6778 struct compound_hdr hdr;
6779 int status;
6780
bf269551 6781 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc 6782 if (!status)
bf269551 6783 status = decode_sequence(xdr, &res->seq_res, req);
1da177e4 6784 if (!status)
bf269551 6785 status = decode_putfh(xdr);
1da177e4 6786 if (!status)
bf269551 6787 status = decode_fsinfo(xdr, res->fsinfo);
1da177e4
LT
6788 return status;
6789}
6790
6791/*
8b173218 6792 * Decode PATHCONF response
1da177e4 6793 */
bf269551 6794static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
d45b2989 6795 struct nfs4_pathconf_res *res)
1da177e4 6796{
1da177e4
LT
6797 struct compound_hdr hdr;
6798 int status;
6799
bf269551 6800 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc 6801 if (!status)
bf269551 6802 status = decode_sequence(xdr, &res->seq_res, req);
1da177e4 6803 if (!status)
bf269551 6804 status = decode_putfh(xdr);
1da177e4 6805 if (!status)
bf269551 6806 status = decode_pathconf(xdr, res->pathconf);
1da177e4
LT
6807 return status;
6808}
6809
6810/*
8b173218 6811 * Decode STATFS response
1da177e4 6812 */
bf269551 6813static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
24ad148a 6814 struct nfs4_statfs_res *res)
1da177e4 6815{
1da177e4
LT
6816 struct compound_hdr hdr;
6817 int status;
6818
bf269551 6819 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc 6820 if (!status)
bf269551 6821 status = decode_sequence(xdr, &res->seq_res, req);
1da177e4 6822 if (!status)
bf269551 6823 status = decode_putfh(xdr);
1da177e4 6824 if (!status)
bf269551 6825 status = decode_statfs(xdr, res->fsstat);
1da177e4
LT
6826 return status;
6827}
6828
6829/*
8b173218 6830 * Decode GETATTR_BITMAP response
1da177e4 6831 */
bf269551
CL
6832static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6833 struct xdr_stream *xdr,
6834 struct nfs4_server_caps_res *res)
1da177e4 6835{
1da177e4
LT
6836 struct compound_hdr hdr;
6837 int status;
6838
bf269551 6839 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6840 if (status)
6841 goto out;
bf269551 6842 status = decode_sequence(xdr, &res->seq_res, req);
9b7b9fcc 6843 if (status)
1da177e4 6844 goto out;
bf269551
CL
6845 status = decode_putfh(xdr);
6846 if (status)
1da177e4 6847 goto out;
bf269551 6848 status = decode_server_caps(xdr, res);
1da177e4
LT
6849out:
6850 return status;
6851}
6852
6853/*
6854 * Decode RENEW response
6855 */
bf269551
CL
6856static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6857 void *__unused)
1da177e4 6858{
1da177e4
LT
6859 struct compound_hdr hdr;
6860 int status;
6861
bf269551 6862 status = decode_compound_hdr(xdr, &hdr);
1da177e4 6863 if (!status)
bf269551 6864 status = decode_renew(xdr);
1da177e4
LT
6865 return status;
6866}
6867
6868/*
8b173218 6869 * Decode SETCLIENTID response
1da177e4 6870 */
bf269551
CL
6871static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6872 struct xdr_stream *xdr,
6873 struct nfs4_setclientid_res *res)
1da177e4 6874{
1da177e4
LT
6875 struct compound_hdr hdr;
6876 int status;
6877
bf269551 6878 status = decode_compound_hdr(xdr, &hdr);
1da177e4 6879 if (!status)
bf269551 6880 status = decode_setclientid(xdr, res);
1da177e4
LT
6881 return status;
6882}
6883
6884/*
8b173218 6885 * Decode SETCLIENTID_CONFIRM response
1da177e4 6886 */
bf269551 6887static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
83ca7f5a 6888 struct xdr_stream *xdr)
1da177e4 6889{
1da177e4
LT
6890 struct compound_hdr hdr;
6891 int status;
6892
bf269551 6893 status = decode_compound_hdr(xdr, &hdr);
1da177e4 6894 if (!status)
bf269551 6895 status = decode_setclientid_confirm(xdr);
1da177e4
LT
6896 return status;
6897}
6898
6899/*
8b173218 6900 * Decode DELEGRETURN response
1da177e4 6901 */
bf269551
CL
6902static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6903 struct xdr_stream *xdr,
6904 struct nfs4_delegreturnres *res)
1da177e4 6905{
1da177e4
LT
6906 struct compound_hdr hdr;
6907 int status;
6908
bf269551 6909 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6910 if (status)
6911 goto out;
bf269551 6912 status = decode_sequence(xdr, &res->seq_res, rqstp);
9b7b9fcc 6913 if (status)
fa178f29 6914 goto out;
bf269551 6915 status = decode_putfh(xdr);
fa178f29
TM
6916 if (status != 0)
6917 goto out;
e144cbcc 6918 status = decode_getfattr(xdr, res->fattr, res->server);
556ae3bb
JL
6919 if (status != 0)
6920 goto out;
e144cbcc 6921 status = decode_delegreturn(xdr);
fa178f29 6922out:
1da177e4
LT
6923 return status;
6924}
6925
683b57b4 6926/*
8b173218 6927 * Decode FS_LOCATIONS response
683b57b4 6928 */
bf269551
CL
6929static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6930 struct xdr_stream *xdr,
22958463 6931 struct nfs4_fs_locations_res *res)
683b57b4 6932{
683b57b4
TM
6933 struct compound_hdr hdr;
6934 int status;
6935
bf269551 6936 status = decode_compound_hdr(xdr, &hdr);
9b7b9fcc
AA
6937 if (status)
6938 goto out;
bf269551 6939 status = decode_sequence(xdr, &res->seq_res, req);
9b7b9fcc 6940 if (status)
683b57b4 6941 goto out;
bf269551
CL
6942 status = decode_putfh(xdr);
6943 if (status)
683b57b4 6944 goto out;
b03d735b
CL
6945 if (res->migration) {
6946 xdr_enter_page(xdr, PAGE_SIZE);
6947 status = decode_getfattr_generic(xdr,
6948 &res->fs_locations->fattr,
8b7e3f49 6949 NULL, res->fs_locations,
aa9c2669 6950 NULL, res->fs_locations->server);
b03d735b
CL
6951 if (status)
6952 goto out;
6953 if (res->renew)
6954 status = decode_renew(xdr);
6955 } else {
6956 status = decode_lookup(xdr);
6957 if (status)
6958 goto out;
6959 xdr_enter_page(xdr, PAGE_SIZE);
6960 status = decode_getfattr_generic(xdr,
6961 &res->fs_locations->fattr,
6962 NULL, res->fs_locations,
6963 NULL, res->fs_locations->server);
6964 }
683b57b4
TM
6965out:
6966 return status;
6967}
6968
5a5ea0d4
BS
6969/*
6970 * Decode SECINFO response
6971 */
6972static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6973 struct xdr_stream *xdr,
6974 struct nfs4_secinfo_res *res)
6975{
6976 struct compound_hdr hdr;
6977 int status;
6978
6979 status = decode_compound_hdr(xdr, &hdr);
6980 if (status)
6981 goto out;
6982 status = decode_sequence(xdr, &res->seq_res, rqstp);
6983 if (status)
6984 goto out;
6985 status = decode_putfh(xdr);
6986 if (status)
6987 goto out;
6988 status = decode_secinfo(xdr, res);
5a5ea0d4
BS
6989out:
6990 return status;
6991}
6992
44c99933
CL
6993/*
6994 * Decode FSID_PRESENT response
6995 */
6996static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6997 struct xdr_stream *xdr,
6998 struct nfs4_fsid_present_res *res)
6999{
7000 struct compound_hdr hdr;
7001 int status;
7002
7003 status = decode_compound_hdr(xdr, &hdr);
7004 if (status)
7005 goto out;
7006 status = decode_sequence(xdr, &res->seq_res, rqstp);
7007 if (status)
7008 goto out;
7009 status = decode_putfh(xdr);
7010 if (status)
7011 goto out;
7012 status = decode_getfh(xdr, res->fh);
7013 if (status)
7014 goto out;
7015 if (res->renew)
7016 status = decode_renew(xdr);
7017out:
7018 return status;
7019}
7020
99fe60d0 7021#if defined(CONFIG_NFS_V4_1)
7c44f1ae
WAA
7022/*
7023 * Decode BIND_CONN_TO_SESSION response
7024 */
7025static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7026 struct xdr_stream *xdr,
7027 void *res)
7028{
7029 struct compound_hdr hdr;
7030 int status;
7031
7032 status = decode_compound_hdr(xdr, &hdr);
7033 if (!status)
7034 status = decode_bind_conn_to_session(xdr, res);
7035 return status;
7036}
7037
99fe60d0 7038/*
8b173218 7039 * Decode EXCHANGE_ID response
99fe60d0 7040 */
bf269551
CL
7041static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7042 struct xdr_stream *xdr,
99fe60d0
BH
7043 void *res)
7044{
99fe60d0
BH
7045 struct compound_hdr hdr;
7046 int status;
7047
bf269551 7048 status = decode_compound_hdr(xdr, &hdr);
99fe60d0 7049 if (!status)
bf269551 7050 status = decode_exchange_id(xdr, res);
99fe60d0
BH
7051 return status;
7052}
2050f0cc 7053
fc931582 7054/*
8b173218 7055 * Decode CREATE_SESSION response
fc931582 7056 */
bf269551
CL
7057static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7058 struct xdr_stream *xdr,
fc931582
AA
7059 struct nfs41_create_session_res *res)
7060{
fc931582
AA
7061 struct compound_hdr hdr;
7062 int status;
7063
bf269551 7064 status = decode_compound_hdr(xdr, &hdr);
fc931582 7065 if (!status)
bf269551 7066 status = decode_create_session(xdr, res);
fc931582
AA
7067 return status;
7068}
7069
0f3e66c6 7070/*
8b173218 7071 * Decode DESTROY_SESSION response
0f3e66c6 7072 */
bf269551
CL
7073static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7074 struct xdr_stream *xdr,
7075 void *res)
0f3e66c6 7076{
0f3e66c6
AA
7077 struct compound_hdr hdr;
7078 int status;
7079
bf269551 7080 status = decode_compound_hdr(xdr, &hdr);
0f3e66c6 7081 if (!status)
bf269551 7082 status = decode_destroy_session(xdr, res);
0f3e66c6
AA
7083 return status;
7084}
7085
66245539
TM
7086/*
7087 * Decode DESTROY_CLIENTID response
7088 */
7089static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7090 struct xdr_stream *xdr,
7091 void *res)
7092{
7093 struct compound_hdr hdr;
7094 int status;
7095
7096 status = decode_compound_hdr(xdr, &hdr);
7097 if (!status)
7098 status = decode_destroy_clientid(xdr, res);
7099 return status;
7100}
7101
fc01cea9 7102/*
8b173218 7103 * Decode SEQUENCE response
fc01cea9 7104 */
bf269551
CL
7105static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7106 struct xdr_stream *xdr,
fc01cea9
AA
7107 struct nfs4_sequence_res *res)
7108{
fc01cea9
AA
7109 struct compound_hdr hdr;
7110 int status;
7111
bf269551 7112 status = decode_compound_hdr(xdr, &hdr);
fc01cea9 7113 if (!status)
bf269551 7114 status = decode_sequence(xdr, res, rqstp);
fc01cea9
AA
7115 return status;
7116}
7117
2050f0cc 7118/*
8b173218 7119 * Decode GET_LEASE_TIME response
2050f0cc 7120 */
bf269551
CL
7121static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7122 struct xdr_stream *xdr,
2050f0cc
AA
7123 struct nfs4_get_lease_time_res *res)
7124{
2050f0cc
AA
7125 struct compound_hdr hdr;
7126 int status;
7127
bf269551 7128 status = decode_compound_hdr(xdr, &hdr);
2050f0cc 7129 if (!status)
bf269551 7130 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
2050f0cc 7131 if (!status)
bf269551 7132 status = decode_putrootfh(xdr);
2050f0cc 7133 if (!status)
bf269551 7134 status = decode_fsinfo(xdr, res->lr_fsinfo);
2050f0cc
AA
7135 return status;
7136}
18019753
RL
7137
7138/*
7139 * Decode RECLAIM_COMPLETE response
7140 */
bf269551
CL
7141static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7142 struct xdr_stream *xdr,
18019753
RL
7143 struct nfs41_reclaim_complete_res *res)
7144{
18019753
RL
7145 struct compound_hdr hdr;
7146 int status;
7147
bf269551 7148 status = decode_compound_hdr(xdr, &hdr);
18019753 7149 if (!status)
bf269551 7150 status = decode_sequence(xdr, &res->seq_res, rqstp);
18019753 7151 if (!status)
8ee2b78a 7152 status = decode_reclaim_complete(xdr, NULL);
18019753
RL
7153 return status;
7154}
b1f69b75
AA
7155
7156/*
7157 * Decode GETDEVINFO response
7158 */
bf269551
CL
7159static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7160 struct xdr_stream *xdr,
b1f69b75
AA
7161 struct nfs4_getdeviceinfo_res *res)
7162{
b1f69b75
AA
7163 struct compound_hdr hdr;
7164 int status;
7165
bf269551 7166 status = decode_compound_hdr(xdr, &hdr);
b1f69b75
AA
7167 if (status != 0)
7168 goto out;
bf269551 7169 status = decode_sequence(xdr, &res->seq_res, rqstp);
b1f69b75
AA
7170 if (status != 0)
7171 goto out;
4e590803 7172 status = decode_getdeviceinfo(xdr, res);
b1f69b75
AA
7173out:
7174 return status;
7175}
7176
7177/*
7178 * Decode LAYOUTGET response
7179 */
bf269551
CL
7180static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7181 struct xdr_stream *xdr,
b1f69b75
AA
7182 struct nfs4_layoutget_res *res)
7183{
b1f69b75
AA
7184 struct compound_hdr hdr;
7185 int status;
7186
bf269551 7187 status = decode_compound_hdr(xdr, &hdr);
b1f69b75
AA
7188 if (status)
7189 goto out;
bf269551 7190 status = decode_sequence(xdr, &res->seq_res, rqstp);
b1f69b75
AA
7191 if (status)
7192 goto out;
bf269551 7193 status = decode_putfh(xdr);
b1f69b75
AA
7194 if (status)
7195 goto out;
bf269551 7196 status = decode_layoutget(xdr, rqstp, res);
b1f69b75
AA
7197out:
7198 return status;
7199}
863a3c6c 7200
cbe82603
BH
7201/*
7202 * Decode LAYOUTRETURN response
7203 */
7204static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7205 struct xdr_stream *xdr,
7206 struct nfs4_layoutreturn_res *res)
7207{
7208 struct compound_hdr hdr;
7209 int status;
7210
7211 status = decode_compound_hdr(xdr, &hdr);
7212 if (status)
7213 goto out;
7214 status = decode_sequence(xdr, &res->seq_res, rqstp);
7215 if (status)
7216 goto out;
7217 status = decode_putfh(xdr);
7218 if (status)
7219 goto out;
7220 status = decode_layoutreturn(xdr, res);
7221out:
7222 return status;
7223}
7224
863a3c6c
AA
7225/*
7226 * Decode LAYOUTCOMMIT response
7227 */
7228static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7229 struct xdr_stream *xdr,
7230 struct nfs4_layoutcommit_res *res)
7231{
7232 struct compound_hdr hdr;
7233 int status;
7234
7235 status = decode_compound_hdr(xdr, &hdr);
7236 if (status)
7237 goto out;
7238 status = decode_sequence(xdr, &res->seq_res, rqstp);
7239 if (status)
7240 goto out;
7241 status = decode_putfh(xdr);
7242 if (status)
7243 goto out;
7244 status = decode_layoutcommit(xdr, rqstp, res);
7245 if (status)
7246 goto out;
6926afd1 7247 decode_getfattr(xdr, res->fattr, res->server);
863a3c6c
AA
7248out:
7249 return status;
7250}
fca78d6d
BS
7251
7252/*
7253 * Decode SECINFO_NO_NAME response
7254 */
7255static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7256 struct xdr_stream *xdr,
7257 struct nfs4_secinfo_res *res)
7258{
7259 struct compound_hdr hdr;
7260 int status;
7261
7262 status = decode_compound_hdr(xdr, &hdr);
7263 if (status)
7264 goto out;
7265 status = decode_sequence(xdr, &res->seq_res, rqstp);
7266 if (status)
7267 goto out;
7268 status = decode_putrootfh(xdr);
7269 if (status)
7270 goto out;
31e4dda4 7271 status = decode_secinfo_no_name(xdr, res);
fca78d6d
BS
7272out:
7273 return status;
7274}
7d974794
BS
7275
7276/*
7277 * Decode TEST_STATEID response
7278 */
7279static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7280 struct xdr_stream *xdr,
7281 struct nfs41_test_stateid_res *res)
7282{
7283 struct compound_hdr hdr;
7284 int status;
7285
7286 status = decode_compound_hdr(xdr, &hdr);
7287 if (status)
7288 goto out;
7289 status = decode_sequence(xdr, &res->seq_res, rqstp);
7290 if (status)
7291 goto out;
7292 status = decode_test_stateid(xdr, res);
7293out:
7294 return status;
7295}
9aeda35f
BS
7296
7297/*
7298 * Decode FREE_STATEID response
7299 */
7300static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7301 struct xdr_stream *xdr,
7302 struct nfs41_free_stateid_res *res)
7303{
7304 struct compound_hdr hdr;
7305 int status;
7306
7307 status = decode_compound_hdr(xdr, &hdr);
7308 if (status)
7309 goto out;
7310 status = decode_sequence(xdr, &res->seq_res, rqstp);
7311 if (status)
7312 goto out;
7313 status = decode_free_stateid(xdr, res);
7314out:
7315 return status;
7316}
99fe60d0
BH
7317#endif /* CONFIG_NFS_V4_1 */
7318
573c4e1e
CL
7319/**
7320 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7321 * the local page cache.
7322 * @xdr: XDR stream where entry resides
7323 * @entry: buffer to fill in with entry data
7324 * @plus: boolean indicating whether this should be a readdirplus entry
7325 *
7326 * Returns zero if successful, otherwise a negative errno value is
7327 * returned.
7328 *
7329 * This function is not invoked during READDIR reply decoding, but
7330 * rather whenever an application invokes the getdents(2) system call
7331 * on a directory already in our cache.
7332 */
7333int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7334 int plus)
1da177e4 7335{
256e48bb 7336 unsigned int savep;
dae100c2 7337 uint32_t bitmap[3] = {0};
1da177e4 7338 uint32_t len;
babddc72
BS
7339 __be32 *p = xdr_inline_decode(xdr, 4);
7340 if (unlikely(!p))
7341 goto out_overflow;
c08e76d0 7342 if (*p == xdr_zero) {
babddc72
BS
7343 p = xdr_inline_decode(xdr, 4);
7344 if (unlikely(!p))
7345 goto out_overflow;
c08e76d0 7346 if (*p == xdr_zero)
573c4e1e 7347 return -EAGAIN;
1da177e4 7348 entry->eof = 1;
573c4e1e 7349 return -EBADCOOKIE;
1da177e4
LT
7350 }
7351
babddc72
BS
7352 p = xdr_inline_decode(xdr, 12);
7353 if (unlikely(!p))
7354 goto out_overflow;
1da177e4
LT
7355 entry->prev_cookie = entry->cookie;
7356 p = xdr_decode_hyper(p, &entry->cookie);
c08e76d0 7357 entry->len = be32_to_cpup(p);
babddc72 7358
9af8c222 7359 p = xdr_inline_decode(xdr, entry->len);
babddc72
BS
7360 if (unlikely(!p))
7361 goto out_overflow;
1da177e4 7362 entry->name = (const char *) p;
1da177e4
LT
7363
7364 /*
7365 * In case the server doesn't return an inode number,
7366 * we fake one here. (We don't use inode number 0,
7367 * since glibc seems to choke on it...)
7368 */
7369 entry->ino = 1;
4f082222 7370 entry->fattr->valid = 0;
1da177e4 7371
9af8c222
TM
7372 if (decode_attr_bitmap(xdr, bitmap) < 0)
7373 goto out_overflow;
7374
256e48bb 7375 if (decode_attr_length(xdr, &len, &savep) < 0)
9af8c222
TM
7376 goto out_overflow;
7377
573c4e1e 7378 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
aa9c2669 7379 NULL, entry->label, entry->server) < 0)
9af8c222 7380 goto out_overflow;
28331a46
TM
7381 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7382 entry->ino = entry->fattr->mounted_on_fileid;
7383 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
9af8c222
TM
7384 entry->ino = entry->fattr->fileid;
7385
0b26a0bf
TM
7386 entry->d_type = DT_UNKNOWN;
7387 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7388 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7389
573c4e1e 7390 return 0;
babddc72
BS
7391
7392out_overflow:
7393 print_overflow_msg(__func__, xdr);
573c4e1e 7394 return -EAGAIN;
1da177e4
LT
7395}
7396
7397/*
7398 * We need to translate between nfs status return values and
7399 * the local errno values which may not be the same.
7400 */
7401static struct {
7402 int stat;
7403 int errno;
7404} nfs_errtbl[] = {
7405 { NFS4_OK, 0 },
856dff3d
BH
7406 { NFS4ERR_PERM, -EPERM },
7407 { NFS4ERR_NOENT, -ENOENT },
7408 { NFS4ERR_IO, -errno_NFSERR_IO},
7409 { NFS4ERR_NXIO, -ENXIO },
7410 { NFS4ERR_ACCESS, -EACCES },
7411 { NFS4ERR_EXIST, -EEXIST },
7412 { NFS4ERR_XDEV, -EXDEV },
7413 { NFS4ERR_NOTDIR, -ENOTDIR },
7414 { NFS4ERR_ISDIR, -EISDIR },
7415 { NFS4ERR_INVAL, -EINVAL },
7416 { NFS4ERR_FBIG, -EFBIG },
7417 { NFS4ERR_NOSPC, -ENOSPC },
7418 { NFS4ERR_ROFS, -EROFS },
7419 { NFS4ERR_MLINK, -EMLINK },
7420 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7421 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7422 { NFS4ERR_DQUOT, -EDQUOT },
7423 { NFS4ERR_STALE, -ESTALE },
7424 { NFS4ERR_BADHANDLE, -EBADHANDLE },
856dff3d
BH
7425 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7426 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7427 { NFS4ERR_TOOSMALL, -ETOOSMALL },
fdcb4577 7428 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
856dff3d
BH
7429 { NFS4ERR_BADTYPE, -EBADTYPE },
7430 { NFS4ERR_LOCKED, -EAGAIN },
856dff3d
BH
7431 { NFS4ERR_SYMLINK, -ELOOP },
7432 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7433 { NFS4ERR_DEADLOCK, -EDEADLK },
856dff3d 7434 { -1, -EIO }
1da177e4
LT
7435};
7436
7437/*
7438 * Convert an NFS error code to a local one.
7439 * This one is used jointly by NFSv2 and NFSv3.
7440 */
7441static int
0a8ea437 7442nfs4_stat_to_errno(int stat)
1da177e4
LT
7443{
7444 int i;
7445 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7446 if (nfs_errtbl[i].stat == stat)
7447 return nfs_errtbl[i].errno;
7448 }
7449 if (stat <= 10000 || stat > 10100) {
7450 /* The server is looney tunes. */
fdcb4577 7451 return -EREMOTEIO;
1da177e4
LT
7452 }
7453 /* If we cannot translate the error, the recovery routines should
7454 * handle it.
7455 * Note: remaining NFSv4 error codes have values > 10000, so should
7456 * not conflict with native Linux error codes.
7457 */
856dff3d 7458 return -stat;
1da177e4
LT
7459}
7460
1c6dcbe5
AS
7461#ifdef CONFIG_NFS_V4_2
7462#include "nfs42xdr.c"
7463#endif /* CONFIG_NFS_V4_2 */
7464
1da177e4
LT
7465#define PROC(proc, argtype, restype) \
7466[NFSPROC4_CLNT_##proc] = { \
7467 .p_proc = NFSPROC4_COMPOUND, \
9f06c719 7468 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
bf269551 7469 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
2bea90d4
CL
7470 .p_arglen = NFS4_##argtype##_sz, \
7471 .p_replen = NFS4_##restype##_sz, \
cc0175c1
CL
7472 .p_statidx = NFSPROC4_CLNT_##proc, \
7473 .p_name = #proc, \
05d564fe 7474}
1da177e4 7475
7c61f0d3
AS
7476#define STUB(proc) \
7477[NFSPROC4_CLNT_##proc] = { \
7478 .p_name = #proc, \
7479}
7480
1da177e4 7481struct rpc_procinfo nfs4_procedures[] = {
7d93bd71
CL
7482 PROC(READ, enc_read, dec_read),
7483 PROC(WRITE, enc_write, dec_write),
7484 PROC(COMMIT, enc_commit, dec_commit),
7485 PROC(OPEN, enc_open, dec_open),
7486 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7487 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7488 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7489 PROC(CLOSE, enc_close, dec_close),
7490 PROC(SETATTR, enc_setattr, dec_setattr),
7491 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7492 PROC(RENEW, enc_renew, dec_renew),
7493 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7494 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7495 PROC(LOCK, enc_lock, dec_lock),
7496 PROC(LOCKT, enc_lockt, dec_lockt),
7497 PROC(LOCKU, enc_locku, dec_locku),
7498 PROC(ACCESS, enc_access, dec_access),
7499 PROC(GETATTR, enc_getattr, dec_getattr),
7500 PROC(LOOKUP, enc_lookup, dec_lookup),
7501 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7502 PROC(REMOVE, enc_remove, dec_remove),
7503 PROC(RENAME, enc_rename, dec_rename),
7504 PROC(LINK, enc_link, dec_link),
7505 PROC(SYMLINK, enc_symlink, dec_symlink),
7506 PROC(CREATE, enc_create, dec_create),
7507 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7508 PROC(STATFS, enc_statfs, dec_statfs),
7509 PROC(READLINK, enc_readlink, dec_readlink),
7510 PROC(READDIR, enc_readdir, dec_readdir),
7511 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7512 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7513 PROC(GETACL, enc_getacl, dec_getacl),
7514 PROC(SETACL, enc_setacl, dec_setacl),
7515 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7516 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
5a5ea0d4 7517 PROC(SECINFO, enc_secinfo, dec_secinfo),
44c99933 7518 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
99fe60d0 7519#if defined(CONFIG_NFS_V4_1)
7d93bd71
CL
7520 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7521 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7522 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7523 PROC(SEQUENCE, enc_sequence, dec_sequence),
7524 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7525 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7526 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7527 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
863a3c6c 7528 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
cbe82603 7529 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
fca78d6d 7530 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7d974794 7531 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
9aeda35f 7532 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7c61f0d3 7533 STUB(GETDEVICELIST),
ad24ecfb
TM
7534 PROC(BIND_CONN_TO_SESSION,
7535 enc_bind_conn_to_session, dec_bind_conn_to_session),
66245539 7536 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
99fe60d0 7537#endif /* CONFIG_NFS_V4_1 */
1c6dcbe5
AS
7538#ifdef CONFIG_NFS_V4_2
7539 PROC(SEEK, enc_seek, dec_seek),
f4ac1674 7540 PROC(ALLOCATE, enc_allocate, dec_allocate),
624bd5b7 7541 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
be3a5d23 7542 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
36022770 7543 PROC(CLONE, enc_clone, dec_clone),
2e72448b 7544 PROC(COPY, enc_copy, dec_copy),
1c6dcbe5 7545#endif /* CONFIG_NFS_V4_2 */
1da177e4
LT
7546};
7547
a613fa16 7548const struct rpc_version nfs_version4 = {
1da177e4 7549 .number = 4,
e8c96f8c 7550 .nrprocs = ARRAY_SIZE(nfs4_procedures),
1da177e4
LT
7551 .procs = nfs4_procedures
7552};
7553
7554/*
7555 * Local variables:
7556 * c-basic-offset: 8
7557 * End:
7558 */