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