]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/nfs/nfs4xdr.c
nfs: nfs4xdr: get rid of WRITE32
[mirror_ubuntu-bionic-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>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h>
44#include <linux/string.h>
45#include <linux/in.h>
46#include <linux/pagemap.h>
47#include <linux/proc_fs.h>
48#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h>
50#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
4ce79717 54#include "nfs4_fs.h"
1da177e4
LT
55
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
0a8ea437 61static int nfs4_stat_to_errno(int);
1da177e4
LT
62
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
6c0195a4 70/* lock,open owner id:
9f958ab8 71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
1da177e4 72 */
9f958ab8
TM
73#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
9104a55d 75#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1da177e4
LT
76#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
9104a55d
TM
80#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
1da177e4
LT
84#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
96928206
BF
92#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1da177e4
LT
94#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
bd625ba8
TM
96#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
96928206
BF
98/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
bd625ba8 100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
96928206
BF
101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
9104a55d
TM
104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
1da177e4
LT
109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
56ae19f3
TM
111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
2f42b5d0 113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
1da177e4
LT
114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
cc38bac3
CL
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
1da177e4
LT
125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
e6889620
TM
134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
2cebf828
TM
136#define encode_share_access_maxsz \
137 (2)
9104a55d 138#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
2cebf828
TM
139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
9104a55d 147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
2cebf828
TM
148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
9104a55d 151 decode_stateid_maxsz + \
2cebf828
TM
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
9104a55d
TM
155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
1da177e4
LT
193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
6ce18391
BH
195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
1da177e4
LT
197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
6ce18391
BH
199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
1da177e4
LT
202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
6ce18391 204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
9104a55d
TM
205#define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 7 + \
207 1 + encode_stateid_maxsz + 8)
208#define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210#define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
217 4)
218#define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
1da177e4
LT
222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
94a6d753 224 1 + \
96928206 225 nfs4_fattr_maxsz)
1da177e4
LT
226#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227#define encode_create_maxsz (op_encode_hdr_maxsz + \
9104a55d
TM
228 1 + 2 + nfs4_name_maxsz + \
229 encode_attrs_maxsz)
2cebf828
TM
230#define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
9104a55d
TM
233#define encode_statfs_maxsz (encode_getattr_maxsz)
234#define decode_statfs_maxsz (decode_getattr_maxsz)
1da177e4
LT
235#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
9104a55d
TM
237#define encode_getacl_maxsz (encode_getattr_maxsz)
238#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242#define decode_setacl_maxsz (decode_setattr_maxsz)
e6889620
TM
243#define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245#define decode_fs_locations_maxsz \
246 (0)
9b7b9fcc
AA
247
248#if defined(CONFIG_NFS_V4_1)
fc931582
AA
249#define NFS4_MAX_MACHINE_NAME_LEN (64)
250
99fe60d0
BH
251#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252 encode_verifier_maxsz + \
253 1 /* co_ownerid.len */ + \
254 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
255 1 /* flags */ + \
256 1 /* spa_how */ + \
257 0 /* SP4_NONE (for now) */ + \
258 1 /* zero implemetation id array */)
259#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260 2 /* eir_clientid */ + \
261 1 /* eir_sequenceid */ + \
262 1 /* eir_flags */ + \
263 1 /* spr_how */ + \
264 0 /* SP4_NONE (for now) */ + \
265 2 /* eir_server_owner.so_minor_id */ + \
266 /* eir_server_owner.so_major_id<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 /* eir_server_scope<> */ \
269 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270 1 /* eir_server_impl_id array length */ + \
271 0 /* ignored eir_server_impl_id contents */)
fc931582
AA
272#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
273#define decode_channel_attrs_maxsz (6 + \
274 1 /* ca_rdma_ird.len */ + \
275 1 /* ca_rdma_ird */)
276#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
277 2 /* csa_clientid */ + \
278 1 /* csa_sequence */ + \
279 1 /* csa_flags */ + \
280 encode_channel_attrs_maxsz + \
281 encode_channel_attrs_maxsz + \
282 1 /* csa_cb_program */ + \
283 1 /* csa_sec_parms.len (1) */ + \
284 1 /* cb_secflavor (AUTH_SYS) */ + \
285 1 /* stamp */ + \
286 1 /* machinename.len */ + \
287 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
288 1 /* uid */ + \
289 1 /* gid */ + \
290 1 /* gids.len (0) */)
291#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
292 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293 1 /* csr_sequence */ + \
294 1 /* csr_flags */ + \
295 decode_channel_attrs_maxsz + \
296 decode_channel_attrs_maxsz)
0f3e66c6
AA
297#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
fc01cea9
AA
299#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
302 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
9b7b9fcc
AA
303#else /* CONFIG_NFS_V4_1 */
304#define encode_sequence_maxsz 0
305#define decode_sequence_maxsz 0
306#endif /* CONFIG_NFS_V4_1 */
307
1da177e4
LT
308#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
309#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
310#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 311 encode_sequence_maxsz + \
1da177e4 312 encode_putfh_maxsz + \
9104a55d 313 encode_read_maxsz)
1da177e4 314#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 315 decode_sequence_maxsz + \
1da177e4 316 decode_putfh_maxsz + \
9104a55d 317 decode_read_maxsz)
1da177e4 318#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 319 encode_sequence_maxsz + \
1da177e4 320 encode_putfh_maxsz + \
9104a55d 321 encode_readlink_maxsz)
1da177e4 322#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 323 decode_sequence_maxsz + \
1da177e4 324 decode_putfh_maxsz + \
9104a55d 325 decode_readlink_maxsz)
1da177e4 326#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 327 encode_sequence_maxsz + \
1da177e4 328 encode_putfh_maxsz + \
9104a55d 329 encode_readdir_maxsz)
1da177e4 330#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 331 decode_sequence_maxsz + \
1da177e4 332 decode_putfh_maxsz + \
9104a55d 333 decode_readdir_maxsz)
1da177e4 334#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 335 encode_sequence_maxsz + \
1da177e4 336 encode_putfh_maxsz + \
9104a55d 337 encode_write_maxsz + \
4f9838c7 338 encode_getattr_maxsz)
1da177e4 339#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 340 decode_sequence_maxsz + \
1da177e4 341 decode_putfh_maxsz + \
9104a55d 342 decode_write_maxsz + \
4f9838c7 343 decode_getattr_maxsz)
1da177e4 344#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 345 encode_sequence_maxsz + \
1da177e4 346 encode_putfh_maxsz + \
9104a55d 347 encode_commit_maxsz + \
4f9838c7 348 encode_getattr_maxsz)
1da177e4 349#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 350 decode_sequence_maxsz + \
1da177e4 351 decode_putfh_maxsz + \
9104a55d 352 decode_commit_maxsz + \
4f9838c7 353 decode_getattr_maxsz)
1da177e4 354#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 355 encode_sequence_maxsz + \
2cebf828
TM
356 encode_putfh_maxsz + \
357 encode_savefh_maxsz + \
358 encode_open_maxsz + \
359 encode_getfh_maxsz + \
360 encode_getattr_maxsz + \
361 encode_restorefh_maxsz + \
362 encode_getattr_maxsz)
1da177e4 363#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 364 decode_sequence_maxsz + \
2cebf828
TM
365 decode_putfh_maxsz + \
366 decode_savefh_maxsz + \
367 decode_open_maxsz + \
368 decode_getfh_maxsz + \
369 decode_getattr_maxsz + \
370 decode_restorefh_maxsz + \
371 decode_getattr_maxsz)
9104a55d
TM
372#define NFS4_enc_open_confirm_sz \
373 (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
375 encode_open_confirm_maxsz)
376#define NFS4_dec_open_confirm_sz \
377 (compound_decode_hdr_maxsz + \
378 decode_putfh_maxsz + \
379 decode_open_confirm_maxsz)
1da177e4 380#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 381 encode_sequence_maxsz + \
1da177e4 382 encode_putfh_maxsz + \
2cebf828
TM
383 encode_open_maxsz + \
384 encode_getattr_maxsz)
1da177e4 385#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 386 decode_sequence_maxsz + \
1da177e4 387 decode_putfh_maxsz + \
2cebf828
TM
388 decode_open_maxsz + \
389 decode_getattr_maxsz)
1da177e4
LT
390#define NFS4_enc_open_downgrade_sz \
391 (compound_encode_hdr_maxsz + \
9b7b9fcc 392 encode_sequence_maxsz + \
9104a55d
TM
393 encode_putfh_maxsz + \
394 encode_open_downgrade_maxsz + \
395 encode_getattr_maxsz)
1da177e4
LT
396#define NFS4_dec_open_downgrade_sz \
397 (compound_decode_hdr_maxsz + \
9b7b9fcc 398 decode_sequence_maxsz + \
9104a55d
TM
399 decode_putfh_maxsz + \
400 decode_open_downgrade_maxsz + \
401 decode_getattr_maxsz)
402#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 403 encode_sequence_maxsz + \
9104a55d
TM
404 encode_putfh_maxsz + \
405 encode_close_maxsz + \
406 encode_getattr_maxsz)
407#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 408 decode_sequence_maxsz + \
9104a55d
TM
409 decode_putfh_maxsz + \
410 decode_close_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 413 encode_sequence_maxsz + \
9104a55d
TM
414 encode_putfh_maxsz + \
415 encode_setattr_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 418 decode_sequence_maxsz + \
9104a55d
TM
419 decode_putfh_maxsz + \
420 decode_setattr_maxsz + \
421 decode_getattr_maxsz)
1da177e4 422#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 423 encode_sequence_maxsz + \
1da177e4
LT
424 encode_putfh_maxsz + \
425 encode_fsinfo_maxsz)
426#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 427 decode_sequence_maxsz + \
1da177e4
LT
428 decode_putfh_maxsz + \
429 decode_fsinfo_maxsz)
430#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
431 encode_renew_maxsz)
432#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
433 decode_renew_maxsz)
434#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
435 encode_setclientid_maxsz)
436#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
437 decode_setclientid_maxsz)
438#define NFS4_enc_setclientid_confirm_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_setclientid_confirm_maxsz + \
441 encode_putrootfh_maxsz + \
442 encode_fsinfo_maxsz)
443#define NFS4_dec_setclientid_confirm_sz \
444 (compound_decode_hdr_maxsz + \
445 decode_setclientid_confirm_maxsz + \
446 decode_putrootfh_maxsz + \
447 decode_fsinfo_maxsz)
448#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 449 encode_sequence_maxsz + \
1da177e4 450 encode_putfh_maxsz + \
9104a55d 451 encode_lock_maxsz)
1da177e4 452#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 453 decode_sequence_maxsz + \
1da177e4 454 decode_putfh_maxsz + \
9104a55d 455 decode_lock_maxsz)
1da177e4 456#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 457 encode_sequence_maxsz + \
1da177e4 458 encode_putfh_maxsz + \
9104a55d
TM
459 encode_lockt_maxsz)
460#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 461 decode_sequence_maxsz + \
9104a55d
TM
462 decode_putfh_maxsz + \
463 decode_lockt_maxsz)
1da177e4 464#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 465 encode_sequence_maxsz + \
1da177e4 466 encode_putfh_maxsz + \
9104a55d 467 encode_locku_maxsz)
1da177e4 468#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 469 decode_sequence_maxsz + \
1da177e4 470 decode_putfh_maxsz + \
9104a55d 471 decode_locku_maxsz)
1da177e4 472#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 473 encode_sequence_maxsz + \
1da177e4 474 encode_putfh_maxsz + \
76b32999
TM
475 encode_access_maxsz + \
476 encode_getattr_maxsz)
1da177e4 477#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 478 decode_sequence_maxsz + \
1da177e4 479 decode_putfh_maxsz + \
76b32999
TM
480 decode_access_maxsz + \
481 decode_getattr_maxsz)
1da177e4 482#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 483 encode_sequence_maxsz + \
1da177e4
LT
484 encode_putfh_maxsz + \
485 encode_getattr_maxsz)
486#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 487 decode_sequence_maxsz + \
1da177e4
LT
488 decode_putfh_maxsz + \
489 decode_getattr_maxsz)
490#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 491 encode_sequence_maxsz + \
1da177e4
LT
492 encode_putfh_maxsz + \
493 encode_lookup_maxsz + \
494 encode_getattr_maxsz + \
495 encode_getfh_maxsz)
496#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 497 decode_sequence_maxsz + \
1da177e4 498 decode_putfh_maxsz + \
e6889620 499 decode_lookup_maxsz + \
1da177e4
LT
500 decode_getattr_maxsz + \
501 decode_getfh_maxsz)
502#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 503 encode_sequence_maxsz + \
1da177e4
LT
504 encode_putrootfh_maxsz + \
505 encode_getattr_maxsz + \
506 encode_getfh_maxsz)
507#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 508 decode_sequence_maxsz + \
1da177e4
LT
509 decode_putrootfh_maxsz + \
510 decode_getattr_maxsz + \
511 decode_getfh_maxsz)
512#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 513 encode_sequence_maxsz + \
1da177e4 514 encode_putfh_maxsz + \
16e42959
TM
515 encode_remove_maxsz + \
516 encode_getattr_maxsz)
1da177e4 517#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 518 decode_sequence_maxsz + \
1da177e4 519 decode_putfh_maxsz + \
6ce18391 520 decode_remove_maxsz + \
16e42959 521 decode_getattr_maxsz)
1da177e4 522#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 523 encode_sequence_maxsz + \
1da177e4
LT
524 encode_putfh_maxsz + \
525 encode_savefh_maxsz + \
526 encode_putfh_maxsz + \
6caf2c82
TM
527 encode_rename_maxsz + \
528 encode_getattr_maxsz + \
529 encode_restorefh_maxsz + \
530 encode_getattr_maxsz)
1da177e4 531#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 532 decode_sequence_maxsz + \
1da177e4
LT
533 decode_putfh_maxsz + \
534 decode_savefh_maxsz + \
535 decode_putfh_maxsz + \
6caf2c82
TM
536 decode_rename_maxsz + \
537 decode_getattr_maxsz + \
538 decode_restorefh_maxsz + \
539 decode_getattr_maxsz)
1da177e4 540#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 541 encode_sequence_maxsz + \
1da177e4
LT
542 encode_putfh_maxsz + \
543 encode_savefh_maxsz + \
544 encode_putfh_maxsz + \
91ba2eee
TM
545 encode_link_maxsz + \
546 decode_getattr_maxsz + \
547 encode_restorefh_maxsz + \
548 decode_getattr_maxsz)
1da177e4 549#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 550 decode_sequence_maxsz + \
1da177e4
LT
551 decode_putfh_maxsz + \
552 decode_savefh_maxsz + \
553 decode_putfh_maxsz + \
91ba2eee
TM
554 decode_link_maxsz + \
555 decode_getattr_maxsz + \
556 decode_restorefh_maxsz + \
557 decode_getattr_maxsz)
1da177e4 558#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 559 encode_sequence_maxsz + \
1da177e4
LT
560 encode_putfh_maxsz + \
561 encode_symlink_maxsz + \
562 encode_getattr_maxsz + \
563 encode_getfh_maxsz)
564#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 565 decode_sequence_maxsz + \
1da177e4
LT
566 decode_putfh_maxsz + \
567 decode_symlink_maxsz + \
568 decode_getattr_maxsz + \
569 decode_getfh_maxsz)
570#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 571 encode_sequence_maxsz + \
1da177e4 572 encode_putfh_maxsz + \
56ae19f3 573 encode_savefh_maxsz + \
1da177e4 574 encode_create_maxsz + \
56ae19f3 575 encode_getfh_maxsz + \
1da177e4 576 encode_getattr_maxsz + \
56ae19f3
TM
577 encode_restorefh_maxsz + \
578 encode_getattr_maxsz)
1da177e4 579#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 580 decode_sequence_maxsz + \
1da177e4 581 decode_putfh_maxsz + \
56ae19f3 582 decode_savefh_maxsz + \
1da177e4 583 decode_create_maxsz + \
56ae19f3 584 decode_getfh_maxsz + \
1da177e4 585 decode_getattr_maxsz + \
56ae19f3
TM
586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
1da177e4 588#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 589 encode_sequence_maxsz + \
1da177e4
LT
590 encode_putfh_maxsz + \
591 encode_getattr_maxsz)
592#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 593 decode_sequence_maxsz + \
1da177e4
LT
594 decode_putfh_maxsz + \
595 decode_getattr_maxsz)
596#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 597 encode_sequence_maxsz + \
1da177e4 598 encode_putfh_maxsz + \
9104a55d 599 encode_statfs_maxsz)
1da177e4 600#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 601 decode_sequence_maxsz + \
1da177e4 602 decode_putfh_maxsz + \
9104a55d 603 decode_statfs_maxsz)
1da177e4 604#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 605 encode_sequence_maxsz + \
ab91f264 606 encode_putfh_maxsz + \
1da177e4
LT
607 encode_getattr_maxsz)
608#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 609 decode_sequence_maxsz + \
ab91f264 610 decode_putfh_maxsz + \
1da177e4
LT
611 decode_getattr_maxsz)
612#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 613 encode_sequence_maxsz + \
1da177e4 614 encode_putfh_maxsz + \
fa178f29
TM
615 encode_delegreturn_maxsz + \
616 encode_getattr_maxsz)
1da177e4 617#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 618 decode_sequence_maxsz + \
fa178f29
TM
619 decode_delegreturn_maxsz + \
620 decode_getattr_maxsz)
029d105e 621#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 622 encode_sequence_maxsz + \
029d105e 623 encode_putfh_maxsz + \
9104a55d 624 encode_getacl_maxsz)
029d105e 625#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 626 decode_sequence_maxsz + \
029d105e 627 decode_putfh_maxsz + \
9104a55d 628 decode_getacl_maxsz)
23ec6965 629#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 630 encode_sequence_maxsz + \
23ec6965 631 encode_putfh_maxsz + \
9104a55d 632 encode_setacl_maxsz)
23ec6965 633#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 634 decode_sequence_maxsz + \
23ec6965 635 decode_putfh_maxsz + \
9104a55d 636 decode_setacl_maxsz)
683b57b4
TM
637#define NFS4_enc_fs_locations_sz \
638 (compound_encode_hdr_maxsz + \
9b7b9fcc 639 encode_sequence_maxsz + \
683b57b4 640 encode_putfh_maxsz + \
e6889620
TM
641 encode_lookup_maxsz + \
642 encode_fs_locations_maxsz)
683b57b4
TM
643#define NFS4_dec_fs_locations_sz \
644 (compound_decode_hdr_maxsz + \
9b7b9fcc 645 decode_sequence_maxsz + \
683b57b4 646 decode_putfh_maxsz + \
e6889620
TM
647 decode_lookup_maxsz + \
648 decode_fs_locations_maxsz)
99fe60d0
BH
649#if defined(CONFIG_NFS_V4_1)
650#define NFS4_enc_exchange_id_sz \
651 (compound_encode_hdr_maxsz + \
652 encode_exchange_id_maxsz)
653#define NFS4_dec_exchange_id_sz \
654 (compound_decode_hdr_maxsz + \
655 decode_exchange_id_maxsz)
fc931582
AA
656#define NFS4_enc_create_session_sz \
657 (compound_encode_hdr_maxsz + \
658 encode_create_session_maxsz)
659#define NFS4_dec_create_session_sz \
660 (compound_decode_hdr_maxsz + \
661 decode_create_session_maxsz)
0f3e66c6
AA
662#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
663 encode_destroy_session_maxsz)
664#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
665 decode_destroy_session_maxsz)
fc01cea9
AA
666#define NFS4_enc_sequence_sz \
667 (compound_decode_hdr_maxsz + \
668 encode_sequence_maxsz)
669#define NFS4_dec_sequence_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_sequence_maxsz)
2050f0cc
AA
672#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
673 encode_sequence_maxsz + \
674 encode_putrootfh_maxsz + \
675 encode_fsinfo_maxsz)
676#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
677 decode_sequence_maxsz + \
678 decode_putrootfh_maxsz + \
679 decode_fsinfo_maxsz)
99fe60d0 680#endif /* CONFIG_NFS_V4_1 */
1da177e4 681
bca79478
TM
682static const umode_t nfs_type2fmt[] = {
683 [NF4BAD] = 0,
684 [NF4REG] = S_IFREG,
685 [NF4DIR] = S_IFDIR,
686 [NF4BLK] = S_IFBLK,
687 [NF4CHR] = S_IFCHR,
688 [NF4LNK] = S_IFLNK,
689 [NF4SOCK] = S_IFSOCK,
690 [NF4FIFO] = S_IFIFO,
691 [NF4ATTRDIR] = 0,
692 [NF4NAMEDATTR] = 0,
1da177e4
LT
693};
694
695struct compound_hdr {
696 int32_t status;
697 uint32_t nops;
d017931c 698 __be32 * nops_p;
1da177e4
LT
699 uint32_t taglen;
700 char * tag;
0c4e8c18 701 uint32_t replen; /* expected reply words */
66cc0429 702 u32 minorversion;
1da177e4
LT
703};
704
705/*
706 * START OF "GENERIC" ENCODE ROUTINES.
707 * These may look a little ugly since they are imported from a "generic"
708 * set of XDR encode/decode routines which are intended to be shared by
709 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
710 *
711 * If the pain of reading these is too great, it should be a straightforward
712 * task to translate them into Linux-specific versions which are more
713 * consistent with the style used in NFSv2/v3...
714 */
1da177e4
LT
715#define WRITE64(n) do { \
716 *p++ = htonl((uint32_t)((n) >> 32)); \
717 *p++ = htonl((uint32_t)(n)); \
718} while (0)
719#define WRITEMEM(ptr,nbytes) do { \
720 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
721} while (0)
722
723#define RESERVE_SPACE(nbytes) do { \
724 p = xdr_reserve_space(xdr, nbytes); \
1da177e4
LT
725 BUG_ON(!p); \
726} while (0)
727
728static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
729{
8687b63a 730 __be32 *p;
1da177e4
LT
731
732 p = xdr_reserve_space(xdr, 4 + len);
733 BUG_ON(p == NULL);
734 xdr_encode_opaque(p, str, len);
735}
736
0c4e8c18
BH
737static void encode_compound_hdr(struct xdr_stream *xdr,
738 struct rpc_rqst *req,
739 struct compound_hdr *hdr)
1da177e4 740{
8687b63a 741 __be32 *p;
0c4e8c18
BH
742 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
743
744 /* initialize running count of expected bytes in reply.
745 * NOTE: the replied tag SHOULD be the same is the one sent,
746 * but this is not required as a MUST for the server to do so. */
747 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
1da177e4
LT
748
749 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
750 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
751 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
e75bc1c8 752 *p++ = cpu_to_be32(hdr->taglen);
1da177e4 753 WRITEMEM(hdr->tag, hdr->taglen);
e75bc1c8 754 *p++ = cpu_to_be32(hdr->minorversion);
d017931c 755 hdr->nops_p = p;
e75bc1c8 756 *p++ = cpu_to_be32(hdr->nops);
d017931c
AA
757}
758
759static void encode_nops(struct compound_hdr *hdr)
760{
fc931582 761 BUG_ON(hdr->nops > NFS4_MAX_OPS);
d017931c 762 *hdr->nops_p = htonl(hdr->nops);
1da177e4
LT
763}
764
765static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
766{
8687b63a 767 __be32 *p;
1da177e4
LT
768
769 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
770 BUG_ON(p == NULL);
771 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
772}
773
cf8cdbe5 774static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
1da177e4
LT
775{
776 char owner_name[IDMAP_NAMESZ];
777 char owner_group[IDMAP_NAMESZ];
778 int owner_namelen = 0;
779 int owner_grouplen = 0;
8687b63a
AV
780 __be32 *p;
781 __be32 *q;
1da177e4
LT
782 int len;
783 uint32_t bmval0 = 0;
784 uint32_t bmval1 = 0;
1da177e4
LT
785
786 /*
787 * We reserve enough space to write the entire attribute buffer at once.
788 * In the worst-case, this would be
789 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
790 * = 36 bytes, plus any contribution from variable-length fields
23ec6965 791 * such as owner/group.
1da177e4
LT
792 */
793 len = 16;
794
795 /* Sigh */
796 if (iap->ia_valid & ATTR_SIZE)
797 len += 8;
798 if (iap->ia_valid & ATTR_MODE)
799 len += 4;
800 if (iap->ia_valid & ATTR_UID) {
7539bbab 801 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
1da177e4 802 if (owner_namelen < 0) {
fe82a183
CL
803 dprintk("nfs: couldn't resolve uid %d to string\n",
804 iap->ia_uid);
1da177e4
LT
805 /* XXX */
806 strcpy(owner_name, "nobody");
807 owner_namelen = sizeof("nobody") - 1;
808 /* goto out; */
809 }
810 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
811 }
812 if (iap->ia_valid & ATTR_GID) {
7539bbab 813 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
1da177e4 814 if (owner_grouplen < 0) {
fe82a183
CL
815 dprintk("nfs: couldn't resolve gid %d to string\n",
816 iap->ia_gid);
1da177e4
LT
817 strcpy(owner_group, "nobody");
818 owner_grouplen = sizeof("nobody") - 1;
819 /* goto out; */
820 }
821 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
822 }
823 if (iap->ia_valid & ATTR_ATIME_SET)
824 len += 16;
825 else if (iap->ia_valid & ATTR_ATIME)
826 len += 4;
827 if (iap->ia_valid & ATTR_MTIME_SET)
828 len += 16;
829 else if (iap->ia_valid & ATTR_MTIME)
830 len += 4;
831 RESERVE_SPACE(len);
832
833 /*
834 * We write the bitmap length now, but leave the bitmap and the attribute
835 * buffer length to be backfilled at the end of this routine.
836 */
e75bc1c8 837 *p++ = cpu_to_be32(2);
1da177e4
LT
838 q = p;
839 p += 3;
840
841 if (iap->ia_valid & ATTR_SIZE) {
842 bmval0 |= FATTR4_WORD0_SIZE;
843 WRITE64(iap->ia_size);
844 }
845 if (iap->ia_valid & ATTR_MODE) {
846 bmval1 |= FATTR4_WORD1_MODE;
e75bc1c8 847 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1da177e4
LT
848 }
849 if (iap->ia_valid & ATTR_UID) {
850 bmval1 |= FATTR4_WORD1_OWNER;
e75bc1c8 851 *p++ = cpu_to_be32(owner_namelen);
1da177e4
LT
852 WRITEMEM(owner_name, owner_namelen);
853 }
854 if (iap->ia_valid & ATTR_GID) {
855 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
e75bc1c8 856 *p++ = cpu_to_be32(owner_grouplen);
1da177e4
LT
857 WRITEMEM(owner_group, owner_grouplen);
858 }
859 if (iap->ia_valid & ATTR_ATIME_SET) {
860 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
e75bc1c8
BH
861 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
862 *p++ = cpu_to_be32(0);
863 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
864 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1da177e4
LT
865 }
866 else if (iap->ia_valid & ATTR_ATIME) {
867 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
e75bc1c8 868 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1da177e4
LT
869 }
870 if (iap->ia_valid & ATTR_MTIME_SET) {
871 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
e75bc1c8
BH
872 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
873 *p++ = cpu_to_be32(0);
874 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
875 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1da177e4
LT
876 }
877 else if (iap->ia_valid & ATTR_MTIME) {
878 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
e75bc1c8 879 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1da177e4 880 }
6c0195a4 881
1da177e4
LT
882 /*
883 * Now we backfill the bitmap and the attribute buffer length.
884 */
885 if (len != ((char *)p - (char *)q) + 4) {
fe82a183 886 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
1da177e4
LT
887 len, ((char *)p - (char *)q) + 4);
888 BUG();
889 }
890 len = (char *)p - (char *)q - 12;
891 *q++ = htonl(bmval0);
892 *q++ = htonl(bmval1);
893 *q++ = htonl(len);
894
1da177e4 895/* out: */
1da177e4
LT
896}
897
cf8cdbe5 898static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1da177e4 899{
8687b63a 900 __be32 *p;
1da177e4
LT
901
902 RESERVE_SPACE(8);
e75bc1c8
BH
903 *p++ = cpu_to_be32(OP_ACCESS);
904 *p++ = cpu_to_be32(access);
d017931c 905 hdr->nops++;
dadf0c27 906 hdr->replen += decode_access_maxsz;
1da177e4
LT
907}
908
cf8cdbe5 909static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1da177e4 910{
8687b63a 911 __be32 *p;
1da177e4 912
8ae20abd 913 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
e75bc1c8
BH
914 *p++ = cpu_to_be32(OP_CLOSE);
915 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
8ae20abd 916 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
d017931c 917 hdr->nops++;
dadf0c27 918 hdr->replen += decode_close_maxsz;
1da177e4
LT
919}
920
cf8cdbe5 921static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1da177e4 922{
8687b63a 923 __be32 *p;
6c0195a4 924
05d564fe 925 RESERVE_SPACE(16);
e75bc1c8 926 *p++ = cpu_to_be32(OP_COMMIT);
05d564fe 927 WRITE64(args->offset);
e75bc1c8 928 *p++ = cpu_to_be32(args->count);
d017931c 929 hdr->nops++;
dadf0c27 930 hdr->replen += decode_commit_maxsz;
1da177e4
LT
931}
932
cf8cdbe5 933static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1da177e4 934{
8687b63a 935 __be32 *p;
6c0195a4 936
1da177e4 937 RESERVE_SPACE(8);
e75bc1c8
BH
938 *p++ = cpu_to_be32(OP_CREATE);
939 *p++ = cpu_to_be32(create->ftype);
1da177e4
LT
940
941 switch (create->ftype) {
942 case NF4LNK:
94a6d753 943 RESERVE_SPACE(4);
e75bc1c8 944 *p++ = cpu_to_be32(create->u.symlink.len);
94a6d753 945 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1da177e4
LT
946 break;
947
948 case NF4BLK: case NF4CHR:
949 RESERVE_SPACE(8);
e75bc1c8
BH
950 *p++ = cpu_to_be32(create->u.device.specdata1);
951 *p++ = cpu_to_be32(create->u.device.specdata2);
1da177e4
LT
952 break;
953
954 default:
955 break;
956 }
957
958 RESERVE_SPACE(4 + create->name->len);
e75bc1c8 959 *p++ = cpu_to_be32(create->name->len);
1da177e4 960 WRITEMEM(create->name->name, create->name->len);
d017931c 961 hdr->nops++;
dadf0c27 962 hdr->replen += decode_create_maxsz;
1da177e4 963
cf8cdbe5 964 encode_attrs(xdr, create->attrs, create->server);
1da177e4
LT
965}
966
cf8cdbe5 967static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1da177e4 968{
05d564fe 969 __be32 *p;
1da177e4 970
05d564fe 971 RESERVE_SPACE(12);
e75bc1c8
BH
972 *p++ = cpu_to_be32(OP_GETATTR);
973 *p++ = cpu_to_be32(1);
974 *p++ = cpu_to_be32(bitmap);
d017931c 975 hdr->nops++;
dadf0c27 976 hdr->replen += decode_getattr_maxsz;
1da177e4
LT
977}
978
cf8cdbe5 979static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1da177e4 980{
05d564fe 981 __be32 *p;
1da177e4 982
05d564fe 983 RESERVE_SPACE(16);
e75bc1c8
BH
984 *p++ = cpu_to_be32(OP_GETATTR);
985 *p++ = cpu_to_be32(2);
986 *p++ = cpu_to_be32(bm0);
987 *p++ = cpu_to_be32(bm1);
d017931c 988 hdr->nops++;
dadf0c27 989 hdr->replen += decode_getattr_maxsz;
1da177e4
LT
990}
991
cf8cdbe5 992static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1da177e4 993{
cf8cdbe5
AA
994 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
995 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1da177e4
LT
996}
997
cf8cdbe5 998static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1da177e4 999{
cf8cdbe5
AA
1000 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1001 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1da177e4
LT
1002}
1003
cf8cdbe5 1004static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
830b8e33 1005{
cf8cdbe5
AA
1006 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1007 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
830b8e33
MN
1008}
1009
cf8cdbe5 1010static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1011{
8687b63a 1012 __be32 *p;
1da177e4
LT
1013
1014 RESERVE_SPACE(4);
e75bc1c8 1015 *p++ = cpu_to_be32(OP_GETFH);
d017931c 1016 hdr->nops++;
dadf0c27 1017 hdr->replen += decode_getfh_maxsz;
1da177e4
LT
1018}
1019
cf8cdbe5 1020static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1021{
8687b63a 1022 __be32 *p;
1da177e4
LT
1023
1024 RESERVE_SPACE(8 + name->len);
e75bc1c8
BH
1025 *p++ = cpu_to_be32(OP_LINK);
1026 *p++ = cpu_to_be32(name->len);
1da177e4 1027 WRITEMEM(name->name, name->len);
d017931c 1028 hdr->nops++;
dadf0c27 1029 hdr->replen += decode_link_maxsz;
1da177e4
LT
1030}
1031
911d1aaf
TM
1032static inline int nfs4_lock_type(struct file_lock *fl, int block)
1033{
1034 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1035 return block ? NFS4_READW_LT : NFS4_READ_LT;
1036 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1037}
1038
1039static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1040{
1041 if (fl->fl_end == OFFSET_MAX)
1042 return ~(uint64_t)0;
1043 return fl->fl_end - fl->fl_start + 1;
1044}
1045
1da177e4
LT
1046/*
1047 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1048 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1049 */
cf8cdbe5 1050static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1da177e4 1051{
8687b63a 1052 __be32 *p;
1da177e4
LT
1053
1054 RESERVE_SPACE(32);
e75bc1c8
BH
1055 *p++ = cpu_to_be32(OP_LOCK);
1056 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1057 *p++ = cpu_to_be32(args->reclaim);
911d1aaf
TM
1058 WRITE64(args->fl->fl_start);
1059 WRITE64(nfs4_lock_length(args->fl));
e75bc1c8 1060 *p++ = cpu_to_be32(args->new_lock_owner);
911d1aaf 1061 if (args->new_lock_owner){
9f958ab8 1062 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
e75bc1c8 1063 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
8ae20abd 1064 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
e75bc1c8 1065 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
911d1aaf 1066 WRITE64(args->lock_owner.clientid);
e75bc1c8 1067 *p++ = cpu_to_be32(16);
9f958ab8
TM
1068 WRITEMEM("lock id:", 8);
1069 WRITE64(args->lock_owner.id);
1da177e4
LT
1070 }
1071 else {
8ae20abd
TM
1072 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1073 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
e75bc1c8 1074 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1da177e4 1075 }
d017931c 1076 hdr->nops++;
dadf0c27 1077 hdr->replen += decode_lock_maxsz;
1da177e4
LT
1078}
1079
cf8cdbe5 1080static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1da177e4 1081{
8687b63a 1082 __be32 *p;
1da177e4 1083
9f958ab8 1084 RESERVE_SPACE(52);
e75bc1c8
BH
1085 *p++ = cpu_to_be32(OP_LOCKT);
1086 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
911d1aaf
TM
1087 WRITE64(args->fl->fl_start);
1088 WRITE64(nfs4_lock_length(args->fl));
1089 WRITE64(args->lock_owner.clientid);
e75bc1c8 1090 *p++ = cpu_to_be32(16);
9f958ab8
TM
1091 WRITEMEM("lock id:", 8);
1092 WRITE64(args->lock_owner.id);
d017931c 1093 hdr->nops++;
dadf0c27 1094 hdr->replen += decode_lockt_maxsz;
1da177e4
LT
1095}
1096
cf8cdbe5 1097static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1da177e4 1098{
8687b63a 1099 __be32 *p;
1da177e4 1100
8ae20abd 1101 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
e75bc1c8
BH
1102 *p++ = cpu_to_be32(OP_LOCKU);
1103 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1104 *p++ = cpu_to_be32(args->seqid->sequence->counter);
8ae20abd 1105 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
911d1aaf
TM
1106 WRITE64(args->fl->fl_start);
1107 WRITE64(nfs4_lock_length(args->fl));
d017931c 1108 hdr->nops++;
dadf0c27 1109 hdr->replen += decode_locku_maxsz;
1da177e4
LT
1110}
1111
cf8cdbe5 1112static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4
LT
1113{
1114 int len = name->len;
8687b63a 1115 __be32 *p;
1da177e4
LT
1116
1117 RESERVE_SPACE(8 + len);
e75bc1c8
BH
1118 *p++ = cpu_to_be32(OP_LOOKUP);
1119 *p++ = cpu_to_be32(len);
1da177e4 1120 WRITEMEM(name->name, len);
d017931c 1121 hdr->nops++;
dadf0c27 1122 hdr->replen += decode_lookup_maxsz;
1da177e4
LT
1123}
1124
dc0b027d 1125static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1da177e4 1126{
8687b63a 1127 __be32 *p;
1da177e4
LT
1128
1129 RESERVE_SPACE(8);
dc0b027d 1130 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
05d564fe 1131 case FMODE_READ:
e75bc1c8 1132 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
05d564fe
AA
1133 break;
1134 case FMODE_WRITE:
e75bc1c8 1135 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
05d564fe
AA
1136 break;
1137 case FMODE_READ|FMODE_WRITE:
e75bc1c8 1138 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
05d564fe
AA
1139 break;
1140 default:
e75bc1c8 1141 *p++ = cpu_to_be32(0);
1da177e4 1142 }
e75bc1c8 1143 *p++ = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1da177e4
LT
1144}
1145
1146static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1147{
8687b63a 1148 __be32 *p;
1da177e4
LT
1149 /*
1150 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1151 * owner 4 = 32
1152 */
1153 RESERVE_SPACE(8);
e75bc1c8
BH
1154 *p++ = cpu_to_be32(OP_OPEN);
1155 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
dc0b027d 1156 encode_share_access(xdr, arg->fmode);
9f958ab8 1157 RESERVE_SPACE(28);
1da177e4 1158 WRITE64(arg->clientid);
e75bc1c8 1159 *p++ = cpu_to_be32(16);
9f958ab8
TM
1160 WRITEMEM("open id:", 8);
1161 WRITE64(arg->id);
1da177e4
LT
1162}
1163
1164static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1165{
8687b63a 1166 __be32 *p;
1da177e4
LT
1167
1168 RESERVE_SPACE(4);
1169 switch(arg->open_flags & O_EXCL) {
05d564fe 1170 case 0:
e75bc1c8 1171 *p++ = cpu_to_be32(NFS4_CREATE_UNCHECKED);
05d564fe
AA
1172 encode_attrs(xdr, arg->u.attrs, arg->server);
1173 break;
1174 default:
e75bc1c8 1175 *p++ = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
05d564fe 1176 encode_nfs4_verifier(xdr, &arg->u.verifier);
1da177e4
LT
1177 }
1178}
1179
1180static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1181{
8687b63a 1182 __be32 *p;
1da177e4
LT
1183
1184 RESERVE_SPACE(4);
1185 switch (arg->open_flags & O_CREAT) {
05d564fe 1186 case 0:
e75bc1c8 1187 *p++ = cpu_to_be32(NFS4_OPEN_NOCREATE);
05d564fe
AA
1188 break;
1189 default:
1190 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
e75bc1c8 1191 *p++ = cpu_to_be32(NFS4_OPEN_CREATE);
05d564fe 1192 encode_createmode(xdr, arg);
1da177e4
LT
1193 }
1194}
1195
bd7bf9d5 1196static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1da177e4 1197{
8687b63a 1198 __be32 *p;
1da177e4
LT
1199
1200 RESERVE_SPACE(4);
1201 switch (delegation_type) {
05d564fe 1202 case 0:
e75bc1c8 1203 *p++ = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
05d564fe
AA
1204 break;
1205 case FMODE_READ:
e75bc1c8 1206 *p++ = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
05d564fe
AA
1207 break;
1208 case FMODE_WRITE|FMODE_READ:
e75bc1c8 1209 *p++ = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
05d564fe
AA
1210 break;
1211 default:
1212 BUG();
1da177e4
LT
1213 }
1214}
1215
1216static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1217{
8687b63a 1218 __be32 *p;
1da177e4
LT
1219
1220 RESERVE_SPACE(4);
e75bc1c8 1221 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1da177e4
LT
1222 encode_string(xdr, name->len, name->name);
1223}
1224
bd7bf9d5 1225static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1da177e4 1226{
8687b63a 1227 __be32 *p;
1da177e4
LT
1228
1229 RESERVE_SPACE(4);
e75bc1c8 1230 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1da177e4
LT
1231 encode_delegation_type(xdr, type);
1232}
1233
1234static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1235{
8687b63a 1236 __be32 *p;
1da177e4 1237
8ae20abd 1238 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
e75bc1c8 1239 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
8ae20abd 1240 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1da177e4
LT
1241 encode_string(xdr, name->len, name->name);
1242}
1243
cf8cdbe5 1244static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1da177e4
LT
1245{
1246 encode_openhdr(xdr, arg);
1247 encode_opentype(xdr, arg);
1248 switch (arg->claim) {
05d564fe
AA
1249 case NFS4_OPEN_CLAIM_NULL:
1250 encode_claim_null(xdr, arg->name);
1251 break;
1252 case NFS4_OPEN_CLAIM_PREVIOUS:
1253 encode_claim_previous(xdr, arg->u.delegation_type);
1254 break;
1255 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1256 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1257 break;
1258 default:
1259 BUG();
1da177e4 1260 }
d017931c 1261 hdr->nops++;
dadf0c27 1262 hdr->replen += decode_open_maxsz;
1da177e4
LT
1263}
1264
cf8cdbe5 1265static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1da177e4 1266{
8687b63a 1267 __be32 *p;
1da177e4 1268
8ae20abd 1269 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
e75bc1c8 1270 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
8ae20abd 1271 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
e75bc1c8 1272 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
d017931c 1273 hdr->nops++;
dadf0c27 1274 hdr->replen += decode_open_confirm_maxsz;
1da177e4
LT
1275}
1276
cf8cdbe5 1277static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1da177e4 1278{
8687b63a 1279 __be32 *p;
1da177e4 1280
8ae20abd 1281 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
e75bc1c8 1282 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
8ae20abd 1283 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
e75bc1c8 1284 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
dc0b027d 1285 encode_share_access(xdr, arg->fmode);
d017931c 1286 hdr->nops++;
dadf0c27 1287 hdr->replen += decode_open_downgrade_maxsz;
1da177e4
LT
1288}
1289
cf8cdbe5 1290static void
d017931c 1291encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1da177e4
LT
1292{
1293 int len = fh->size;
8687b63a 1294 __be32 *p;
1da177e4
LT
1295
1296 RESERVE_SPACE(8 + len);
e75bc1c8
BH
1297 *p++ = cpu_to_be32(OP_PUTFH);
1298 *p++ = cpu_to_be32(len);
1da177e4 1299 WRITEMEM(fh->data, len);
d017931c 1300 hdr->nops++;
dadf0c27 1301 hdr->replen += decode_putfh_maxsz;
1da177e4
LT
1302}
1303
cf8cdbe5 1304static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1305{
05d564fe 1306 __be32 *p;
6c0195a4 1307
05d564fe 1308 RESERVE_SPACE(4);
e75bc1c8 1309 *p++ = cpu_to_be32(OP_PUTROOTFH);
d017931c 1310 hdr->nops++;
dadf0c27 1311 hdr->replen += decode_putrootfh_maxsz;
1da177e4
LT
1312}
1313
1314static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1315{
1da177e4 1316 nfs4_stateid stateid;
8687b63a 1317 __be32 *p;
1da177e4 1318
8ae20abd 1319 RESERVE_SPACE(NFS4_STATEID_SIZE);
1da177e4
LT
1320 if (ctx->state != NULL) {
1321 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
8ae20abd 1322 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1da177e4 1323 } else
8ae20abd 1324 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1da177e4
LT
1325}
1326
cf8cdbe5 1327static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1da177e4 1328{
8687b63a 1329 __be32 *p;
1da177e4
LT
1330
1331 RESERVE_SPACE(4);
e75bc1c8 1332 *p++ = cpu_to_be32(OP_READ);
1da177e4
LT
1333
1334 encode_stateid(xdr, args->context);
1335
1336 RESERVE_SPACE(12);
1337 WRITE64(args->offset);
e75bc1c8 1338 *p++ = cpu_to_be32(args->count);
d017931c 1339 hdr->nops++;
dadf0c27 1340 hdr->replen += decode_read_maxsz;
1da177e4
LT
1341}
1342
cf8cdbe5 1343static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1da177e4 1344{
97d312d0
MN
1345 uint32_t attrs[2] = {
1346 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1347 FATTR4_WORD1_MOUNTED_ON_FILEID,
1348 };
8687b63a 1349 __be32 *p;
1da177e4 1350
8ae20abd 1351 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
e75bc1c8 1352 *p++ = cpu_to_be32(OP_READDIR);
1da177e4 1353 WRITE64(readdir->cookie);
8ae20abd 1354 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
e75bc1c8
BH
1355 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1356 *p++ = cpu_to_be32(readdir->count);
1357 *p++ = cpu_to_be32(2);
97d312d0
MN
1358 /* Switch to mounted_on_fileid if the server supports it */
1359 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1360 attrs[0] &= ~FATTR4_WORD0_FILEID;
1361 else
1362 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
e75bc1c8
BH
1363 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1364 *p++ = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
d017931c 1365 hdr->nops++;
dadf0c27 1366 hdr->replen += decode_readdir_maxsz;
44109241
FI
1367 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1368 __func__,
eadf4598
TM
1369 (unsigned long long)readdir->cookie,
1370 ((u32 *)readdir->verifier.data)[0],
1371 ((u32 *)readdir->verifier.data)[1],
1372 attrs[0] & readdir->bitmask[0],
1373 attrs[1] & readdir->bitmask[1]);
1da177e4
LT
1374}
1375
cf8cdbe5 1376static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1da177e4 1377{
8687b63a 1378 __be32 *p;
1da177e4
LT
1379
1380 RESERVE_SPACE(4);
e75bc1c8 1381 *p++ = cpu_to_be32(OP_READLINK);
d017931c 1382 hdr->nops++;
dadf0c27 1383 hdr->replen += decode_readlink_maxsz;
1da177e4
LT
1384}
1385
cf8cdbe5 1386static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1387{
8687b63a 1388 __be32 *p;
1da177e4
LT
1389
1390 RESERVE_SPACE(8 + name->len);
e75bc1c8
BH
1391 *p++ = cpu_to_be32(OP_REMOVE);
1392 *p++ = cpu_to_be32(name->len);
1da177e4 1393 WRITEMEM(name->name, name->len);
d017931c 1394 hdr->nops++;
dadf0c27 1395 hdr->replen += decode_remove_maxsz;
1da177e4
LT
1396}
1397
cf8cdbe5 1398static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1da177e4 1399{
8687b63a 1400 __be32 *p;
1da177e4
LT
1401
1402 RESERVE_SPACE(8 + oldname->len);
e75bc1c8
BH
1403 *p++ = cpu_to_be32(OP_RENAME);
1404 *p++ = cpu_to_be32(oldname->len);
1da177e4 1405 WRITEMEM(oldname->name, oldname->len);
6c0195a4 1406
1da177e4 1407 RESERVE_SPACE(4 + newname->len);
e75bc1c8 1408 *p++ = cpu_to_be32(newname->len);
1da177e4 1409 WRITEMEM(newname->name, newname->len);
d017931c 1410 hdr->nops++;
dadf0c27 1411 hdr->replen += decode_rename_maxsz;
1da177e4
LT
1412}
1413
cf8cdbe5 1414static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1da177e4 1415{
8687b63a 1416 __be32 *p;
1da177e4
LT
1417
1418 RESERVE_SPACE(12);
e75bc1c8 1419 *p++ = cpu_to_be32(OP_RENEW);
1da177e4 1420 WRITE64(client_stateid->cl_clientid);
d017931c 1421 hdr->nops++;
dadf0c27 1422 hdr->replen += decode_renew_maxsz;
1da177e4
LT
1423}
1424
cf8cdbe5 1425static void
d017931c 1426encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
56ae19f3 1427{
8687b63a 1428 __be32 *p;
56ae19f3
TM
1429
1430 RESERVE_SPACE(4);
e75bc1c8 1431 *p++ = cpu_to_be32(OP_RESTOREFH);
d017931c 1432 hdr->nops++;
dadf0c27 1433 hdr->replen += decode_restorefh_maxsz;
56ae19f3
TM
1434}
1435
23ec6965 1436static int
d017931c 1437encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
23ec6965 1438{
8687b63a 1439 __be32 *p;
23ec6965 1440
8ae20abd 1441 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
e75bc1c8 1442 *p++ = cpu_to_be32(OP_SETATTR);
8ae20abd 1443 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
23ec6965 1444 RESERVE_SPACE(2*4);
e75bc1c8
BH
1445 *p++ = cpu_to_be32(1);
1446 *p++ = cpu_to_be32(FATTR4_WORD0_ACL);
23ec6965
BF
1447 if (arg->acl_len % 4)
1448 return -EINVAL;
1449 RESERVE_SPACE(4);
e75bc1c8 1450 *p++ = cpu_to_be32(arg->acl_len);
23ec6965 1451 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
d017931c 1452 hdr->nops++;
dadf0c27 1453 hdr->replen += decode_setacl_maxsz;
23ec6965
BF
1454 return 0;
1455}
1456
cf8cdbe5 1457static void
d017931c 1458encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1459{
8687b63a 1460 __be32 *p;
1da177e4
LT
1461
1462 RESERVE_SPACE(4);
e75bc1c8 1463 *p++ = cpu_to_be32(OP_SAVEFH);
d017931c 1464 hdr->nops++;
dadf0c27 1465 hdr->replen += decode_savefh_maxsz;
1da177e4
LT
1466}
1467
cf8cdbe5 1468static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1da177e4 1469{
8687b63a 1470 __be32 *p;
6c0195a4 1471
05d564fe 1472 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
e75bc1c8 1473 *p++ = cpu_to_be32(OP_SETATTR);
8ae20abd 1474 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
d017931c 1475 hdr->nops++;
dadf0c27 1476 hdr->replen += decode_setattr_maxsz;
cf8cdbe5 1477 encode_attrs(xdr, arg->iap, server);
1da177e4
LT
1478}
1479
cf8cdbe5 1480static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1da177e4 1481{
8687b63a 1482 __be32 *p;
1da177e4 1483
8ae20abd 1484 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
e75bc1c8 1485 *p++ = cpu_to_be32(OP_SETCLIENTID);
8ae20abd 1486 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1da177e4
LT
1487
1488 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1489 RESERVE_SPACE(4);
e75bc1c8 1490 *p++ = cpu_to_be32(setclientid->sc_prog);
1da177e4
LT
1491 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1492 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1493 RESERVE_SPACE(4);
e75bc1c8 1494 *p++ = cpu_to_be32(setclientid->sc_cb_ident);
d017931c 1495 hdr->nops++;
dadf0c27 1496 hdr->replen += decode_setclientid_maxsz;
1da177e4
LT
1497}
1498
cf8cdbe5 1499static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1da177e4 1500{
05d564fe 1501 __be32 *p;
1da177e4 1502
05d564fe 1503 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
e75bc1c8 1504 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
05d564fe
AA
1505 WRITE64(client_state->cl_clientid);
1506 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
d017931c 1507 hdr->nops++;
dadf0c27 1508 hdr->replen += decode_setclientid_confirm_maxsz;
1da177e4
LT
1509}
1510
cf8cdbe5 1511static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1da177e4 1512{
8687b63a 1513 __be32 *p;
1da177e4
LT
1514
1515 RESERVE_SPACE(4);
e75bc1c8 1516 *p++ = cpu_to_be32(OP_WRITE);
1da177e4
LT
1517
1518 encode_stateid(xdr, args->context);
1519
1520 RESERVE_SPACE(16);
1521 WRITE64(args->offset);
e75bc1c8
BH
1522 *p++ = cpu_to_be32(args->stable);
1523 *p++ = cpu_to_be32(args->count);
1da177e4
LT
1524
1525 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
d017931c 1526 hdr->nops++;
dadf0c27 1527 hdr->replen += decode_write_maxsz;
1da177e4
LT
1528}
1529
cf8cdbe5 1530static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1da177e4 1531{
8687b63a 1532 __be32 *p;
1da177e4 1533
8ae20abd 1534 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1da177e4 1535
e75bc1c8 1536 *p++ = cpu_to_be32(OP_DELEGRETURN);
8ae20abd 1537 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
d017931c 1538 hdr->nops++;
dadf0c27 1539 hdr->replen += decode_delegreturn_maxsz;
1da177e4 1540}
9b7b9fcc 1541
99fe60d0 1542#if defined(CONFIG_NFS_V4_1)
9b7b9fcc 1543/* NFSv4.1 operations */
99fe60d0
BH
1544static void encode_exchange_id(struct xdr_stream *xdr,
1545 struct nfs41_exchange_id_args *args,
1546 struct compound_hdr *hdr)
1547{
1548 __be32 *p;
1549
1550 RESERVE_SPACE(4 + sizeof(args->verifier->data));
e75bc1c8 1551 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
99fe60d0
BH
1552 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1553
1554 encode_string(xdr, args->id_len, args->id);
1555
1556 RESERVE_SPACE(12);
e75bc1c8
BH
1557 *p++ = cpu_to_be32(args->flags);
1558 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1559 *p++ = cpu_to_be32(0); /* zero length implementation id array */
99fe60d0
BH
1560 hdr->nops++;
1561 hdr->replen += decode_exchange_id_maxsz;
1562}
fc931582
AA
1563
1564static void encode_create_session(struct xdr_stream *xdr,
1565 struct nfs41_create_session_args *args,
1566 struct compound_hdr *hdr)
1567{
1568 __be32 *p;
1569 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1570 uint32_t len;
1571 struct nfs_client *clp = args->client;
1572
1573 RESERVE_SPACE(4);
e75bc1c8 1574 *p++ = cpu_to_be32(OP_CREATE_SESSION);
fc931582
AA
1575
1576 RESERVE_SPACE(8);
1577 WRITE64(clp->cl_ex_clid);
1578
1579 RESERVE_SPACE(8);
e75bc1c8
BH
1580 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1581 *p++ = cpu_to_be32(args->flags); /*flags */
fc931582
AA
1582
1583 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1584 /* Fore Channel */
e75bc1c8
BH
1585 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1586 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1587 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1588 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1589 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1590 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1591 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
fc931582
AA
1592
1593 /* Back Channel */
e75bc1c8
BH
1594 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1595 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1596 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1597 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1598 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1599 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1600 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
fc931582
AA
1601
1602 RESERVE_SPACE(4);
e75bc1c8 1603 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
fc931582
AA
1604
1605 RESERVE_SPACE(4); /* # of security flavors */
e75bc1c8 1606 *p++ = cpu_to_be32(1);
fc931582
AA
1607
1608 RESERVE_SPACE(4);
e75bc1c8 1609 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
fc931582
AA
1610
1611 /* authsys_parms rfc1831 */
1612 RESERVE_SPACE(4);
e75bc1c8 1613 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
fc931582
AA
1614 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1615 clp->cl_ipaddr);
1616 RESERVE_SPACE(16 + len);
e75bc1c8 1617 *p++ = cpu_to_be32(len);
fc931582 1618 WRITEMEM(machine_name, len);
e75bc1c8
BH
1619 *p++ = cpu_to_be32(0); /* UID */
1620 *p++ = cpu_to_be32(0); /* GID */
1621 *p++ = cpu_to_be32(0); /* No more gids */
fc931582
AA
1622 hdr->nops++;
1623 hdr->replen += decode_create_session_maxsz;
1624}
0f3e66c6
AA
1625
1626static void encode_destroy_session(struct xdr_stream *xdr,
1627 struct nfs4_session *session,
1628 struct compound_hdr *hdr)
1629{
1630 __be32 *p;
1631 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
e75bc1c8 1632 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
0f3e66c6
AA
1633 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1634 hdr->nops++;
1635 hdr->replen += decode_destroy_session_maxsz;
1636}
99fe60d0
BH
1637#endif /* CONFIG_NFS_V4_1 */
1638
9b7b9fcc
AA
1639static void encode_sequence(struct xdr_stream *xdr,
1640 const struct nfs4_sequence_args *args,
1641 struct compound_hdr *hdr)
1642{
1643#if defined(CONFIG_NFS_V4_1)
1644 struct nfs4_session *session = args->sa_session;
fc01cea9
AA
1645 struct nfs4_slot_table *tp;
1646 struct nfs4_slot *slot;
1647 __be32 *p;
9b7b9fcc
AA
1648
1649 if (!session)
1650 return;
1651
fc01cea9
AA
1652 tp = &session->fc_slot_table;
1653
1654 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1655 slot = tp->slots + args->sa_slotid;
1656
1657 RESERVE_SPACE(4);
e75bc1c8 1658 *p++ = cpu_to_be32(OP_SEQUENCE);
fc01cea9
AA
1659
1660 /*
1661 * Sessionid + seqid + slotid + max slotid + cache_this
1662 */
1663 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1664 "max_slotid=%d cache_this=%d\n",
1665 __func__,
1666 ((u32 *)session->sess_id.data)[0],
1667 ((u32 *)session->sess_id.data)[1],
1668 ((u32 *)session->sess_id.data)[2],
1669 ((u32 *)session->sess_id.data)[3],
1670 slot->seq_nr, args->sa_slotid,
1671 tp->highest_used_slotid, args->sa_cache_this);
1672 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
1673 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
e75bc1c8
BH
1674 *p++ = cpu_to_be32(slot->seq_nr);
1675 *p++ = cpu_to_be32(args->sa_slotid);
1676 *p++ = cpu_to_be32(tp->highest_used_slotid);
1677 *p++ = cpu_to_be32(args->sa_cache_this);
9b7b9fcc
AA
1678 hdr->nops++;
1679 hdr->replen += decode_sequence_maxsz;
1680#endif /* CONFIG_NFS_V4_1 */
1681}
1682
1da177e4
LT
1683/*
1684 * END OF "GENERIC" ENCODE ROUTINES.
1685 */
1686
66cc0429
BH
1687static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1688{
1689#if defined(CONFIG_NFS_V4_1)
1690 if (args->sa_session)
1691 return args->sa_session->clp->cl_minorversion;
1692#endif /* CONFIG_NFS_V4_1 */
1693 return 0;
1694}
1695
1da177e4
LT
1696/*
1697 * Encode an ACCESS request
1698 */
8687b63a 1699static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1da177e4
LT
1700{
1701 struct xdr_stream xdr;
1702 struct compound_hdr hdr = {
66cc0429 1703 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1704 };
1da177e4
LT
1705
1706 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1707 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1708 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1709 encode_putfh(&xdr, args->fh, &hdr);
1710 encode_access(&xdr, args->access, &hdr);
1711 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1712 encode_nops(&hdr);
cf8cdbe5 1713 return 0;
1da177e4
LT
1714}
1715
1716/*
1717 * Encode LOOKUP request
1718 */
8687b63a 1719static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1da177e4
LT
1720{
1721 struct xdr_stream xdr;
1722 struct compound_hdr hdr = {
66cc0429 1723 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1724 };
1da177e4
LT
1725
1726 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1727 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1728 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1729 encode_putfh(&xdr, args->dir_fh, &hdr);
1730 encode_lookup(&xdr, args->name, &hdr);
1731 encode_getfh(&xdr, &hdr);
1732 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1733 encode_nops(&hdr);
cf8cdbe5 1734 return 0;
1da177e4
LT
1735}
1736
1737/*
1738 * Encode LOOKUP_ROOT request
1739 */
8687b63a 1740static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1da177e4
LT
1741{
1742 struct xdr_stream xdr;
1743 struct compound_hdr hdr = {
66cc0429 1744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1745 };
1da177e4
LT
1746
1747 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1748 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1749 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1750 encode_putrootfh(&xdr, &hdr);
1751 encode_getfh(&xdr, &hdr);
1752 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1753 encode_nops(&hdr);
cf8cdbe5 1754 return 0;
1da177e4
LT
1755}
1756
1757/*
1758 * Encode REMOVE request
1759 */
4fdc17b2 1760static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1da177e4
LT
1761{
1762 struct xdr_stream xdr;
1763 struct compound_hdr hdr = {
66cc0429 1764 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1765 };
1da177e4
LT
1766
1767 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1768 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1769 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1770 encode_putfh(&xdr, args->fh, &hdr);
1771 encode_remove(&xdr, &args->name, &hdr);
1772 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1773 encode_nops(&hdr);
cf8cdbe5 1774 return 0;
1da177e4
LT
1775}
1776
1777/*
1778 * Encode RENAME request
1779 */
8687b63a 1780static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1da177e4
LT
1781{
1782 struct xdr_stream xdr;
1783 struct compound_hdr hdr = {
66cc0429 1784 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1785 };
1da177e4
LT
1786
1787 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1788 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1789 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1790 encode_putfh(&xdr, args->old_dir, &hdr);
1791 encode_savefh(&xdr, &hdr);
1792 encode_putfh(&xdr, args->new_dir, &hdr);
1793 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1794 encode_getfattr(&xdr, args->bitmask, &hdr);
1795 encode_restorefh(&xdr, &hdr);
1796 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1797 encode_nops(&hdr);
cf8cdbe5 1798 return 0;
1da177e4
LT
1799}
1800
1801/*
1802 * Encode LINK request
1803 */
8687b63a 1804static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1da177e4
LT
1805{
1806 struct xdr_stream xdr;
1807 struct compound_hdr hdr = {
66cc0429 1808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1809 };
1da177e4
LT
1810
1811 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1812 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1813 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1814 encode_putfh(&xdr, args->fh, &hdr);
1815 encode_savefh(&xdr, &hdr);
1816 encode_putfh(&xdr, args->dir_fh, &hdr);
1817 encode_link(&xdr, args->name, &hdr);
1818 encode_getfattr(&xdr, args->bitmask, &hdr);
1819 encode_restorefh(&xdr, &hdr);
1820 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1821 encode_nops(&hdr);
cf8cdbe5 1822 return 0;
1da177e4
LT
1823}
1824
1825/*
1826 * Encode CREATE request
1827 */
8687b63a 1828static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1da177e4
LT
1829{
1830 struct xdr_stream xdr;
1831 struct compound_hdr hdr = {
66cc0429 1832 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1833 };
1da177e4
LT
1834
1835 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1836 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1837 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1838 encode_putfh(&xdr, args->dir_fh, &hdr);
1839 encode_savefh(&xdr, &hdr);
1840 encode_create(&xdr, args, &hdr);
1841 encode_getfh(&xdr, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
1843 encode_restorefh(&xdr, &hdr);
1844 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1845 encode_nops(&hdr);
cf8cdbe5 1846 return 0;
1da177e4
LT
1847}
1848
1849/*
1850 * Encode SYMLINK request
1851 */
8687b63a 1852static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1da177e4
LT
1853{
1854 return nfs4_xdr_enc_create(req, p, args);
1855}
1856
1857/*
1858 * Encode GETATTR request
1859 */
8687b63a 1860static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1da177e4
LT
1861{
1862 struct xdr_stream xdr;
1863 struct compound_hdr hdr = {
66cc0429 1864 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1865 };
1da177e4
LT
1866
1867 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1868 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1869 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1870 encode_putfh(&xdr, args->fh, &hdr);
1871 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1872 encode_nops(&hdr);
cf8cdbe5 1873 return 0;
1da177e4
LT
1874}
1875
1876/*
1877 * Encode a CLOSE request
1878 */
8687b63a 1879static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1da177e4 1880{
05d564fe
AA
1881 struct xdr_stream xdr;
1882 struct compound_hdr hdr = {
66cc0429 1883 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 1884 };
05d564fe
AA
1885
1886 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1887 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1888 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1889 encode_putfh(&xdr, args->fh, &hdr);
1890 encode_close(&xdr, args, &hdr);
1891 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1892 encode_nops(&hdr);
cf8cdbe5 1893 return 0;
1da177e4
LT
1894}
1895
1896/*
1897 * Encode an OPEN request
1898 */
8687b63a 1899static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1da177e4
LT
1900{
1901 struct xdr_stream xdr;
1902 struct compound_hdr hdr = {
66cc0429 1903 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1904 };
1da177e4
LT
1905
1906 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1907 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1908 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1909 encode_putfh(&xdr, args->fh, &hdr);
1910 encode_savefh(&xdr, &hdr);
1911 encode_open(&xdr, args, &hdr);
1912 encode_getfh(&xdr, &hdr);
1913 encode_getfattr(&xdr, args->bitmask, &hdr);
1914 encode_restorefh(&xdr, &hdr);
1915 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1916 encode_nops(&hdr);
cf8cdbe5 1917 return 0;
1da177e4
LT
1918}
1919
1920/*
1921 * Encode an OPEN_CONFIRM request
1922 */
8687b63a 1923static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1da177e4
LT
1924{
1925 struct xdr_stream xdr;
1926 struct compound_hdr hdr = {
d017931c 1927 .nops = 0,
1da177e4 1928 };
1da177e4
LT
1929
1930 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1931 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5
AA
1932 encode_putfh(&xdr, args->fh, &hdr);
1933 encode_open_confirm(&xdr, args, &hdr);
d017931c 1934 encode_nops(&hdr);
cf8cdbe5 1935 return 0;
1da177e4
LT
1936}
1937
1938/*
1939 * Encode an OPEN request with no attributes.
1940 */
8687b63a 1941static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1da177e4
LT
1942{
1943 struct xdr_stream xdr;
1944 struct compound_hdr hdr = {
66cc0429 1945 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1946 };
1da177e4
LT
1947
1948 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1949 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1950 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1951 encode_putfh(&xdr, args->fh, &hdr);
1952 encode_open(&xdr, args, &hdr);
1953 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1954 encode_nops(&hdr);
cf8cdbe5 1955 return 0;
1da177e4
LT
1956}
1957
1958/*
1959 * Encode an OPEN_DOWNGRADE request
1960 */
8687b63a 1961static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1da177e4
LT
1962{
1963 struct xdr_stream xdr;
1964 struct compound_hdr hdr = {
66cc0429 1965 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1966 };
1da177e4
LT
1967
1968 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1969 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1970 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1971 encode_putfh(&xdr, args->fh, &hdr);
1972 encode_open_downgrade(&xdr, args, &hdr);
1973 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1974 encode_nops(&hdr);
cf8cdbe5 1975 return 0;
1da177e4
LT
1976}
1977
1978/*
1979 * Encode a LOCK request
1980 */
8687b63a 1981static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1da177e4
LT
1982{
1983 struct xdr_stream xdr;
1984 struct compound_hdr hdr = {
66cc0429 1985 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1986 };
1da177e4
LT
1987
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1989 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1990 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1991 encode_putfh(&xdr, args->fh, &hdr);
1992 encode_lock(&xdr, args, &hdr);
d017931c 1993 encode_nops(&hdr);
cf8cdbe5 1994 return 0;
1da177e4
LT
1995}
1996
1997/*
1998 * Encode a LOCKT request
1999 */
8687b63a 2000static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1da177e4
LT
2001{
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
66cc0429 2004 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2005 };
1da177e4
LT
2006
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2008 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2009 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2010 encode_putfh(&xdr, args->fh, &hdr);
2011 encode_lockt(&xdr, args, &hdr);
d017931c 2012 encode_nops(&hdr);
cf8cdbe5 2013 return 0;
1da177e4
LT
2014}
2015
2016/*
2017 * Encode a LOCKU request
2018 */
8687b63a 2019static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1da177e4
LT
2020{
2021 struct xdr_stream xdr;
2022 struct compound_hdr hdr = {
66cc0429 2023 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2024 };
1da177e4
LT
2025
2026 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2027 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2028 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2029 encode_putfh(&xdr, args->fh, &hdr);
2030 encode_locku(&xdr, args, &hdr);
d017931c 2031 encode_nops(&hdr);
cf8cdbe5 2032 return 0;
1da177e4
LT
2033}
2034
2035/*
2036 * Encode a READLINK request
2037 */
8687b63a 2038static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1da177e4
LT
2039{
2040 struct xdr_stream xdr;
2041 struct compound_hdr hdr = {
66cc0429 2042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2043 };
1da177e4
LT
2044
2045 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2046 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2047 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2048 encode_putfh(&xdr, args->fh, &hdr);
2049 encode_readlink(&xdr, args, req, &hdr);
e3a535e1 2050
28f56694 2051 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
e3a535e1 2052 args->pgbase, args->pglen);
d017931c 2053 encode_nops(&hdr);
cf8cdbe5 2054 return 0;
1da177e4
LT
2055}
2056
2057/*
2058 * Encode a READDIR request
2059 */
8687b63a 2060static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1da177e4
LT
2061{
2062 struct xdr_stream xdr;
2063 struct compound_hdr hdr = {
66cc0429 2064 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2065 };
1da177e4
LT
2066
2067 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2068 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2069 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2070 encode_putfh(&xdr, args->fh, &hdr);
2071 encode_readdir(&xdr, args, req, &hdr);
d6ac02df 2072
28f56694 2073 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
d6ac02df
TM
2074 args->pgbase, args->count);
2075 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
28f56694 2076 __func__, hdr.replen << 2, args->pages,
d6ac02df 2077 args->pgbase, args->count);
d017931c 2078 encode_nops(&hdr);
cf8cdbe5 2079 return 0;
1da177e4
LT
2080}
2081
2082/*
2083 * Encode a READ request
2084 */
8687b63a 2085static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1da177e4 2086{
1da177e4
LT
2087 struct xdr_stream xdr;
2088 struct compound_hdr hdr = {
66cc0429 2089 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2090 };
1da177e4
LT
2091
2092 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2093 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2094 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2095 encode_putfh(&xdr, args->fh, &hdr);
2096 encode_read(&xdr, args, &hdr);
1da177e4 2097
28f56694 2098 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
1da177e4 2099 args->pages, args->pgbase, args->count);
4f22ccc3 2100 req->rq_rcv_buf.flags |= XDRBUF_READ;
d017931c 2101 encode_nops(&hdr);
cf8cdbe5 2102 return 0;
1da177e4
LT
2103}
2104
2105/*
2106 * Encode an SETATTR request
2107 */
8687b63a 2108static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1da177e4 2109{
05d564fe
AA
2110 struct xdr_stream xdr;
2111 struct compound_hdr hdr = {
66cc0429 2112 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 2113 };
05d564fe
AA
2114
2115 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2116 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2117 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2118 encode_putfh(&xdr, args->fh, &hdr);
2119 encode_setattr(&xdr, args, args->server, &hdr);
2120 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2121 encode_nops(&hdr);
cf8cdbe5 2122 return 0;
1da177e4
LT
2123}
2124
029d105e
BF
2125/*
2126 * Encode a GETACL request
2127 */
2128static int
8687b63a 2129nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
029d105e
BF
2130 struct nfs_getaclargs *args)
2131{
2132 struct xdr_stream xdr;
029d105e 2133 struct compound_hdr hdr = {
66cc0429 2134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
029d105e 2135 };
28f56694 2136 uint32_t replen;
029d105e
BF
2137
2138 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2139 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2140 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5 2141 encode_putfh(&xdr, args->fh, &hdr);
28f56694 2142 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
cf8cdbe5
AA
2143 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2144
28f56694 2145 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
029d105e 2146 args->acl_pages, args->acl_pgbase, args->acl_len);
d017931c 2147 encode_nops(&hdr);
cf8cdbe5 2148 return 0;
029d105e
BF
2149}
2150
1da177e4
LT
2151/*
2152 * Encode a WRITE request
2153 */
8687b63a 2154static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1da177e4
LT
2155{
2156 struct xdr_stream xdr;
2157 struct compound_hdr hdr = {
66cc0429 2158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2159 };
1da177e4
LT
2160
2161 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2162 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2163 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2164 encode_putfh(&xdr, args->fh, &hdr);
2165 encode_write(&xdr, args, &hdr);
4f22ccc3 2166 req->rq_snd_buf.flags |= XDRBUF_WRITE;
cf8cdbe5 2167 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2168 encode_nops(&hdr);
cf8cdbe5 2169 return 0;
1da177e4
LT
2170}
2171
2172/*
2173 * a COMMIT request
2174 */
8687b63a 2175static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1da177e4
LT
2176{
2177 struct xdr_stream xdr;
2178 struct compound_hdr hdr = {
66cc0429 2179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2180 };
1da177e4
LT
2181
2182 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2183 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2184 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2185 encode_putfh(&xdr, args->fh, &hdr);
2186 encode_commit(&xdr, args, &hdr);
2187 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2188 encode_nops(&hdr);
cf8cdbe5 2189 return 0;
1da177e4
LT
2190}
2191
2192/*
2193 * FSINFO request
2194 */
8687b63a 2195static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1da177e4
LT
2196{
2197 struct xdr_stream xdr;
2198 struct compound_hdr hdr = {
66cc0429 2199 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2200 };
1da177e4
LT
2201
2202 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2203 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2204 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2205 encode_putfh(&xdr, args->fh, &hdr);
2206 encode_fsinfo(&xdr, args->bitmask, &hdr);
d017931c 2207 encode_nops(&hdr);
cf8cdbe5 2208 return 0;
1da177e4
LT
2209}
2210
2211/*
2212 * a PATHCONF request
2213 */
8687b63a 2214static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1da177e4 2215{
1da177e4
LT
2216 struct xdr_stream xdr;
2217 struct compound_hdr hdr = {
66cc0429 2218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2219 };
1da177e4
LT
2220
2221 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2222 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2223 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2224 encode_putfh(&xdr, args->fh, &hdr);
2225 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2226 &hdr);
d017931c 2227 encode_nops(&hdr);
cf8cdbe5 2228 return 0;
1da177e4
LT
2229}
2230
2231/*
2232 * a STATFS request
2233 */
8687b63a 2234static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1da177e4 2235{
1da177e4
LT
2236 struct xdr_stream xdr;
2237 struct compound_hdr hdr = {
66cc0429 2238 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2239 };
1da177e4
LT
2240
2241 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2242 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2243 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2244 encode_putfh(&xdr, args->fh, &hdr);
2245 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2246 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
d017931c 2247 encode_nops(&hdr);
cf8cdbe5 2248 return 0;
1da177e4
LT
2249}
2250
2251/*
2252 * GETATTR_BITMAP request
2253 */
43652ad5
BH
2254static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2255 struct nfs4_server_caps_arg *args)
1da177e4
LT
2256{
2257 struct xdr_stream xdr;
2258 struct compound_hdr hdr = {
66cc0429 2259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2260 };
1da177e4
LT
2261
2262 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2263 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2264 encode_sequence(&xdr, &args->seq_args, &hdr);
43652ad5 2265 encode_putfh(&xdr, args->fhandle, &hdr);
cf8cdbe5
AA
2266 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2267 FATTR4_WORD0_LINK_SUPPORT|
2268 FATTR4_WORD0_SYMLINK_SUPPORT|
2269 FATTR4_WORD0_ACLSUPPORT, &hdr);
d017931c 2270 encode_nops(&hdr);
cf8cdbe5 2271 return 0;
1da177e4
LT
2272}
2273
2274/*
2275 * a RENEW request
2276 */
8687b63a 2277static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1da177e4
LT
2278{
2279 struct xdr_stream xdr;
2280 struct compound_hdr hdr = {
d017931c 2281 .nops = 0,
1da177e4
LT
2282 };
2283
2284 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2285 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5 2286 encode_renew(&xdr, clp, &hdr);
d017931c 2287 encode_nops(&hdr);
cf8cdbe5 2288 return 0;
1da177e4
LT
2289}
2290
2291/*
2292 * a SETCLIENTID request
2293 */
8687b63a 2294static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1da177e4
LT
2295{
2296 struct xdr_stream xdr;
2297 struct compound_hdr hdr = {
d017931c 2298 .nops = 0,
1da177e4
LT
2299 };
2300
2301 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2302 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5 2303 encode_setclientid(&xdr, sc, &hdr);
d017931c 2304 encode_nops(&hdr);
cf8cdbe5 2305 return 0;
1da177e4
LT
2306}
2307
2308/*
2309 * a SETCLIENTID_CONFIRM request
2310 */
8687b63a 2311static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1da177e4
LT
2312{
2313 struct xdr_stream xdr;
2314 struct compound_hdr hdr = {
d017931c 2315 .nops = 0,
1da177e4
LT
2316 };
2317 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1da177e4
LT
2318
2319 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2320 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5
AA
2321 encode_setclientid_confirm(&xdr, clp, &hdr);
2322 encode_putrootfh(&xdr, &hdr);
2323 encode_fsinfo(&xdr, lease_bitmap, &hdr);
d017931c 2324 encode_nops(&hdr);
cf8cdbe5 2325 return 0;
1da177e4
LT
2326}
2327
2328/*
2329 * DELEGRETURN request
2330 */
8687b63a 2331static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
1da177e4
LT
2332{
2333 struct xdr_stream xdr;
2334 struct compound_hdr hdr = {
66cc0429 2335 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2336 };
1da177e4
LT
2337
2338 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2339 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2340 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2341 encode_putfh(&xdr, args->fhandle, &hdr);
2342 encode_delegreturn(&xdr, args->stateid, &hdr);
2343 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2344 encode_nops(&hdr);
cf8cdbe5 2345 return 0;
1da177e4
LT
2346}
2347
683b57b4
TM
2348/*
2349 * Encode FS_LOCATIONS request
2350 */
8687b63a 2351static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
683b57b4
TM
2352{
2353 struct xdr_stream xdr;
2354 struct compound_hdr hdr = {
66cc0429 2355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
683b57b4 2356 };
28f56694 2357 uint32_t replen;
683b57b4
TM
2358
2359 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2360 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2361 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2362 encode_putfh(&xdr, args->dir_fh, &hdr);
2363 encode_lookup(&xdr, args->name, &hdr);
28f56694 2364 replen = hdr.replen; /* get the attribute into args->page */
cf8cdbe5
AA
2365 encode_fs_locations(&xdr, args->bitmask, &hdr);
2366
28f56694 2367 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
683b57b4 2368 0, PAGE_SIZE);
d017931c 2369 encode_nops(&hdr);
cf8cdbe5 2370 return 0;
683b57b4
TM
2371}
2372
99fe60d0
BH
2373#if defined(CONFIG_NFS_V4_1)
2374/*
2375 * EXCHANGE_ID request
2376 */
2377static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2378 struct nfs41_exchange_id_args *args)
2379{
2380 struct xdr_stream xdr;
2381 struct compound_hdr hdr = {
2382 .minorversion = args->client->cl_minorversion,
2383 };
2384
2385 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2386 encode_compound_hdr(&xdr, req, &hdr);
2387 encode_exchange_id(&xdr, args, &hdr);
2388 encode_nops(&hdr);
2389 return 0;
2390}
2050f0cc 2391
fc931582
AA
2392/*
2393 * a CREATE_SESSION request
2394 */
2395static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2396 struct nfs41_create_session_args *args)
2397{
2398 struct xdr_stream xdr;
2399 struct compound_hdr hdr = {
2400 .minorversion = args->client->cl_minorversion,
2401 };
2402
2403 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2404 encode_compound_hdr(&xdr, req, &hdr);
2405 encode_create_session(&xdr, args, &hdr);
2406 encode_nops(&hdr);
2407 return 0;
2408}
2409
0f3e66c6
AA
2410/*
2411 * a DESTROY_SESSION request
2412 */
2413static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2414 struct nfs4_session *session)
2415{
2416 struct xdr_stream xdr;
2417 struct compound_hdr hdr = {
2418 .minorversion = session->clp->cl_minorversion,
2419 };
2420
2421 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2422 encode_compound_hdr(&xdr, req, &hdr);
2423 encode_destroy_session(&xdr, session, &hdr);
2424 encode_nops(&hdr);
2425 return 0;
2426}
2427
fc01cea9
AA
2428/*
2429 * a SEQUENCE request
2430 */
2431static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2432 struct nfs4_sequence_args *args)
2433{
2434 struct xdr_stream xdr;
2435 struct compound_hdr hdr = {
2436 .minorversion = nfs4_xdr_minorversion(args),
2437 };
2438
2439 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2440 encode_compound_hdr(&xdr, req, &hdr);
2441 encode_sequence(&xdr, args, &hdr);
2442 encode_nops(&hdr);
2443 return 0;
2444}
2445
2050f0cc
AA
2446/*
2447 * a GET_LEASE_TIME request
2448 */
2449static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2450 struct nfs4_get_lease_time_args *args)
2451{
2452 struct xdr_stream xdr;
2453 struct compound_hdr hdr = {
2454 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2455 };
2456 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2457
2458 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2459 encode_compound_hdr(&xdr, req, &hdr);
2460 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2461 encode_putrootfh(&xdr, &hdr);
2462 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2463 encode_nops(&hdr);
2464 return 0;
2465}
99fe60d0
BH
2466#endif /* CONFIG_NFS_V4_1 */
2467
1da177e4
LT
2468/*
2469 * START OF "GENERIC" DECODE ROUTINES.
2470 * These may look a little ugly since they are imported from a "generic"
2471 * set of XDR encode/decode routines which are intended to be shared by
2472 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2473 *
2474 * If the pain of reading these is too great, it should be a straightforward
2475 * task to translate them into Linux-specific versions which are more
2476 * consistent with the style used in NFSv2/v3...
2477 */
2478#define READ32(x) (x) = ntohl(*p++)
2479#define READ64(x) do { \
2480 (x) = (u64)ntohl(*p++) << 32; \
2481 (x) |= ntohl(*p++); \
2482} while (0)
2483#define READTIME(x) do { \
2484 p++; \
2485 (x.tv_sec) = ntohl(*p++); \
2486 (x.tv_nsec) = ntohl(*p++); \
2487} while (0)
2488#define COPYMEM(x,nbytes) do { \
2489 memcpy((x), p, nbytes); \
2490 p += XDR_QUADLEN(nbytes); \
2491} while (0)
2492
2493#define READ_BUF(nbytes) do { \
2494 p = xdr_inline_decode(xdr, nbytes); \
e4cc6ee2 2495 if (unlikely(!p)) { \
fe82a183 2496 dprintk("nfs: %s: prematurely hit end of receive" \
3110ff80 2497 " buffer\n", __func__); \
fe82a183 2498 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
3110ff80 2499 __func__, xdr->p, nbytes, xdr->end); \
1da177e4
LT
2500 return -EIO; \
2501 } \
2502} while (0)
2503
683b57b4 2504static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
1da177e4 2505{
8687b63a 2506 __be32 *p;
1da177e4
LT
2507
2508 READ_BUF(4);
2509 READ32(*len);
2510 READ_BUF(*len);
2511 *string = (char *)p;
2512 return 0;
2513}
2514
2515static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2516{
8687b63a 2517 __be32 *p;
1da177e4
LT
2518
2519 READ_BUF(8);
2520 READ32(hdr->status);
2521 READ32(hdr->taglen);
6c0195a4 2522
1da177e4
LT
2523 READ_BUF(hdr->taglen + 4);
2524 hdr->tag = (char *)p;
2525 p += XDR_QUADLEN(hdr->taglen);
2526 READ32(hdr->nops);
aadf6152
BH
2527 if (unlikely(hdr->nops < 1))
2528 return nfs4_stat_to_errno(hdr->status);
1da177e4
LT
2529 return 0;
2530}
2531
2532static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2533{
8687b63a 2534 __be32 *p;
1da177e4
LT
2535 uint32_t opnum;
2536 int32_t nfserr;
2537
2538 READ_BUF(8);
2539 READ32(opnum);
2540 if (opnum != expected) {
fe82a183
CL
2541 dprintk("nfs: Server returned operation"
2542 " %d but we issued a request for %d\n",
1da177e4
LT
2543 opnum, expected);
2544 return -EIO;
2545 }
2546 READ32(nfserr);
2547 if (nfserr != NFS_OK)
856dff3d 2548 return nfs4_stat_to_errno(nfserr);
1da177e4
LT
2549 return 0;
2550}
2551
2552/* Dummy routine */
adfa6f98 2553static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
1da177e4 2554{
8687b63a 2555 __be32 *p;
683b57b4 2556 unsigned int strlen;
1da177e4
LT
2557 char *str;
2558
2559 READ_BUF(12);
2560 return decode_opaque_inline(xdr, &strlen, &str);
2561}
2562
2563static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2564{
8687b63a
AV
2565 uint32_t bmlen;
2566 __be32 *p;
1da177e4
LT
2567
2568 READ_BUF(4);
2569 READ32(bmlen);
2570
2571 bitmap[0] = bitmap[1] = 0;
2572 READ_BUF((bmlen << 2));
2573 if (bmlen > 0) {
2574 READ32(bitmap[0]);
2575 if (bmlen > 1)
2576 READ32(bitmap[1]);
2577 }
2578 return 0;
2579}
2580
8687b63a 2581static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
1da177e4 2582{
8687b63a 2583 __be32 *p;
1da177e4
LT
2584
2585 READ_BUF(4);
2586 READ32(*attrlen);
2587 *savep = xdr->p;
2588 return 0;
2589}
2590
2591static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2592{
2593 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2594 decode_attr_bitmap(xdr, bitmask);
2595 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2596 } else
2597 bitmask[0] = bitmask[1] = 0;
44109241 2598 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
1da177e4
LT
2599 return 0;
2600}
2601
2602static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2603{
8687b63a 2604 __be32 *p;
409924e4 2605 int ret = 0;
1da177e4
LT
2606
2607 *type = 0;
2608 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2609 return -EIO;
2610 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2611 READ_BUF(4);
2612 READ32(*type);
2613 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3110ff80 2614 dprintk("%s: bad type %d\n", __func__, *type);
1da177e4
LT
2615 return -EIO;
2616 }
2617 bitmap[0] &= ~FATTR4_WORD0_TYPE;
409924e4 2618 ret = NFS_ATTR_FATTR_TYPE;
1da177e4 2619 }
bca79478 2620 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
409924e4 2621 return ret;
1da177e4
LT
2622}
2623
2624static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2625{
8687b63a 2626 __be32 *p;
409924e4 2627 int ret = 0;
1da177e4
LT
2628
2629 *change = 0;
2630 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2631 return -EIO;
2632 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2633 READ_BUF(8);
2634 READ64(*change);
2635 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
409924e4 2636 ret = NFS_ATTR_FATTR_CHANGE;
1da177e4 2637 }
3110ff80 2638 dprintk("%s: change attribute=%Lu\n", __func__,
1da177e4 2639 (unsigned long long)*change);
409924e4 2640 return ret;
1da177e4
LT
2641}
2642
2643static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2644{
8687b63a 2645 __be32 *p;
409924e4 2646 int ret = 0;
1da177e4
LT
2647
2648 *size = 0;
2649 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2650 return -EIO;
2651 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2652 READ_BUF(8);
2653 READ64(*size);
2654 bitmap[0] &= ~FATTR4_WORD0_SIZE;
409924e4 2655 ret = NFS_ATTR_FATTR_SIZE;
1da177e4 2656 }
3110ff80 2657 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
409924e4 2658 return ret;
1da177e4
LT
2659}
2660
2661static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2662{
8687b63a 2663 __be32 *p;
1da177e4
LT
2664
2665 *res = 0;
2666 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2667 return -EIO;
2668 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2669 READ_BUF(4);
2670 READ32(*res);
2671 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2672 }
3110ff80 2673 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
1da177e4
LT
2674 return 0;
2675}
2676
2677static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2678{
8687b63a 2679 __be32 *p;
1da177e4
LT
2680
2681 *res = 0;
2682 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2683 return -EIO;
2684 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2685 READ_BUF(4);
2686 READ32(*res);
2687 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2688 }
3110ff80 2689 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
1da177e4
LT
2690 return 0;
2691}
2692
8b4bdcf8 2693static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
1da177e4 2694{
8687b63a 2695 __be32 *p;
409924e4 2696 int ret = 0;
1da177e4
LT
2697
2698 fsid->major = 0;
2699 fsid->minor = 0;
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2701 return -EIO;
2702 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2703 READ_BUF(16);
2704 READ64(fsid->major);
2705 READ64(fsid->minor);
2706 bitmap[0] &= ~FATTR4_WORD0_FSID;
409924e4 2707 ret = NFS_ATTR_FATTR_FSID;
1da177e4 2708 }
3110ff80 2709 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
1da177e4
LT
2710 (unsigned long long)fsid->major,
2711 (unsigned long long)fsid->minor);
409924e4 2712 return ret;
1da177e4
LT
2713}
2714
2715static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2716{
8687b63a 2717 __be32 *p;
1da177e4
LT
2718
2719 *res = 60;
2720 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2721 return -EIO;
2722 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2723 READ_BUF(4);
2724 READ32(*res);
2725 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2726 }
3110ff80 2727 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
1da177e4
LT
2728 return 0;
2729}
2730
2731static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2732{
8687b63a 2733 __be32 *p;
1da177e4
LT
2734
2735 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2736 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2737 return -EIO;
2738 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2739 READ_BUF(4);
2740 READ32(*res);
2741 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2742 }
3110ff80 2743 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
1da177e4
LT
2744 return 0;
2745}
2746
2747static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2748{
8687b63a 2749 __be32 *p;
409924e4 2750 int ret = 0;
1da177e4
LT
2751
2752 *fileid = 0;
2753 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2754 return -EIO;
2755 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2756 READ_BUF(8);
2757 READ64(*fileid);
2758 bitmap[0] &= ~FATTR4_WORD0_FILEID;
409924e4 2759 ret = NFS_ATTR_FATTR_FILEID;
1da177e4 2760 }
3110ff80 2761 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
409924e4 2762 return ret;
1da177e4
LT
2763}
2764
99baf625
MN
2765static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2766{
8687b63a 2767 __be32 *p;
409924e4 2768 int ret = 0;
99baf625
MN
2769
2770 *fileid = 0;
2771 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2772 return -EIO;
2773 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2774 READ_BUF(8);
2775 READ64(*fileid);
2776 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
409924e4 2777 ret = NFS_ATTR_FATTR_FILEID;
99baf625 2778 }
3110ff80 2779 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
409924e4 2780 return ret;
99baf625
MN
2781}
2782
1da177e4
LT
2783static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2784{
8687b63a 2785 __be32 *p;
1da177e4
LT
2786 int status = 0;
2787
2788 *res = 0;
2789 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2790 return -EIO;
2791 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2792 READ_BUF(8);
2793 READ64(*res);
2794 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2795 }
3110ff80 2796 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
2797 return status;
2798}
2799
2800static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2801{
8687b63a 2802 __be32 *p;
1da177e4
LT
2803 int status = 0;
2804
2805 *res = 0;
2806 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2807 return -EIO;
2808 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2809 READ_BUF(8);
2810 READ64(*res);
2811 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2812 }
3110ff80 2813 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
2814 return status;
2815}
2816
2817static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2818{
8687b63a 2819 __be32 *p;
1da177e4
LT
2820 int status = 0;
2821
2822 *res = 0;
2823 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2824 return -EIO;
2825 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2826 READ_BUF(8);
2827 READ64(*res);
2828 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2829 }
3110ff80 2830 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
2831 return status;
2832}
2833
7aaa0b3b
MN
2834static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2835{
464ad6b1 2836 u32 n;
8687b63a 2837 __be32 *p;
7aaa0b3b
MN
2838 int status = 0;
2839
2840 READ_BUF(4);
2841 READ32(n);
33a43f28
AA
2842 if (n == 0)
2843 goto root_path;
7aaa0b3b
MN
2844 dprintk("path ");
2845 path->ncomponents = 0;
2846 while (path->ncomponents < n) {
2847 struct nfs4_string *component = &path->components[path->ncomponents];
2848 status = decode_opaque_inline(xdr, &component->len, &component->data);
2849 if (unlikely(status != 0))
2850 goto out_eio;
2851 if (path->ncomponents != n)
2852 dprintk("/");
2853 dprintk("%s", component->data);
2854 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2855 path->ncomponents++;
2856 else {
2857 dprintk("cannot parse %d components in path\n", n);
2858 goto out_eio;
2859 }
2860 }
2861out:
2862 dprintk("\n");
2863 return status;
33a43f28
AA
2864root_path:
2865/* a root pathname is sent as a zero component4 */
2866 path->ncomponents = 1;
2867 path->components[0].len=0;
2868 path->components[0].data=NULL;
2869 dprintk("path /\n");
2870 goto out;
7aaa0b3b
MN
2871out_eio:
2872 dprintk(" status %d", status);
2873 status = -EIO;
2874 goto out;
2875}
2876
2877static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
683b57b4
TM
2878{
2879 int n;
8687b63a 2880 __be32 *p;
683b57b4
TM
2881 int status = -EIO;
2882
2883 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2884 goto out;
2885 status = 0;
2886 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2887 goto out;
3110ff80 2888 dprintk("%s: fsroot ", __func__);
7aaa0b3b 2889 status = decode_pathname(xdr, &res->fs_path);
683b57b4
TM
2890 if (unlikely(status != 0))
2891 goto out;
2892 READ_BUF(4);
2893 READ32(n);
2894 if (n <= 0)
2895 goto out_eio;
2896 res->nlocations = 0;
2897 while (res->nlocations < n) {
464ad6b1 2898 u32 m;
7aaa0b3b 2899 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
683b57b4 2900
7aaa0b3b
MN
2901 READ_BUF(4);
2902 READ32(m);
7aaa0b3b
MN
2903
2904 loc->nservers = 0;
3110ff80 2905 dprintk("%s: servers ", __func__);
7aaa0b3b
MN
2906 while (loc->nservers < m) {
2907 struct nfs4_string *server = &loc->servers[loc->nservers];
2908 status = decode_opaque_inline(xdr, &server->len, &server->data);
2909 if (unlikely(status != 0))
2910 goto out_eio;
2911 dprintk("%s ", server->data);
2912 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2913 loc->nservers++;
2914 else {
464ad6b1
CL
2915 unsigned int i;
2916 dprintk("%s: using first %u of %u servers "
2917 "returned for location %u\n",
3110ff80 2918 __func__,
464ad6b1
CL
2919 NFS4_FS_LOCATION_MAXSERVERS,
2920 m, res->nlocations);
7aaa0b3b 2921 for (i = loc->nservers; i < m; i++) {
2e42c3e2 2922 unsigned int len;
7aaa0b3b
MN
2923 char *data;
2924 status = decode_opaque_inline(xdr, &len, &data);
2925 if (unlikely(status != 0))
2926 goto out_eio;
2927 }
2928 }
2929 }
2930 status = decode_pathname(xdr, &loc->rootpath);
683b57b4
TM
2931 if (unlikely(status != 0))
2932 goto out_eio;
7aaa0b3b 2933 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
683b57b4
TM
2934 res->nlocations++;
2935 }
409924e4
TM
2936 if (res->nlocations != 0)
2937 status = NFS_ATTR_FATTR_V4_REFERRAL;
683b57b4 2938out:
3110ff80 2939 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
683b57b4
TM
2940 return status;
2941out_eio:
2942 status = -EIO;
2943 goto out;
2944}
2945
1da177e4
LT
2946static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2947{
8687b63a 2948 __be32 *p;
1da177e4
LT
2949 int status = 0;
2950
2951 *res = 0;
2952 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2953 return -EIO;
2954 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2955 READ_BUF(8);
2956 READ64(*res);
2957 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2958 }
3110ff80 2959 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
2960 return status;
2961}
2962
2963static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2964{
8687b63a 2965 __be32 *p;
1da177e4
LT
2966 int status = 0;
2967
2968 *maxlink = 1;
2969 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2970 return -EIO;
2971 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2972 READ_BUF(4);
2973 READ32(*maxlink);
2974 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2975 }
3110ff80 2976 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
1da177e4
LT
2977 return status;
2978}
2979
2980static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2981{
8687b63a 2982 __be32 *p;
1da177e4
LT
2983 int status = 0;
2984
2985 *maxname = 1024;
2986 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2987 return -EIO;
2988 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2989 READ_BUF(4);
2990 READ32(*maxname);
2991 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2992 }
3110ff80 2993 dprintk("%s: maxname=%u\n", __func__, *maxname);
1da177e4
LT
2994 return status;
2995}
2996
2997static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2998{
8687b63a 2999 __be32 *p;
1da177e4
LT
3000 int status = 0;
3001
3002 *res = 1024;
3003 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3004 return -EIO;
3005 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3006 uint64_t maxread;
3007 READ_BUF(8);
3008 READ64(maxread);
3009 if (maxread > 0x7FFFFFFF)
3010 maxread = 0x7FFFFFFF;
3011 *res = (uint32_t)maxread;
3012 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3013 }
3110ff80 3014 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
1da177e4
LT
3015 return status;
3016}
3017
3018static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3019{
8687b63a 3020 __be32 *p;
1da177e4
LT
3021 int status = 0;
3022
3023 *res = 1024;
3024 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3025 return -EIO;
3026 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3027 uint64_t maxwrite;
3028 READ_BUF(8);
3029 READ64(maxwrite);
3030 if (maxwrite > 0x7FFFFFFF)
3031 maxwrite = 0x7FFFFFFF;
3032 *res = (uint32_t)maxwrite;
3033 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3034 }
3110ff80 3035 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
1da177e4
LT
3036 return status;
3037}
3038
bca79478 3039static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
1da177e4 3040{
bca79478 3041 uint32_t tmp;
8687b63a 3042 __be32 *p;
409924e4 3043 int ret = 0;
1da177e4
LT
3044
3045 *mode = 0;
3046 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3047 return -EIO;
3048 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3049 READ_BUF(4);
bca79478
TM
3050 READ32(tmp);
3051 *mode = tmp & ~S_IFMT;
1da177e4 3052 bitmap[1] &= ~FATTR4_WORD1_MODE;
409924e4 3053 ret = NFS_ATTR_FATTR_MODE;
1da177e4 3054 }
3110ff80 3055 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
409924e4 3056 return ret;
1da177e4
LT
3057}
3058
3059static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3060{
8687b63a 3061 __be32 *p;
409924e4 3062 int ret = 0;
1da177e4
LT
3063
3064 *nlink = 1;
3065 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3066 return -EIO;
3067 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3068 READ_BUF(4);
3069 READ32(*nlink);
3070 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
409924e4 3071 ret = NFS_ATTR_FATTR_NLINK;
1da177e4 3072 }
3110ff80 3073 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
409924e4 3074 return ret;
1da177e4
LT
3075}
3076
2e42c3e2 3077static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
1da177e4 3078{
8687b63a
AV
3079 uint32_t len;
3080 __be32 *p;
409924e4 3081 int ret = 0;
1da177e4
LT
3082
3083 *uid = -2;
3084 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3085 return -EIO;
3086 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3087 READ_BUF(4);
3088 READ32(len);
3089 READ_BUF(len);
3090 if (len < XDR_MAX_NETOBJ) {
409924e4
TM
3091 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3092 ret = NFS_ATTR_FATTR_OWNER;
3093 else
1da177e4 3094 dprintk("%s: nfs_map_name_to_uid failed!\n",
3110ff80 3095 __func__);
1da177e4 3096 } else
fe82a183 3097 dprintk("%s: name too long (%u)!\n",
3110ff80 3098 __func__, len);
1da177e4
LT
3099 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3100 }
3110ff80 3101 dprintk("%s: uid=%d\n", __func__, (int)*uid);
409924e4 3102 return ret;
1da177e4
LT
3103}
3104
2e42c3e2 3105static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
1da177e4 3106{
8687b63a
AV
3107 uint32_t len;
3108 __be32 *p;
409924e4 3109 int ret = 0;
1da177e4
LT
3110
3111 *gid = -2;
3112 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3113 return -EIO;
3114 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3115 READ_BUF(4);
3116 READ32(len);
3117 READ_BUF(len);
3118 if (len < XDR_MAX_NETOBJ) {
409924e4
TM
3119 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3120 ret = NFS_ATTR_FATTR_GROUP;
3121 else
1da177e4 3122 dprintk("%s: nfs_map_group_to_gid failed!\n",
3110ff80 3123 __func__);
1da177e4 3124 } else
fe82a183 3125 dprintk("%s: name too long (%u)!\n",
3110ff80 3126 __func__, len);
1da177e4
LT
3127 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3128 }
3110ff80 3129 dprintk("%s: gid=%d\n", __func__, (int)*gid);
409924e4 3130 return ret;
1da177e4
LT
3131}
3132
3133static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3134{
8687b63a
AV
3135 uint32_t major = 0, minor = 0;
3136 __be32 *p;
409924e4 3137 int ret = 0;
1da177e4
LT
3138
3139 *rdev = MKDEV(0,0);
3140 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3141 return -EIO;
3142 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3143 dev_t tmp;
3144
3145 READ_BUF(8);
3146 READ32(major);
3147 READ32(minor);
3148 tmp = MKDEV(major, minor);
3149 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3150 *rdev = tmp;
3151 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
409924e4 3152 ret = NFS_ATTR_FATTR_RDEV;
1da177e4 3153 }
3110ff80 3154 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
409924e4 3155 return ret;
1da177e4
LT
3156}
3157
3158static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3159{
8687b63a 3160 __be32 *p;
1da177e4
LT
3161 int status = 0;
3162
3163 *res = 0;
3164 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3165 return -EIO;
3166 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3167 READ_BUF(8);
3168 READ64(*res);
3169 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3170 }
3110ff80 3171 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
3172 return status;
3173}
3174
3175static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3176{
8687b63a 3177 __be32 *p;
1da177e4
LT
3178 int status = 0;
3179
3180 *res = 0;
3181 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3182 return -EIO;
3183 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3184 READ_BUF(8);
3185 READ64(*res);
3186 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3187 }
3110ff80 3188 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
3189 return status;
3190}
3191
3192static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3193{
8687b63a 3194 __be32 *p;
1da177e4
LT
3195 int status = 0;
3196
3197 *res = 0;
3198 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3199 return -EIO;
3200 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3201 READ_BUF(8);
3202 READ64(*res);
3203 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3204 }
3110ff80 3205 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
1da177e4
LT
3206 return status;
3207}
3208
3209static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3210{
8687b63a 3211 __be32 *p;
409924e4 3212 int ret = 0;
1da177e4
LT
3213
3214 *used = 0;
3215 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3216 return -EIO;
3217 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3218 READ_BUF(8);
3219 READ64(*used);
3220 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
409924e4 3221 ret = NFS_ATTR_FATTR_SPACE_USED;
1da177e4 3222 }
3110ff80 3223 dprintk("%s: space used=%Lu\n", __func__,
1da177e4 3224 (unsigned long long)*used);
409924e4 3225 return ret;
1da177e4
LT
3226}
3227
3228static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3229{
8687b63a 3230 __be32 *p;
1da177e4
LT
3231 uint64_t sec;
3232 uint32_t nsec;
3233
3234 READ_BUF(12);
3235 READ64(sec);
3236 READ32(nsec);
3237 time->tv_sec = (time_t)sec;
3238 time->tv_nsec = (long)nsec;
3239 return 0;
3240}
3241
3242static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3243{
3244 int status = 0;
3245
3246 time->tv_sec = 0;
3247 time->tv_nsec = 0;
3248 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3249 return -EIO;
3250 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3251 status = decode_attr_time(xdr, time);
409924e4
TM
3252 if (status == 0)
3253 status = NFS_ATTR_FATTR_ATIME;
1da177e4
LT
3254 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3255 }
3110ff80 3256 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
3257 return status;
3258}
3259
3260static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3261{
3262 int status = 0;
3263
3264 time->tv_sec = 0;
3265 time->tv_nsec = 0;
3266 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3267 return -EIO;
3268 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3269 status = decode_attr_time(xdr, time);
409924e4
TM
3270 if (status == 0)
3271 status = NFS_ATTR_FATTR_CTIME;
1da177e4
LT
3272 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3273 }
3110ff80 3274 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
3275 return status;
3276}
3277
3278static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3279{
3280 int status = 0;
3281
3282 time->tv_sec = 0;
3283 time->tv_nsec = 0;
3284 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3285 return -EIO;
3286 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3287 status = decode_attr_time(xdr, time);
409924e4
TM
3288 if (status == 0)
3289 status = NFS_ATTR_FATTR_MTIME;
1da177e4
LT
3290 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3291 }
3110ff80 3292 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
3293 return status;
3294}
3295
8687b63a 3296static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
1da177e4
LT
3297{
3298 unsigned int attrwords = XDR_QUADLEN(attrlen);
3299 unsigned int nwords = xdr->p - savep;
3300
3301 if (unlikely(attrwords != nwords)) {
fe82a183
CL
3302 dprintk("%s: server returned incorrect attribute length: "
3303 "%u %c %u\n",
3110ff80 3304 __func__,
1da177e4
LT
3305 attrwords << 2,
3306 (attrwords < nwords) ? '<' : '>',
3307 nwords << 2);
3308 return -EIO;
3309 }
3310 return 0;
3311}
3312
3313static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3314{
8687b63a 3315 __be32 *p;
1da177e4
LT
3316
3317 READ_BUF(20);
3318 READ32(cinfo->atomic);
3319 READ64(cinfo->before);
3320 READ64(cinfo->after);
3321 return 0;
3322}
3323
3324static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3325{
8687b63a 3326 __be32 *p;
1da177e4
LT
3327 uint32_t supp, acc;
3328 int status;
3329
3330 status = decode_op_hdr(xdr, OP_ACCESS);
3331 if (status)
3332 return status;
3333 READ_BUF(8);
3334 READ32(supp);
3335 READ32(acc);
3336 access->supported = supp;
3337 access->access = acc;
3338 return 0;
3339}
3340
3341static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3342{
8687b63a 3343 __be32 *p;
1da177e4
LT
3344 int status;
3345
3346 status = decode_op_hdr(xdr, OP_CLOSE);
c1d51931
TM
3347 if (status != -EIO)
3348 nfs_increment_open_seqid(status, res->seqid);
1da177e4
LT
3349 if (status)
3350 return status;
8ae20abd
TM
3351 READ_BUF(NFS4_STATEID_SIZE);
3352 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
1da177e4
LT
3353 return 0;
3354}
3355
3356static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3357{
8687b63a 3358 __be32 *p;
1da177e4
LT
3359 int status;
3360
3361 status = decode_op_hdr(xdr, OP_COMMIT);
3362 if (status)
3363 return status;
3364 READ_BUF(8);
3365 COPYMEM(res->verf->verifier, 8);
3366 return 0;
3367}
3368
3369static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3370{
8687b63a 3371 __be32 *p;
1da177e4
LT
3372 uint32_t bmlen;
3373 int status;
3374
3375 status = decode_op_hdr(xdr, OP_CREATE);
3376 if (status)
3377 return status;
3378 if ((status = decode_change_info(xdr, cinfo)))
3379 return status;
3380 READ_BUF(4);
3381 READ32(bmlen);
3382 READ_BUF(bmlen << 2);
3383 return 0;
3384}
3385
3386static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3387{
8687b63a 3388 __be32 *savep;
6c0195a4 3389 uint32_t attrlen, bitmap[2] = {0};
1da177e4
LT
3390 int status;
3391
3392 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3393 goto xdr_error;
3394 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3395 goto xdr_error;
3396 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3397 goto xdr_error;
3398 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3399 goto xdr_error;
3400 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3401 goto xdr_error;
3402 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3403 goto xdr_error;
3404 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3405 goto xdr_error;
3406 status = verify_attr_len(xdr, savep, attrlen);
3407xdr_error:
3110ff80 3408 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3409 return status;
3410}
6c0195a4 3411
1da177e4
LT
3412static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3413{
8687b63a 3414 __be32 *savep;
6c0195a4 3415 uint32_t attrlen, bitmap[2] = {0};
1da177e4 3416 int status;
6c0195a4 3417
1da177e4
LT
3418 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3419 goto xdr_error;
3420 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3421 goto xdr_error;
3422 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3423 goto xdr_error;
3424
3425 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3426 goto xdr_error;
3427 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3428 goto xdr_error;
3429 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3430 goto xdr_error;
3431 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3432 goto xdr_error;
3433 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3434 goto xdr_error;
3435 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3436 goto xdr_error;
3437
3438 status = verify_attr_len(xdr, savep, attrlen);
3439xdr_error:
3110ff80 3440 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3441 return status;
3442}
3443
3444static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3445{
8687b63a 3446 __be32 *savep;
6c0195a4 3447 uint32_t attrlen, bitmap[2] = {0};
1da177e4 3448 int status;
6c0195a4 3449
1da177e4
LT
3450 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3451 goto xdr_error;
3452 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3453 goto xdr_error;
3454 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3455 goto xdr_error;
3456
3457 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3458 goto xdr_error;
3459 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3460 goto xdr_error;
3461
3462 status = verify_attr_len(xdr, savep, attrlen);
3463xdr_error:
3110ff80 3464 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3465 return status;
3466}
3467
3468static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3469{
8687b63a 3470 __be32 *savep;
1da177e4
LT
3471 uint32_t attrlen,
3472 bitmap[2] = {0},
3473 type;
bca79478
TM
3474 int status;
3475 umode_t fmode = 0;
99baf625 3476 uint64_t fileid;
1da177e4 3477
f26c7a78
TM
3478 status = decode_op_hdr(xdr, OP_GETATTR);
3479 if (status < 0)
1da177e4 3480 goto xdr_error;
f26c7a78
TM
3481
3482 status = decode_attr_bitmap(xdr, bitmap);
3483 if (status < 0)
1da177e4
LT
3484 goto xdr_error;
3485
f26c7a78
TM
3486 status = decode_attr_length(xdr, &attrlen, &savep);
3487 if (status < 0)
1da177e4
LT
3488 goto xdr_error;
3489
3490
f26c7a78
TM
3491 status = decode_attr_type(xdr, bitmap, &type);
3492 if (status < 0)
1da177e4 3493 goto xdr_error;
409924e4
TM
3494 fattr->mode = 0;
3495 if (status != 0) {
3496 fattr->mode |= nfs_type2fmt[type];
3497 fattr->valid |= status;
3498 }
1da177e4 3499
f26c7a78
TM
3500 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3501 if (status < 0)
1da177e4 3502 goto xdr_error;
409924e4 3503 fattr->valid |= status;
f26c7a78
TM
3504
3505 status = decode_attr_size(xdr, bitmap, &fattr->size);
3506 if (status < 0)
1da177e4 3507 goto xdr_error;
409924e4 3508 fattr->valid |= status;
f26c7a78
TM
3509
3510 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3511 if (status < 0)
1da177e4 3512 goto xdr_error;
409924e4 3513 fattr->valid |= status;
f26c7a78
TM
3514
3515 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3516 if (status < 0)
1da177e4 3517 goto xdr_error;
409924e4 3518 fattr->valid |= status;
f26c7a78
TM
3519
3520 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
7aaa0b3b 3521 struct nfs4_fs_locations,
f26c7a78
TM
3522 fattr));
3523 if (status < 0)
683b57b4 3524 goto xdr_error;
409924e4 3525 fattr->valid |= status;
f26c7a78
TM
3526
3527 status = decode_attr_mode(xdr, bitmap, &fmode);
3528 if (status < 0)
1da177e4 3529 goto xdr_error;
409924e4
TM
3530 if (status != 0) {
3531 fattr->mode |= fmode;
3532 fattr->valid |= status;
3533 }
f26c7a78
TM
3534
3535 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3536 if (status < 0)
1da177e4 3537 goto xdr_error;
409924e4 3538 fattr->valid |= status;
f26c7a78
TM
3539
3540 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3541 if (status < 0)
1da177e4 3542 goto xdr_error;
409924e4 3543 fattr->valid |= status;
f26c7a78
TM
3544
3545 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3546 if (status < 0)
1da177e4 3547 goto xdr_error;
409924e4 3548 fattr->valid |= status;
f26c7a78
TM
3549
3550 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3551 if (status < 0)
1da177e4 3552 goto xdr_error;
409924e4 3553 fattr->valid |= status;
f26c7a78
TM
3554
3555 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3556 if (status < 0)
1da177e4 3557 goto xdr_error;
409924e4 3558 fattr->valid |= status;
f26c7a78
TM
3559
3560 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3561 if (status < 0)
1da177e4 3562 goto xdr_error;
409924e4 3563 fattr->valid |= status;
f26c7a78
TM
3564
3565 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3566 if (status < 0)
1da177e4 3567 goto xdr_error;
409924e4 3568 fattr->valid |= status;
f26c7a78
TM
3569
3570 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3571 if (status < 0)
1da177e4 3572 goto xdr_error;
409924e4 3573 fattr->valid |= status;
f26c7a78
TM
3574
3575 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3576 if (status < 0)
99baf625 3577 goto xdr_error;
409924e4 3578 if (status != 0 && !(fattr->valid & status)) {
99baf625 3579 fattr->fileid = fileid;
409924e4
TM
3580 fattr->valid |= status;
3581 }
f26c7a78
TM
3582
3583 status = verify_attr_len(xdr, savep, attrlen);
1da177e4 3584xdr_error:
3110ff80 3585 dprintk("%s: xdr returned %d\n", __func__, -status);
1da177e4
LT
3586 return status;
3587}
3588
3589
3590static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3591{
8687b63a 3592 __be32 *savep;
1da177e4
LT
3593 uint32_t attrlen, bitmap[2];
3594 int status;
3595
3596 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3597 goto xdr_error;
3598 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3599 goto xdr_error;
3600 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3601 goto xdr_error;
3602
3603 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3604
3605 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3606 goto xdr_error;
3607 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3608 goto xdr_error;
3609 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3610 goto xdr_error;
3611 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3612 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3613 goto xdr_error;
3614 fsinfo->wtpref = fsinfo->wtmax;
3615
3616 status = verify_attr_len(xdr, savep, attrlen);
3617xdr_error:
3110ff80 3618 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3619 return status;
3620}
3621
3622static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3623{
8687b63a 3624 __be32 *p;
1da177e4
LT
3625 uint32_t len;
3626 int status;
3627
9936781d
TM
3628 /* Zero handle first to allow comparisons */
3629 memset(fh, 0, sizeof(*fh));
3630
1da177e4
LT
3631 status = decode_op_hdr(xdr, OP_GETFH);
3632 if (status)
3633 return status;
1da177e4
LT
3634
3635 READ_BUF(4);
3636 READ32(len);
3637 if (len > NFS4_FHSIZE)
3638 return -EIO;
3639 fh->size = len;
3640 READ_BUF(len);
3641 COPYMEM(fh->data, len);
3642 return 0;
3643}
3644
3645static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3646{
3647 int status;
6c0195a4 3648
1da177e4
LT
3649 status = decode_op_hdr(xdr, OP_LINK);
3650 if (status)
3651 return status;
3652 return decode_change_info(xdr, cinfo);
3653}
3654
3655/*
3656 * We create the owner, so we know a proper owner.id length is 4.
3657 */
911d1aaf 3658static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
1da177e4 3659{
911d1aaf 3660 uint64_t offset, length, clientid;
8687b63a 3661 __be32 *p;
911d1aaf 3662 uint32_t namelen, type;
1da177e4
LT
3663
3664 READ_BUF(32);
911d1aaf
TM
3665 READ64(offset);
3666 READ64(length);
3667 READ32(type);
3668 if (fl != NULL) {
3669 fl->fl_start = (loff_t)offset;
3670 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3671 if (length == ~(uint64_t)0)
3672 fl->fl_end = OFFSET_MAX;
3673 fl->fl_type = F_WRLCK;
3674 if (type & 1)
3675 fl->fl_type = F_RDLCK;
3676 fl->fl_pid = 0;
3677 }
3678 READ64(clientid);
1da177e4
LT
3679 READ32(namelen);
3680 READ_BUF(namelen);
1da177e4
LT
3681 return -NFS4ERR_DENIED;
3682}
3683
911d1aaf 3684static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
1da177e4 3685{
8687b63a 3686 __be32 *p;
1da177e4
LT
3687 int status;
3688
3689 status = decode_op_hdr(xdr, OP_LOCK);
c1d51931
TM
3690 if (status == -EIO)
3691 goto out;
1da177e4 3692 if (status == 0) {
8ae20abd
TM
3693 READ_BUF(NFS4_STATEID_SIZE);
3694 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
1da177e4 3695 } else if (status == -NFS4ERR_DENIED)
c1d51931
TM
3696 status = decode_lock_denied(xdr, NULL);
3697 if (res->open_seqid != NULL)
3698 nfs_increment_open_seqid(status, res->open_seqid);
3699 nfs_increment_lock_seqid(status, res->lock_seqid);
3700out:
1da177e4
LT
3701 return status;
3702}
3703
911d1aaf 3704static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
1da177e4
LT
3705{
3706 int status;
3707 status = decode_op_hdr(xdr, OP_LOCKT);
3708 if (status == -NFS4ERR_DENIED)
911d1aaf 3709 return decode_lock_denied(xdr, res->denied);
1da177e4
LT
3710 return status;
3711}
3712
911d1aaf 3713static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
1da177e4 3714{
8687b63a 3715 __be32 *p;
1da177e4
LT
3716 int status;
3717
3718 status = decode_op_hdr(xdr, OP_LOCKU);
c1d51931
TM
3719 if (status != -EIO)
3720 nfs_increment_lock_seqid(status, res->seqid);
1da177e4 3721 if (status == 0) {
8ae20abd
TM
3722 READ_BUF(NFS4_STATEID_SIZE);
3723 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
1da177e4
LT
3724 }
3725 return status;
3726}
3727
3728static int decode_lookup(struct xdr_stream *xdr)
3729{
3730 return decode_op_hdr(xdr, OP_LOOKUP);
3731}
3732
3733/* This is too sick! */
3734static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3735{
05d564fe 3736 __be32 *p;
1da177e4
LT
3737 uint32_t limit_type, nblocks, blocksize;
3738
3739 READ_BUF(12);
3740 READ32(limit_type);
3741 switch (limit_type) {
05d564fe
AA
3742 case 1:
3743 READ64(*maxsize);
3744 break;
3745 case 2:
3746 READ32(nblocks);
3747 READ32(blocksize);
3748 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
1da177e4
LT
3749 }
3750 return 0;
3751}
3752
3753static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3754{
05d564fe
AA
3755 __be32 *p;
3756 uint32_t delegation_type;
1da177e4
LT
3757
3758 READ_BUF(4);
3759 READ32(delegation_type);
3760 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3761 res->delegation_type = 0;
3762 return 0;
3763 }
8ae20abd
TM
3764 READ_BUF(NFS4_STATEID_SIZE+4);
3765 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
1da177e4 3766 READ32(res->do_recall);
05d564fe 3767
1da177e4 3768 switch (delegation_type) {
05d564fe
AA
3769 case NFS4_OPEN_DELEGATE_READ:
3770 res->delegation_type = FMODE_READ;
3771 break;
3772 case NFS4_OPEN_DELEGATE_WRITE:
3773 res->delegation_type = FMODE_WRITE|FMODE_READ;
3774 if (decode_space_limit(xdr, &res->maxsize) < 0)
1da177e4
LT
3775 return -EIO;
3776 }
7539bbab 3777 return decode_ace(xdr, NULL, res->server->nfs_client);
1da177e4
LT
3778}
3779
3780static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3781{
05d564fe 3782 __be32 *p;
aa53ed54 3783 uint32_t savewords, bmlen, i;
05d564fe 3784 int status;
1da177e4 3785
05d564fe 3786 status = decode_op_hdr(xdr, OP_OPEN);
c1d51931
TM
3787 if (status != -EIO)
3788 nfs_increment_open_seqid(status, res->seqid);
05d564fe
AA
3789 if (status)
3790 return status;
3791 READ_BUF(NFS4_STATEID_SIZE);
3792 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
1da177e4 3793
05d564fe 3794 decode_change_info(xdr, &res->cinfo);
1da177e4 3795
05d564fe
AA
3796 READ_BUF(8);
3797 READ32(res->rflags);
3798 READ32(bmlen);
3799 if (bmlen > 10)
3800 goto xdr_error;
1da177e4 3801
05d564fe 3802 READ_BUF(bmlen << 2);
aa53ed54
JL
3803 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3804 for (i = 0; i < savewords; ++i)
3805 READ32(res->attrset[i]);
3806 for (; i < NFS4_BITMAP_SIZE; i++)
3807 res->attrset[i] = 0;
3808
1da177e4
LT
3809 return decode_delegation(xdr, res);
3810xdr_error:
3110ff80 3811 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
1da177e4
LT
3812 return -EIO;
3813}
3814
3815static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3816{
05d564fe 3817 __be32 *p;
1da177e4
LT
3818 int status;
3819
05d564fe 3820 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
c1d51931
TM
3821 if (status != -EIO)
3822 nfs_increment_open_seqid(status, res->seqid);
05d564fe
AA
3823 if (status)
3824 return status;
3825 READ_BUF(NFS4_STATEID_SIZE);
3826 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3827 return 0;
1da177e4
LT
3828}
3829
3830static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3831{
8687b63a 3832 __be32 *p;
1da177e4
LT
3833 int status;
3834
3835 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
c1d51931
TM
3836 if (status != -EIO)
3837 nfs_increment_open_seqid(status, res->seqid);
1da177e4
LT
3838 if (status)
3839 return status;
8ae20abd
TM
3840 READ_BUF(NFS4_STATEID_SIZE);
3841 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
1da177e4
LT
3842 return 0;
3843}
3844
3845static int decode_putfh(struct xdr_stream *xdr)
3846{
3847 return decode_op_hdr(xdr, OP_PUTFH);
3848}
3849
3850static int decode_putrootfh(struct xdr_stream *xdr)
3851{
3852 return decode_op_hdr(xdr, OP_PUTROOTFH);
3853}
3854
3855static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3856{
3857 struct kvec *iov = req->rq_rcv_buf.head;
8687b63a 3858 __be32 *p;
1da177e4
LT
3859 uint32_t count, eof, recvd, hdrlen;
3860 int status;
3861
3862 status = decode_op_hdr(xdr, OP_READ);
3863 if (status)
3864 return status;
3865 READ_BUF(8);
3866 READ32(eof);
3867 READ32(count);
3868 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3869 recvd = req->rq_rcv_buf.len - hdrlen;
3870 if (count > recvd) {
fe82a183 3871 dprintk("NFS: server cheating in read reply: "
1da177e4
LT
3872 "count %u > recvd %u\n", count, recvd);
3873 count = recvd;
3874 eof = 0;
3875 }
3876 xdr_read_pages(xdr, count);
3877 res->eof = eof;
3878 res->count = count;
3879 return 0;
3880}
3881
3882static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3883{
3884 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3885 struct page *page = *rcvbuf->pages;
3886 struct kvec *iov = rcvbuf->head;
bcecff77
CL
3887 size_t hdrlen;
3888 u32 recvd, pglen = rcvbuf->page_len;
8687b63a 3889 __be32 *end, *entry, *p, *kaddr;
7bda2cdf 3890 unsigned int nr = 0;
bcecff77 3891 int status;
1da177e4
LT
3892
3893 status = decode_op_hdr(xdr, OP_READDIR);
3894 if (status)
3895 return status;
3896 READ_BUF(8);
3897 COPYMEM(readdir->verifier.data, 8);
44109241
FI
3898 dprintk("%s: verifier = %08x:%08x\n",
3899 __func__,
eadf4598
TM
3900 ((u32 *)readdir->verifier.data)[0],
3901 ((u32 *)readdir->verifier.data)[1]);
3902
1da177e4
LT
3903
3904 hdrlen = (char *) p - (char *) iov->iov_base;
3905 recvd = rcvbuf->len - hdrlen;
3906 if (pglen > recvd)
3907 pglen = recvd;
3908 xdr_read_pages(xdr, pglen);
3909
3910 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
8687b63a 3911 kaddr = p = kmap_atomic(page, KM_USER0);
e8896495 3912 end = p + ((pglen + readdir->pgbase) >> 2);
1da177e4 3913 entry = p;
7bda2cdf
JL
3914
3915 /* Make sure the packet actually has a value_follows and EOF entry */
3916 if ((entry + 1) > end)
3917 goto short_pkt;
3918
3919 for (; *p++; nr++) {
bcecff77 3920 u32 len, attrlen, xlen;
e8896495 3921 if (end - p < 3)
1da177e4 3922 goto short_pkt;
eadf4598 3923 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
1da177e4
LT
3924 p += 2; /* cookie */
3925 len = ntohl(*p++); /* filename length */
3926 if (len > NFS4_MAXNAMLEN) {
fe82a183
CL
3927 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3928 len);
1da177e4
LT
3929 goto err_unmap;
3930 }
e8896495
DH
3931 xlen = XDR_QUADLEN(len);
3932 if (end - p < xlen + 1)
1da177e4 3933 goto short_pkt;
e8896495
DH
3934 dprintk("filename = %*s\n", len, (char *)p);
3935 p += xlen;
1da177e4 3936 len = ntohl(*p++); /* bitmap length */
e8896495 3937 if (end - p < len + 1)
1da177e4 3938 goto short_pkt;
e8896495 3939 p += len;
1da177e4 3940 attrlen = XDR_QUADLEN(ntohl(*p++));
e8896495 3941 if (end - p < attrlen + 2)
1da177e4 3942 goto short_pkt;
e8896495 3943 p += attrlen; /* attributes */
1da177e4
LT
3944 entry = p;
3945 }
7bda2cdf
JL
3946 /*
3947 * Apparently some server sends responses that are a valid size, but
3948 * contain no entries, and have value_follows==0 and EOF==0. For
3949 * those, just set the EOF marker.
3950 */
3951 if (!nr && entry[1] == 0) {
3952 dprintk("NFS: readdir reply truncated!\n");
3953 entry[1] = 1;
3954 }
6c0195a4 3955out:
1da177e4
LT
3956 kunmap_atomic(kaddr, KM_USER0);
3957 return 0;
3958short_pkt:
7bda2cdf
JL
3959 /*
3960 * When we get a short packet there are 2 possibilities. We can
3961 * return an error, or fix up the response to look like a valid
3962 * response and return what we have so far. If there are no
3963 * entries and the packet was short, then return -EIO. If there
3964 * are valid entries in the response, return them and pretend that
3965 * the call was successful, but incomplete. The caller can retry the
3966 * readdir starting at the last cookie.
3967 */
3110ff80 3968 dprintk("%s: short packet at entry %d\n", __func__, nr);
1da177e4 3969 entry[0] = entry[1] = 0;
7bda2cdf
JL
3970 if (nr)
3971 goto out;
1da177e4
LT
3972err_unmap:
3973 kunmap_atomic(kaddr, KM_USER0);
3974 return -errno_NFSERR_IO;
3975}
3976
3977static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3978{
3979 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3980 struct kvec *iov = rcvbuf->head;
bcecff77
CL
3981 size_t hdrlen;
3982 u32 len, recvd;
8687b63a 3983 __be32 *p;
1da177e4
LT
3984 char *kaddr;
3985 int status;
3986
3987 status = decode_op_hdr(xdr, OP_READLINK);
3988 if (status)
3989 return status;
3990
3991 /* Convert length of symlink */
3992 READ_BUF(4);
3993 READ32(len);
3994 if (len >= rcvbuf->page_len || len <= 0) {
fe82a183 3995 dprintk("nfs: server returned giant symlink!\n");
1da177e4
LT
3996 return -ENAMETOOLONG;
3997 }
3998 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3999 recvd = req->rq_rcv_buf.len - hdrlen;
4000 if (recvd < len) {
fe82a183 4001 dprintk("NFS: server cheating in readlink reply: "
1da177e4
LT
4002 "count %u > recvd %u\n", len, recvd);
4003 return -EIO;
4004 }
4005 xdr_read_pages(xdr, len);
4006 /*
4007 * The XDR encode routine has set things up so that
4008 * the link text will be copied directly into the
4009 * buffer. We just have to do overflow-checking,
4010 * and and null-terminate the text (the VFS expects
4011 * null-termination).
4012 */
4013 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4014 kaddr[len+rcvbuf->page_base] = '\0';
4015 kunmap_atomic(kaddr, KM_USER0);
4016 return 0;
4017}
4018
4019static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4020{
4021 int status;
4022
4023 status = decode_op_hdr(xdr, OP_REMOVE);
4024 if (status)
4025 goto out;
4026 status = decode_change_info(xdr, cinfo);
4027out:
4028 return status;
4029}
4030
4031static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4032 struct nfs4_change_info *new_cinfo)
4033{
4034 int status;
4035
4036 status = decode_op_hdr(xdr, OP_RENAME);
4037 if (status)
4038 goto out;
4039 if ((status = decode_change_info(xdr, old_cinfo)))
4040 goto out;
4041 status = decode_change_info(xdr, new_cinfo);
4042out:
4043 return status;
4044}
4045
4046static int decode_renew(struct xdr_stream *xdr)
4047{
4048 return decode_op_hdr(xdr, OP_RENEW);
4049}
4050
56ae19f3
TM
4051static int
4052decode_restorefh(struct xdr_stream *xdr)
4053{
4054 return decode_op_hdr(xdr, OP_RESTOREFH);
4055}
4056
029d105e
BF
4057static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4058 size_t *acl_len)
4059{
8687b63a 4060 __be32 *savep;
029d105e
BF
4061 uint32_t attrlen,
4062 bitmap[2] = {0};
4063 struct kvec *iov = req->rq_rcv_buf.head;
4064 int status;
4065
4066 *acl_len = 0;
4067 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4068 goto out;
4069 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4070 goto out;
4071 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4072 goto out;
4073
4074 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4075 return -EIO;
4076 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
bcecff77
CL
4077 size_t hdrlen;
4078 u32 recvd;
029d105e
BF
4079
4080 /* We ignore &savep and don't do consistency checks on
4081 * the attr length. Let userspace figure it out.... */
4082 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4083 recvd = req->rq_rcv_buf.len - hdrlen;
4084 if (attrlen > recvd) {
fe82a183 4085 dprintk("NFS: server cheating in getattr"
029d105e
BF
4086 " acl reply: attrlen %u > recvd %u\n",
4087 attrlen, recvd);
4088 return -EINVAL;
4089 }
c04871e6 4090 xdr_read_pages(xdr, attrlen);
029d105e 4091 *acl_len = attrlen;
8c233cf9
BF
4092 } else
4093 status = -EOPNOTSUPP;
029d105e
BF
4094
4095out:
4096 return status;
4097}
4098
1da177e4
LT
4099static int
4100decode_savefh(struct xdr_stream *xdr)
4101{
4102 return decode_op_hdr(xdr, OP_SAVEFH);
4103}
4104
9e9ecc03 4105static int decode_setattr(struct xdr_stream *xdr)
1da177e4 4106{
8687b63a 4107 __be32 *p;
1da177e4
LT
4108 uint32_t bmlen;
4109 int status;
4110
1da177e4
LT
4111 status = decode_op_hdr(xdr, OP_SETATTR);
4112 if (status)
4113 return status;
4114 READ_BUF(4);
4115 READ32(bmlen);
4116 READ_BUF(bmlen << 2);
4117 return 0;
4118}
4119
adfa6f98 4120static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
1da177e4 4121{
8687b63a 4122 __be32 *p;
1da177e4
LT
4123 uint32_t opnum;
4124 int32_t nfserr;
4125
4126 READ_BUF(8);
4127 READ32(opnum);
4128 if (opnum != OP_SETCLIENTID) {
fe82a183 4129 dprintk("nfs: decode_setclientid: Server returned operation"
6c0195a4 4130 " %d\n", opnum);
1da177e4
LT
4131 return -EIO;
4132 }
4133 READ32(nfserr);
4134 if (nfserr == NFS_OK) {
8ae20abd 4135 READ_BUF(8 + NFS4_VERIFIER_SIZE);
1da177e4 4136 READ64(clp->cl_clientid);
8ae20abd 4137 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
1da177e4
LT
4138 } else if (nfserr == NFSERR_CLID_INUSE) {
4139 uint32_t len;
4140
4141 /* skip netid string */
4142 READ_BUF(4);
4143 READ32(len);
4144 READ_BUF(len);
4145
4146 /* skip uaddr string */
4147 READ_BUF(4);
4148 READ32(len);
4149 READ_BUF(len);
4150 return -NFSERR_CLID_INUSE;
4151 } else
856dff3d 4152 return nfs4_stat_to_errno(nfserr);
1da177e4
LT
4153
4154 return 0;
4155}
4156
4157static int decode_setclientid_confirm(struct xdr_stream *xdr)
4158{
4159 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4160}
4161
4162static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4163{
8687b63a 4164 __be32 *p;
1da177e4
LT
4165 int status;
4166
4167 status = decode_op_hdr(xdr, OP_WRITE);
4168 if (status)
4169 return status;
4170
4171 READ_BUF(16);
4172 READ32(res->count);
4173 READ32(res->verf->committed);
4174 COPYMEM(res->verf->verifier, 8);
4175 return 0;
4176}
4177
4178static int decode_delegreturn(struct xdr_stream *xdr)
4179{
4180 return decode_op_hdr(xdr, OP_DELEGRETURN);
4181}
4182
99fe60d0
BH
4183#if defined(CONFIG_NFS_V4_1)
4184static int decode_exchange_id(struct xdr_stream *xdr,
4185 struct nfs41_exchange_id_res *res)
4186{
4187 __be32 *p;
4188 uint32_t dummy;
4189 int status;
4190 struct nfs_client *clp = res->client;
4191
4192 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4193 if (status)
4194 return status;
4195
4196 READ_BUF(8);
4197 READ64(clp->cl_ex_clid);
4198 READ_BUF(12);
4199 READ32(clp->cl_seqid);
4200 READ32(clp->cl_exchange_flags);
4201
4202 /* We ask for SP4_NONE */
4203 READ32(dummy);
4204 if (dummy != SP4_NONE)
4205 return -EIO;
4206
4207 /* Throw away minor_id */
4208 READ_BUF(8);
4209
4210 /* Throw away Major id */
4211 READ_BUF(4);
4212 READ32(dummy);
4213 READ_BUF(dummy);
4214
4215 /* Throw away server_scope */
4216 READ_BUF(4);
4217 READ32(dummy);
4218 READ_BUF(dummy);
4219
4220 /* Throw away Implementation id array */
4221 READ_BUF(4);
4222 READ32(dummy);
4223 READ_BUF(dummy);
4224
4225 return 0;
4226}
fc931582
AA
4227
4228static int decode_chan_attrs(struct xdr_stream *xdr,
4229 struct nfs4_channel_attrs *attrs)
4230{
4231 __be32 *p;
4232 u32 nr_attrs;
4233
4234 READ_BUF(28);
4235 READ32(attrs->headerpadsz);
4236 READ32(attrs->max_rqst_sz);
4237 READ32(attrs->max_resp_sz);
4238 READ32(attrs->max_resp_sz_cached);
4239 READ32(attrs->max_ops);
4240 READ32(attrs->max_reqs);
4241 READ32(nr_attrs);
4242 if (unlikely(nr_attrs > 1)) {
4243 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4244 __func__, nr_attrs);
4245 return -EINVAL;
4246 }
4247 if (nr_attrs == 1)
4248 READ_BUF(4); /* skip rdma_attrs */
4249 return 0;
4250}
4251
4252static int decode_create_session(struct xdr_stream *xdr,
4253 struct nfs41_create_session_res *res)
4254{
4255 __be32 *p;
4256 int status;
4257 struct nfs_client *clp = res->client;
4258 struct nfs4_session *session = clp->cl_session;
4259
4260 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4261
4262 if (status)
4263 return status;
4264
4265 /* sessionid */
4266 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4267 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4268
4269 /* seqid, flags */
4270 READ_BUF(8);
4271 READ32(clp->cl_seqid);
4272 READ32(session->flags);
4273
4274 /* Channel attributes */
4275 status = decode_chan_attrs(xdr, &session->fc_attrs);
4276 if (!status)
4277 status = decode_chan_attrs(xdr, &session->bc_attrs);
4278 return status;
4279}
0f3e66c6
AA
4280
4281static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4282{
4283 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4284}
99fe60d0
BH
4285#endif /* CONFIG_NFS_V4_1 */
4286
9b7b9fcc
AA
4287static int decode_sequence(struct xdr_stream *xdr,
4288 struct nfs4_sequence_res *res,
4289 struct rpc_rqst *rqstp)
4290{
4291#if defined(CONFIG_NFS_V4_1)
fc01cea9
AA
4292 struct nfs4_slot *slot;
4293 struct nfs4_sessionid id;
4294 u32 dummy;
4295 int status;
4296 __be32 *p;
4297
9b7b9fcc
AA
4298 if (!res->sr_session)
4299 return 0;
4300
fc01cea9
AA
4301 status = decode_op_hdr(xdr, OP_SEQUENCE);
4302 if (status)
4303 goto out_err;
9b7b9fcc 4304
fc01cea9
AA
4305 /*
4306 * If the server returns different values for sessionID, slotID or
4307 * sequence number, the server is looney tunes.
4308 */
4309 status = -ESERVERFAULT;
4310
4311 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
4312 READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
4313 COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
4314 if (memcmp(id.data, res->sr_session->sess_id.data,
4315 NFS4_MAX_SESSIONID_LEN)) {
4316 dprintk("%s Invalid session id\n", __func__);
4317 goto out_err;
4318 }
4319 /* seqid */
4320 READ32(dummy);
4321 if (dummy != slot->seq_nr) {
4322 dprintk("%s Invalid sequence number\n", __func__);
4323 goto out_err;
4324 }
4325 /* slot id */
4326 READ32(dummy);
4327 if (dummy != res->sr_slotid) {
4328 dprintk("%s Invalid slot id\n", __func__);
4329 goto out_err;
4330 }
4331 /* highest slot id - currently not processed */
4332 READ32(dummy);
4333 /* target highest slot id - currently not processed */
4334 READ32(dummy);
4335 /* result flags - currently not processed */
4336 READ32(dummy);
4337 status = 0;
4338out_err:
4339 res->sr_status = status;
4340 return status;
4341#else /* CONFIG_NFS_V4_1 */
9b7b9fcc 4342 return 0;
fc01cea9 4343#endif /* CONFIG_NFS_V4_1 */
9b7b9fcc
AA
4344}
4345
49c2559e
BH
4346/*
4347 * END OF "GENERIC" DECODE ROUTINES.
4348 */
4349
1da177e4
LT
4350/*
4351 * Decode OPEN_DOWNGRADE response
4352 */
8687b63a 4353static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
1da177e4 4354{
05d564fe
AA
4355 struct xdr_stream xdr;
4356 struct compound_hdr hdr;
4357 int status;
4358
4359 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4360 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4361 if (status)
4362 goto out;
4363 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
4364 if (status)
4365 goto out;
4366 status = decode_putfh(&xdr);
4367 if (status)
4368 goto out;
4369 status = decode_open_downgrade(&xdr, res);
516a6af6
TM
4370 if (status != 0)
4371 goto out;
4372 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4 4373out:
05d564fe 4374 return status;
1da177e4
LT
4375}
4376
1da177e4
LT
4377/*
4378 * Decode ACCESS response
4379 */
8687b63a 4380static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
1da177e4
LT
4381{
4382 struct xdr_stream xdr;
4383 struct compound_hdr hdr;
4384 int status;
6c0195a4 4385
1da177e4 4386 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4387 status = decode_compound_hdr(&xdr, &hdr);
4388 if (status)
4389 goto out;
4390 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4391 if (status)
1da177e4 4392 goto out;
76b32999
TM
4393 status = decode_putfh(&xdr);
4394 if (status != 0)
4395 goto out;
4396 status = decode_access(&xdr, res);
4397 if (status != 0)
4398 goto out;
4399 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
4400out:
4401 return status;
4402}
4403
4404/*
4405 * Decode LOOKUP response
4406 */
8687b63a 4407static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
1da177e4
LT
4408{
4409 struct xdr_stream xdr;
4410 struct compound_hdr hdr;
4411 int status;
6c0195a4 4412
1da177e4 4413 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4414 status = decode_compound_hdr(&xdr, &hdr);
4415 if (status)
4416 goto out;
4417 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4418 if (status)
1da177e4
LT
4419 goto out;
4420 if ((status = decode_putfh(&xdr)) != 0)
4421 goto out;
4422 if ((status = decode_lookup(&xdr)) != 0)
4423 goto out;
4424 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4425 goto out;
4426 status = decode_getfattr(&xdr, res->fattr, res->server);
4427out:
4428 return status;
4429}
4430
4431/*
4432 * Decode LOOKUP_ROOT response
4433 */
8687b63a 4434static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
1da177e4
LT
4435{
4436 struct xdr_stream xdr;
4437 struct compound_hdr hdr;
4438 int status;
6c0195a4 4439
1da177e4 4440 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4441 status = decode_compound_hdr(&xdr, &hdr);
4442 if (status)
4443 goto out;
4444 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4445 if (status)
1da177e4
LT
4446 goto out;
4447 if ((status = decode_putrootfh(&xdr)) != 0)
4448 goto out;
4449 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4450 status = decode_getfattr(&xdr, res->fattr, res->server);
4451out:
4452 return status;
4453}
4454
4455/*
4456 * Decode REMOVE response
4457 */
4fdc17b2 4458static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
1da177e4
LT
4459{
4460 struct xdr_stream xdr;
4461 struct compound_hdr hdr;
4462 int status;
6c0195a4 4463
1da177e4 4464 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4465 status = decode_compound_hdr(&xdr, &hdr);
4466 if (status)
4467 goto out;
4468 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4469 if (status)
1da177e4 4470 goto out;
16e42959
TM
4471 if ((status = decode_putfh(&xdr)) != 0)
4472 goto out;
4473 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4474 goto out;
4fdc17b2 4475 decode_getfattr(&xdr, &res->dir_attr, res->server);
1da177e4
LT
4476out:
4477 return status;
4478}
4479
4480/*
4481 * Decode RENAME response
4482 */
8687b63a 4483static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
1da177e4
LT
4484{
4485 struct xdr_stream xdr;
4486 struct compound_hdr hdr;
4487 int status;
6c0195a4 4488
1da177e4 4489 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4490 status = decode_compound_hdr(&xdr, &hdr);
4491 if (status)
4492 goto out;
4493 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4494 if (status)
1da177e4
LT
4495 goto out;
4496 if ((status = decode_putfh(&xdr)) != 0)
4497 goto out;
4498 if ((status = decode_savefh(&xdr)) != 0)
4499 goto out;
4500 if ((status = decode_putfh(&xdr)) != 0)
4501 goto out;
6caf2c82
TM
4502 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4503 goto out;
4504 /* Current FH is target directory */
4505 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4506 goto out;
4507 if ((status = decode_restorefh(&xdr)) != 0)
4508 goto out;
4509 decode_getfattr(&xdr, res->old_fattr, res->server);
1da177e4
LT
4510out:
4511 return status;
4512}
4513
4514/*
4515 * Decode LINK response
4516 */
8687b63a 4517static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
1da177e4
LT
4518{
4519 struct xdr_stream xdr;
4520 struct compound_hdr hdr;
4521 int status;
6c0195a4 4522
1da177e4 4523 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4524 status = decode_compound_hdr(&xdr, &hdr);
4525 if (status)
4526 goto out;
4527 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4528 if (status)
1da177e4
LT
4529 goto out;
4530 if ((status = decode_putfh(&xdr)) != 0)
4531 goto out;
4532 if ((status = decode_savefh(&xdr)) != 0)
4533 goto out;
4534 if ((status = decode_putfh(&xdr)) != 0)
4535 goto out;
91ba2eee
TM
4536 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4537 goto out;
4538 /*
4539 * Note order: OP_LINK leaves the directory as the current
4540 * filehandle.
4541 */
4542 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4543 goto out;
4544 if ((status = decode_restorefh(&xdr)) != 0)
4545 goto out;
4546 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
4547out:
4548 return status;
4549}
4550
4551/*
4552 * Decode CREATE response
4553 */
8687b63a 4554static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
1da177e4
LT
4555{
4556 struct xdr_stream xdr;
4557 struct compound_hdr hdr;
4558 int status;
6c0195a4 4559
1da177e4 4560 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4561 status = decode_compound_hdr(&xdr, &hdr);
4562 if (status)
4563 goto out;
4564 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4565 if (status)
1da177e4
LT
4566 goto out;
4567 if ((status = decode_putfh(&xdr)) != 0)
4568 goto out;
56ae19f3
TM
4569 if ((status = decode_savefh(&xdr)) != 0)
4570 goto out;
1da177e4
LT
4571 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4572 goto out;
4573 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4574 goto out;
56ae19f3
TM
4575 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4576 goto out;
4577 if ((status = decode_restorefh(&xdr)) != 0)
4578 goto out;
4579 decode_getfattr(&xdr, res->dir_fattr, res->server);
1da177e4
LT
4580out:
4581 return status;
4582}
4583
4584/*
4585 * Decode SYMLINK response
4586 */
8687b63a 4587static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
1da177e4
LT
4588{
4589 return nfs4_xdr_dec_create(rqstp, p, res);
4590}
4591
4592/*
4593 * Decode GETATTR response
4594 */
8687b63a 4595static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
1da177e4
LT
4596{
4597 struct xdr_stream xdr;
4598 struct compound_hdr hdr;
4599 int status;
6c0195a4 4600
1da177e4
LT
4601 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4602 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4603 if (status)
4604 goto out;
4605 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4606 if (status)
4607 goto out;
4608 status = decode_putfh(&xdr);
4609 if (status)
4610 goto out;
4611 status = decode_getfattr(&xdr, res->fattr, res->server);
4612out:
4613 return status;
1da177e4
LT
4614}
4615
23ec6965
BF
4616/*
4617 * Encode an SETACL request
4618 */
4619static int
8687b63a 4620nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
23ec6965 4621{
05d564fe
AA
4622 struct xdr_stream xdr;
4623 struct compound_hdr hdr = {
66cc0429 4624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe
AA
4625 };
4626 int status;
4627
4628 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 4629 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 4630 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5 4631 encode_putfh(&xdr, args->fh, &hdr);
d017931c 4632 status = encode_setacl(&xdr, args, &hdr);
d017931c 4633 encode_nops(&hdr);
05d564fe 4634 return status;
23ec6965 4635}
05d564fe 4636
23ec6965
BF
4637/*
4638 * Decode SETACL response
4639 */
4640static int
73c403a9
BH
4641nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4642 struct nfs_setaclres *res)
23ec6965
BF
4643{
4644 struct xdr_stream xdr;
4645 struct compound_hdr hdr;
4646 int status;
4647
4648 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4649 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4650 if (status)
4651 goto out;
4652 status = decode_sequence(&xdr, &res->seq_res, rqstp);
23ec6965
BF
4653 if (status)
4654 goto out;
4655 status = decode_putfh(&xdr);
4656 if (status)
4657 goto out;
9e9ecc03 4658 status = decode_setattr(&xdr);
23ec6965
BF
4659out:
4660 return status;
4661}
1da177e4 4662
029d105e
BF
4663/*
4664 * Decode GETACL response
4665 */
4666static int
663c79b3
BH
4667nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4668 struct nfs_getaclres *res)
029d105e
BF
4669{
4670 struct xdr_stream xdr;
4671 struct compound_hdr hdr;
4672 int status;
4673
4674 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4675 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4676 if (status)
4677 goto out;
4678 status = decode_sequence(&xdr, &res->seq_res, rqstp);
029d105e
BF
4679 if (status)
4680 goto out;
4681 status = decode_putfh(&xdr);
4682 if (status)
4683 goto out;
663c79b3 4684 status = decode_getacl(&xdr, rqstp, &res->acl_len);
029d105e
BF
4685
4686out:
4687 return status;
4688}
4689
1da177e4
LT
4690/*
4691 * Decode CLOSE response
4692 */
8687b63a 4693static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
1da177e4 4694{
05d564fe
AA
4695 struct xdr_stream xdr;
4696 struct compound_hdr hdr;
4697 int status;
4698
4699 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4700 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4701 if (status)
4702 goto out;
4703 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
4704 if (status)
4705 goto out;
4706 status = decode_putfh(&xdr);
4707 if (status)
4708 goto out;
4709 status = decode_close(&xdr, res);
516a6af6
TM
4710 if (status != 0)
4711 goto out;
4712 /*
4713 * Note: Server may do delete on close for this file
4714 * in which case the getattr call will fail with
4715 * an ESTALE error. Shouldn't be a problem,
4716 * though, since fattr->valid will remain unset.
4717 */
4718 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4 4719out:
05d564fe 4720 return status;
1da177e4
LT
4721}
4722
4723/*
4724 * Decode OPEN response
4725 */
8687b63a 4726static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
1da177e4 4727{
05d564fe
AA
4728 struct xdr_stream xdr;
4729 struct compound_hdr hdr;
4730 int status;
4731
4732 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4733 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4734 if (status)
4735 goto out;
4736 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
4737 if (status)
4738 goto out;
4739 status = decode_putfh(&xdr);
4740 if (status)
4741 goto out;
4742 status = decode_savefh(&xdr);
4743 if (status)
4744 goto out;
4745 status = decode_open(&xdr, res);
56ae19f3
TM
4746 if (status)
4747 goto out;
9936781d 4748 if (decode_getfh(&xdr, &res->fh) != 0)
1da177e4 4749 goto out;
56ae19f3
TM
4750 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4751 goto out;
365c8f58 4752 if (decode_restorefh(&xdr) != 0)
56ae19f3
TM
4753 goto out;
4754 decode_getfattr(&xdr, res->dir_attr, res->server);
1da177e4 4755out:
05d564fe 4756 return status;
1da177e4
LT
4757}
4758
4759/*
4760 * Decode OPEN_CONFIRM response
4761 */
8687b63a 4762static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
1da177e4 4763{
05d564fe
AA
4764 struct xdr_stream xdr;
4765 struct compound_hdr hdr;
4766 int status;
4767
4768 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4769 status = decode_compound_hdr(&xdr, &hdr);
4770 if (status)
4771 goto out;
4772 status = decode_putfh(&xdr);
4773 if (status)
4774 goto out;
4775 status = decode_open_confirm(&xdr, res);
1da177e4 4776out:
05d564fe 4777 return status;
1da177e4
LT
4778}
4779
4780/*
4781 * Decode OPEN response
4782 */
8687b63a 4783static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
1da177e4 4784{
05d564fe
AA
4785 struct xdr_stream xdr;
4786 struct compound_hdr hdr;
4787 int status;
4788
4789 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4790 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4791 if (status)
4792 goto out;
4793 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
4794 if (status)
4795 goto out;
4796 status = decode_putfh(&xdr);
4797 if (status)
4798 goto out;
4799 status = decode_open(&xdr, res);
4800 if (status)
4801 goto out;
864472e9 4802 decode_getfattr(&xdr, res->f_attr, res->server);
1da177e4 4803out:
05d564fe 4804 return status;
1da177e4
LT
4805}
4806
4807/*
4808 * Decode SETATTR response
4809 */
8687b63a 4810static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
1da177e4 4811{
05d564fe
AA
4812 struct xdr_stream xdr;
4813 struct compound_hdr hdr;
4814 int status;
4815
4816 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4817 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4818 if (status)
4819 goto out;
4820 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
4821 if (status)
4822 goto out;
4823 status = decode_putfh(&xdr);
4824 if (status)
4825 goto out;
9e9ecc03 4826 status = decode_setattr(&xdr);
05d564fe
AA
4827 if (status)
4828 goto out;
78f945f8 4829 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4 4830out:
05d564fe 4831 return status;
1da177e4
LT
4832}
4833
4834/*
4835 * Decode LOCK response
4836 */
8687b63a 4837static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
1da177e4
LT
4838{
4839 struct xdr_stream xdr;
4840 struct compound_hdr hdr;
4841 int status;
4842
4843 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4844 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4845 if (status)
4846 goto out;
4847 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4848 if (status)
4849 goto out;
4850 status = decode_putfh(&xdr);
4851 if (status)
4852 goto out;
4853 status = decode_lock(&xdr, res);
4854out:
4855 return status;
4856}
4857
4858/*
4859 * Decode LOCKT response
4860 */
8687b63a 4861static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
1da177e4
LT
4862{
4863 struct xdr_stream xdr;
4864 struct compound_hdr hdr;
4865 int status;
4866
4867 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4868 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4869 if (status)
4870 goto out;
4871 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4872 if (status)
4873 goto out;
4874 status = decode_putfh(&xdr);
4875 if (status)
4876 goto out;
4877 status = decode_lockt(&xdr, res);
4878out:
4879 return status;
4880}
4881
4882/*
4883 * Decode LOCKU response
4884 */
8687b63a 4885static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
1da177e4
LT
4886{
4887 struct xdr_stream xdr;
4888 struct compound_hdr hdr;
4889 int status;
4890
4891 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4892 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4893 if (status)
4894 goto out;
4895 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4896 if (status)
4897 goto out;
4898 status = decode_putfh(&xdr);
4899 if (status)
4900 goto out;
4901 status = decode_locku(&xdr, res);
4902out:
4903 return status;
4904}
4905
4906/*
4907 * Decode READLINK response
4908 */
f50c7000
BH
4909static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4910 struct nfs4_readlink_res *res)
1da177e4
LT
4911{
4912 struct xdr_stream xdr;
4913 struct compound_hdr hdr;
4914 int status;
4915
4916 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4917 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4918 if (status)
4919 goto out;
4920 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4921 if (status)
4922 goto out;
4923 status = decode_putfh(&xdr);
4924 if (status)
4925 goto out;
4926 status = decode_readlink(&xdr, rqstp);
4927out:
4928 return status;
4929}
4930
4931/*
4932 * Decode READDIR response
4933 */
8687b63a 4934static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
1da177e4
LT
4935{
4936 struct xdr_stream xdr;
4937 struct compound_hdr hdr;
4938 int status;
4939
4940 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4941 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4942 if (status)
4943 goto out;
4944 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4945 if (status)
4946 goto out;
4947 status = decode_putfh(&xdr);
4948 if (status)
4949 goto out;
4950 status = decode_readdir(&xdr, rqstp, res);
4951out:
4952 return status;
4953}
4954
4955/*
4956 * Decode Read response
4957 */
8687b63a 4958static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
1da177e4
LT
4959{
4960 struct xdr_stream xdr;
4961 struct compound_hdr hdr;
4962 int status;
4963
4964 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4965 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4966 if (status)
4967 goto out;
4968 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4969 if (status)
4970 goto out;
4971 status = decode_putfh(&xdr);
4972 if (status)
4973 goto out;
4974 status = decode_read(&xdr, rqstp, res);
4975 if (!status)
4976 status = res->count;
4977out:
4978 return status;
4979}
4980
4981/*
4982 * Decode WRITE response
4983 */
8687b63a 4984static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
1da177e4
LT
4985{
4986 struct xdr_stream xdr;
4987 struct compound_hdr hdr;
4988 int status;
4989
4990 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4991 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4992 if (status)
4993 goto out;
4994 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4995 if (status)
4996 goto out;
4997 status = decode_putfh(&xdr);
4998 if (status)
4999 goto out;
5000 status = decode_write(&xdr, res);
4f9838c7
TM
5001 if (status)
5002 goto out;
5003 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
5004 if (!status)
5005 status = res->count;
5006out:
5007 return status;
5008}
5009
5010/*
5011 * Decode COMMIT response
5012 */
8687b63a 5013static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
1da177e4
LT
5014{
5015 struct xdr_stream xdr;
5016 struct compound_hdr hdr;
5017 int status;
5018
5019 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5020 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5021 if (status)
5022 goto out;
5023 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5024 if (status)
5025 goto out;
5026 status = decode_putfh(&xdr);
5027 if (status)
5028 goto out;
5029 status = decode_commit(&xdr, res);
4f9838c7
TM
5030 if (status)
5031 goto out;
5032 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
5033out:
5034 return status;
5035}
5036
5037/*
5038 * FSINFO request
5039 */
3dda5e43
BH
5040static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5041 struct nfs4_fsinfo_res *res)
1da177e4
LT
5042{
5043 struct xdr_stream xdr;
5044 struct compound_hdr hdr;
5045 int status;
5046
5047 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5048 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5049 if (!status)
5050 status = decode_sequence(&xdr, &res->seq_res, req);
1da177e4
LT
5051 if (!status)
5052 status = decode_putfh(&xdr);
5053 if (!status)
3dda5e43 5054 status = decode_fsinfo(&xdr, res->fsinfo);
1da177e4
LT
5055 return status;
5056}
5057
5058/*
5059 * PATHCONF request
5060 */
d45b2989
BH
5061static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5062 struct nfs4_pathconf_res *res)
1da177e4
LT
5063{
5064 struct xdr_stream xdr;
5065 struct compound_hdr hdr;
5066 int status;
5067
5068 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5069 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5070 if (!status)
5071 status = decode_sequence(&xdr, &res->seq_res, req);
1da177e4
LT
5072 if (!status)
5073 status = decode_putfh(&xdr);
5074 if (!status)
d45b2989 5075 status = decode_pathconf(&xdr, res->pathconf);
1da177e4
LT
5076 return status;
5077}
5078
5079/*
5080 * STATFS request
5081 */
24ad148a
BH
5082static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5083 struct nfs4_statfs_res *res)
1da177e4
LT
5084{
5085 struct xdr_stream xdr;
5086 struct compound_hdr hdr;
5087 int status;
5088
5089 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5090 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5091 if (!status)
5092 status = decode_sequence(&xdr, &res->seq_res, req);
1da177e4
LT
5093 if (!status)
5094 status = decode_putfh(&xdr);
5095 if (!status)
24ad148a 5096 status = decode_statfs(&xdr, res->fsstat);
1da177e4
LT
5097 return status;
5098}
5099
5100/*
5101 * GETATTR_BITMAP request
5102 */
8687b63a 5103static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
1da177e4
LT
5104{
5105 struct xdr_stream xdr;
5106 struct compound_hdr hdr;
5107 int status;
5108
5109 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
9b7b9fcc
AA
5110 status = decode_compound_hdr(&xdr, &hdr);
5111 if (status)
5112 goto out;
5113 status = decode_sequence(&xdr, &res->seq_res, req);
5114 if (status)
1da177e4
LT
5115 goto out;
5116 if ((status = decode_putfh(&xdr)) != 0)
5117 goto out;
5118 status = decode_server_caps(&xdr, res);
5119out:
5120 return status;
5121}
5122
5123/*
5124 * Decode RENEW response
5125 */
8687b63a 5126static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
1da177e4
LT
5127{
5128 struct xdr_stream xdr;
5129 struct compound_hdr hdr;
5130 int status;
5131
5132 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5133 status = decode_compound_hdr(&xdr, &hdr);
5134 if (!status)
5135 status = decode_renew(&xdr);
5136 return status;
5137}
5138
5139/*
5140 * a SETCLIENTID request
5141 */
8687b63a 5142static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
adfa6f98 5143 struct nfs_client *clp)
1da177e4
LT
5144{
5145 struct xdr_stream xdr;
5146 struct compound_hdr hdr;
5147 int status;
5148
5149 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5150 status = decode_compound_hdr(&xdr, &hdr);
5151 if (!status)
5152 status = decode_setclientid(&xdr, clp);
1da177e4
LT
5153 return status;
5154}
5155
5156/*
5157 * a SETCLIENTID_CONFIRM request
5158 */
8687b63a 5159static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
1da177e4
LT
5160{
5161 struct xdr_stream xdr;
5162 struct compound_hdr hdr;
5163 int status;
5164
5165 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5166 status = decode_compound_hdr(&xdr, &hdr);
5167 if (!status)
5168 status = decode_setclientid_confirm(&xdr);
5169 if (!status)
5170 status = decode_putrootfh(&xdr);
5171 if (!status)
5172 status = decode_fsinfo(&xdr, fsinfo);
1da177e4
LT
5173 return status;
5174}
5175
5176/*
5177 * DELEGRETURN request
5178 */
8687b63a 5179static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
1da177e4
LT
5180{
5181 struct xdr_stream xdr;
5182 struct compound_hdr hdr;
5183 int status;
5184
5185 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5186 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5187 if (status)
5188 goto out;
5189 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5190 if (status)
fa178f29
TM
5191 goto out;
5192 status = decode_putfh(&xdr);
5193 if (status != 0)
5194 goto out;
5195 status = decode_delegreturn(&xdr);
5196 decode_getfattr(&xdr, res->fattr, res->server);
5197out:
1da177e4
LT
5198 return status;
5199}
5200
683b57b4
TM
5201/*
5202 * FS_LOCATIONS request
5203 */
22958463
BH
5204static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5205 struct nfs4_fs_locations_res *res)
683b57b4
TM
5206{
5207 struct xdr_stream xdr;
5208 struct compound_hdr hdr;
5209 int status;
5210
5211 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5212 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5213 if (status)
5214 goto out;
5215 status = decode_sequence(&xdr, &res->seq_res, req);
5216 if (status)
683b57b4
TM
5217 goto out;
5218 if ((status = decode_putfh(&xdr)) != 0)
5219 goto out;
5220 if ((status = decode_lookup(&xdr)) != 0)
5221 goto out;
5222 xdr_enter_page(&xdr, PAGE_SIZE);
22958463
BH
5223 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
5224 res->fs_locations->server);
683b57b4
TM
5225out:
5226 return status;
5227}
5228
99fe60d0
BH
5229#if defined(CONFIG_NFS_V4_1)
5230/*
5231 * EXCHANGE_ID request
5232 */
5233static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5234 void *res)
5235{
5236 struct xdr_stream xdr;
5237 struct compound_hdr hdr;
5238 int status;
5239
5240 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5241 status = decode_compound_hdr(&xdr, &hdr);
5242 if (!status)
5243 status = decode_exchange_id(&xdr, res);
5244 return status;
5245}
2050f0cc 5246
fc931582
AA
5247/*
5248 * a CREATE_SESSION request
5249 */
5250static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5251 struct nfs41_create_session_res *res)
5252{
5253 struct xdr_stream xdr;
5254 struct compound_hdr hdr;
5255 int status;
5256
5257 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5258 status = decode_compound_hdr(&xdr, &hdr);
5259 if (!status)
5260 status = decode_create_session(&xdr, res);
5261 return status;
5262}
5263
0f3e66c6
AA
5264/*
5265 * a DESTROY_SESSION request
5266 */
5267static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5268 void *dummy)
5269{
5270 struct xdr_stream xdr;
5271 struct compound_hdr hdr;
5272 int status;
5273
5274 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5275 status = decode_compound_hdr(&xdr, &hdr);
5276 if (!status)
5277 status = decode_destroy_session(&xdr, dummy);
5278 return status;
5279}
5280
fc01cea9
AA
5281/*
5282 * a SEQUENCE request
5283 */
5284static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5285 struct nfs4_sequence_res *res)
5286{
5287 struct xdr_stream xdr;
5288 struct compound_hdr hdr;
5289 int status;
5290
5291 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5292 status = decode_compound_hdr(&xdr, &hdr);
5293 if (!status)
5294 status = decode_sequence(&xdr, res, rqstp);
5295 return status;
5296}
5297
2050f0cc
AA
5298/*
5299 * a GET_LEASE_TIME request
5300 */
5301static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5302 struct nfs4_get_lease_time_res *res)
5303{
5304 struct xdr_stream xdr;
5305 struct compound_hdr hdr;
5306 int status;
5307
5308 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5309 status = decode_compound_hdr(&xdr, &hdr);
5310 if (!status)
5311 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5312 if (!status)
5313 status = decode_putrootfh(&xdr);
5314 if (!status)
5315 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5316 return status;
5317}
99fe60d0
BH
5318#endif /* CONFIG_NFS_V4_1 */
5319
0dbb4c67 5320__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
1da177e4
LT
5321{
5322 uint32_t bitmap[2] = {0};
5323 uint32_t len;
5324
5325 if (!*p++) {
5326 if (!*p)
5327 return ERR_PTR(-EAGAIN);
5328 entry->eof = 1;
5329 return ERR_PTR(-EBADCOOKIE);
5330 }
5331
5332 entry->prev_cookie = entry->cookie;
5333 p = xdr_decode_hyper(p, &entry->cookie);
5334 entry->len = ntohl(*p++);
5335 entry->name = (const char *) p;
5336 p += XDR_QUADLEN(entry->len);
5337
5338 /*
5339 * In case the server doesn't return an inode number,
5340 * we fake one here. (We don't use inode number 0,
5341 * since glibc seems to choke on it...)
5342 */
5343 entry->ino = 1;
5344
5345 len = ntohl(*p++); /* bitmap length */
5346 if (len-- > 0) {
5347 bitmap[0] = ntohl(*p++);
5348 if (len-- > 0) {
5349 bitmap[1] = ntohl(*p++);
5350 p += len;
5351 }
5352 }
5353 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5354 if (len > 0) {
97d312d0
MN
5355 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5356 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5357 /* Ignore the return value of rdattr_error for now */
5358 p++;
5359 len--;
5360 }
1da177e4
LT
5361 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5362 xdr_decode_hyper(p, &entry->ino);
5363 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5364 xdr_decode_hyper(p, &entry->ino);
5365 p += len;
5366 }
5367
5368 entry->eof = !p[0] && p[1];
5369 return p;
5370}
5371
5372/*
5373 * We need to translate between nfs status return values and
5374 * the local errno values which may not be the same.
5375 */
5376static struct {
5377 int stat;
5378 int errno;
5379} nfs_errtbl[] = {
5380 { NFS4_OK, 0 },
856dff3d
BH
5381 { NFS4ERR_PERM, -EPERM },
5382 { NFS4ERR_NOENT, -ENOENT },
5383 { NFS4ERR_IO, -errno_NFSERR_IO},
5384 { NFS4ERR_NXIO, -ENXIO },
5385 { NFS4ERR_ACCESS, -EACCES },
5386 { NFS4ERR_EXIST, -EEXIST },
5387 { NFS4ERR_XDEV, -EXDEV },
5388 { NFS4ERR_NOTDIR, -ENOTDIR },
5389 { NFS4ERR_ISDIR, -EISDIR },
5390 { NFS4ERR_INVAL, -EINVAL },
5391 { NFS4ERR_FBIG, -EFBIG },
5392 { NFS4ERR_NOSPC, -ENOSPC },
5393 { NFS4ERR_ROFS, -EROFS },
5394 { NFS4ERR_MLINK, -EMLINK },
5395 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5396 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5397 { NFS4ERR_DQUOT, -EDQUOT },
5398 { NFS4ERR_STALE, -ESTALE },
5399 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5400 { NFS4ERR_BADOWNER, -EINVAL },
5401 { NFS4ERR_BADNAME, -EINVAL },
5402 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5403 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5404 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5405 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5406 { NFS4ERR_BADTYPE, -EBADTYPE },
5407 { NFS4ERR_LOCKED, -EAGAIN },
5408 { NFS4ERR_RESOURCE, -EREMOTEIO },
5409 { NFS4ERR_SYMLINK, -ELOOP },
5410 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5411 { NFS4ERR_DEADLOCK, -EDEADLK },
5412 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
1da177e4
LT
5413 * to be handled by a
5414 * middle-layer.
5415 */
856dff3d 5416 { -1, -EIO }
1da177e4
LT
5417};
5418
5419/*
5420 * Convert an NFS error code to a local one.
5421 * This one is used jointly by NFSv2 and NFSv3.
5422 */
5423static int
0a8ea437 5424nfs4_stat_to_errno(int stat)
1da177e4
LT
5425{
5426 int i;
5427 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5428 if (nfs_errtbl[i].stat == stat)
5429 return nfs_errtbl[i].errno;
5430 }
5431 if (stat <= 10000 || stat > 10100) {
5432 /* The server is looney tunes. */
856dff3d 5433 return -ESERVERFAULT;
1da177e4
LT
5434 }
5435 /* If we cannot translate the error, the recovery routines should
5436 * handle it.
5437 * Note: remaining NFSv4 error codes have values > 10000, so should
5438 * not conflict with native Linux error codes.
5439 */
856dff3d 5440 return -stat;
1da177e4
LT
5441}
5442
1da177e4
LT
5443#define PROC(proc, argtype, restype) \
5444[NFSPROC4_CLNT_##proc] = { \
5445 .p_proc = NFSPROC4_COMPOUND, \
5446 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5447 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
2bea90d4
CL
5448 .p_arglen = NFS4_##argtype##_sz, \
5449 .p_replen = NFS4_##restype##_sz, \
cc0175c1
CL
5450 .p_statidx = NFSPROC4_CLNT_##proc, \
5451 .p_name = #proc, \
05d564fe 5452}
1da177e4
LT
5453
5454struct rpc_procinfo nfs4_procedures[] = {
5455 PROC(READ, enc_read, dec_read),
5456 PROC(WRITE, enc_write, dec_write),
5457 PROC(COMMIT, enc_commit, dec_commit),
5458 PROC(OPEN, enc_open, dec_open),
5459 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5460 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5461 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5462 PROC(CLOSE, enc_close, dec_close),
5463 PROC(SETATTR, enc_setattr, dec_setattr),
5464 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5465 PROC(RENEW, enc_renew, dec_renew),
5466 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5467 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5468 PROC(LOCK, enc_lock, dec_lock),
5469 PROC(LOCKT, enc_lockt, dec_lockt),
5470 PROC(LOCKU, enc_locku, dec_locku),
5471 PROC(ACCESS, enc_access, dec_access),
5472 PROC(GETATTR, enc_getattr, dec_getattr),
5473 PROC(LOOKUP, enc_lookup, dec_lookup),
5474 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5475 PROC(REMOVE, enc_remove, dec_remove),
5476 PROC(RENAME, enc_rename, dec_rename),
5477 PROC(LINK, enc_link, dec_link),
5478 PROC(SYMLINK, enc_symlink, dec_symlink),
5479 PROC(CREATE, enc_create, dec_create),
5480 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5481 PROC(STATFS, enc_statfs, dec_statfs),
5482 PROC(READLINK, enc_readlink, dec_readlink),
5483 PROC(READDIR, enc_readdir, dec_readdir),
5484 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5485 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
029d105e 5486 PROC(GETACL, enc_getacl, dec_getacl),
23ec6965 5487 PROC(SETACL, enc_setacl, dec_setacl),
683b57b4 5488 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
99fe60d0
BH
5489#if defined(CONFIG_NFS_V4_1)
5490 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
fc931582 5491 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
0f3e66c6 5492 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
fc01cea9 5493 PROC(SEQUENCE, enc_sequence, dec_sequence),
2050f0cc 5494 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
99fe60d0 5495#endif /* CONFIG_NFS_V4_1 */
1da177e4
LT
5496};
5497
5498struct rpc_version nfs_version4 = {
5499 .number = 4,
e8c96f8c 5500 .nrprocs = ARRAY_SIZE(nfs4_procedures),
1da177e4
LT
5501 .procs = nfs4_procedures
5502};
5503
5504/*
5505 * Local variables:
5506 * c-basic-offset: 8
5507 * End:
5508 */