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