blob: 0b1f3fcdd28a06651f731e33eec5fe78a1caf0d5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
41#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/errno.h>
43#include <linux/string.h>
44#include <linux/in.h>
45#include <linux/pagemap.h>
46#include <linux/proc_fs.h>
47#include <linux/kdev_t.h>
48#include <linux/sunrpc/clnt.h>
49#include <linux/nfs.h>
50#include <linux/nfs4.h>
51#include <linux/nfs_fs.h>
52#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000053#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050054#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
David Howells0a8ea432006-08-22 20:06:08 -040061static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
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
Andy Adamson6c0195a2008-12-23 16:06:15 -050070/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040071 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040075#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#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)
Trond Myklebust9104a552007-07-17 21:52:42 -040080#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))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#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))
J. Bruce Fields96928202005-06-22 17:16:22 +000092#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040096#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000098/* 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 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#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)
Trond Myklebust9104a552007-07-17 21:52:42 -0400104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#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 + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500119 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#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)
Trond Myklebuste6889622007-07-02 13:58:30 -0400134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400136#define encode_share_access_maxsz \
137 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500138#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400139#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)
Trond Myklebust9104a552007-07-17 21:52:42 -0400147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400151 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400224 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000225 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400228 1 + 2 + nfs4_name_maxsz + \
229 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400230#define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_statfs_maxsz (encode_getattr_maxsz)
234#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#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)
Trond Myklebuste6889622007-07-02 13:58:30 -0400243#define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245#define decode_fs_locations_maxsz \
246 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400247
248#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400249#define NFS4_MAX_MACHINE_NAME_LEN (64)
250
Benny Halevy99fe60d2009-04-01 09:22:29 -0400251#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 */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400272#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)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400297#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400299#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)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400303#else /* CONFIG_NFS_V4_1 */
304#define encode_sequence_maxsz 0
305#define decode_sequence_maxsz 0
306#endif /* CONFIG_NFS_V4_1 */
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#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 + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400311 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400313 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400315 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400317 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400319 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400321 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400323 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400325 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400327 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400329 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400331 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400333 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400335 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400337 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400338 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400340 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400342 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400343 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400345 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400348 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400353 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400356 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400365 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)
Trond Myklebust9104a552007-07-17 21:52:42 -0400372#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400381 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400383 encode_open_maxsz + \
384 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400386 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400388 decode_open_maxsz + \
389 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_open_downgrade_sz \
391 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400393 encode_putfh_maxsz + \
394 encode_open_downgrade_maxsz + \
395 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define NFS4_dec_open_downgrade_sz \
397 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 decode_putfh_maxsz + \
400 decode_open_downgrade_maxsz + \
401 decode_getattr_maxsz)
402#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400404 encode_putfh_maxsz + \
405 encode_close_maxsz + \
406 encode_getattr_maxsz)
407#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 decode_putfh_maxsz + \
410 decode_close_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_putfh_maxsz + \
415 encode_setattr_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_putfh_maxsz + \
420 decode_setattr_maxsz + \
421 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 encode_putfh_maxsz + \
425 encode_fsinfo_maxsz)
426#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 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 + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400453 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400459 encode_lockt_maxsz)
460#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 decode_putfh_maxsz + \
463 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400467 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400471 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400475 encode_access_maxsz + \
476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400480 decode_access_maxsz + \
481 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400483 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 encode_putfh_maxsz + \
485 encode_getattr_maxsz)
486#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 decode_putfh_maxsz + \
489 decode_getattr_maxsz)
490#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 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 + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400499 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 decode_getattr_maxsz + \
501 decode_getfh_maxsz)
502#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 encode_putrootfh_maxsz + \
505 encode_getattr_maxsz + \
506 encode_getfh_maxsz)
507#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 decode_putrootfh_maxsz + \
510 decode_getattr_maxsz + \
511 decode_getfh_maxsz)
512#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400515 encode_remove_maxsz + \
516 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400520 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400521 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 encode_putfh_maxsz + \
525 encode_savefh_maxsz + \
526 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400527 encode_rename_maxsz + \
528 encode_getattr_maxsz + \
529 encode_restorefh_maxsz + \
530 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
534 decode_savefh_maxsz + \
535 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400536 decode_rename_maxsz + \
537 decode_getattr_maxsz + \
538 decode_restorefh_maxsz + \
539 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 encode_putfh_maxsz + \
543 encode_savefh_maxsz + \
544 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400545 encode_link_maxsz + \
546 decode_getattr_maxsz + \
547 encode_restorefh_maxsz + \
548 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 decode_putfh_maxsz + \
552 decode_savefh_maxsz + \
553 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400554 decode_link_maxsz + \
555 decode_getattr_maxsz + \
556 decode_restorefh_maxsz + \
557 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 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 + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 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 + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400573 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400575 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400577 encode_restorefh_maxsz + \
578 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400582 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400584 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_putfh_maxsz + \
591 encode_getattr_maxsz)
592#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 decode_putfh_maxsz + \
595 decode_getattr_maxsz)
596#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400599 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400603 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800606 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_getattr_maxsz)
608#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800610 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_getattr_maxsz)
612#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100615 encode_delegreturn_maxsz + \
616 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100619 decode_delegreturn_maxsz + \
620 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000621#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000623 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400624 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000625#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000627 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400628 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000629#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000631 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400632 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000633#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000635 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400636 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400637#define NFS4_enc_fs_locations_sz \
638 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400640 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400641 encode_lookup_maxsz + \
642 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400643#define NFS4_dec_fs_locations_sz \
644 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400645 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400646 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400647 decode_lookup_maxsz + \
648 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400649#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)
Andy Adamsonfc931582009-04-01 09:22:31 -0400656#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)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400662#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)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400666#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)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400672#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)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400680#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Trond Myklebustbca79472009-03-11 14:10:26 -0400682static 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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693};
694
695struct compound_hdr {
696 int32_t status;
697 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500698 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 uint32_t taglen;
700 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400701 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400702 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703};
704
Benny Halevy13c65ce2009-08-14 17:19:25 +0300705static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
706{
707 __be32 *p = xdr_reserve_space(xdr, nbytes);
708 BUG_ON(!p);
709 return p;
710}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
713{
Al Viro8687b632006-10-19 23:28:48 -0700714 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 p = xdr_reserve_space(xdr, 4 + len);
717 BUG_ON(p == NULL);
718 xdr_encode_opaque(p, str, len);
719}
720
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400721static void encode_compound_hdr(struct xdr_stream *xdr,
722 struct rpc_rqst *req,
723 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Al Viro8687b632006-10-19 23:28:48 -0700725 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400726 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
727
728 /* initialize running count of expected bytes in reply.
729 * NOTE: the replied tag SHOULD be the same is the one sent,
730 * but this is not required as a MUST for the server to do so. */
731 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
734 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300735 p = reserve_space(xdr, 4 + hdr->taglen + 8);
736 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300737 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500738 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300739 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500740}
741
742static void encode_nops(struct compound_hdr *hdr)
743{
Andy Adamsonfc931582009-04-01 09:22:31 -0400744 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500745 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
748static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
749{
Al Viro8687b632006-10-19 23:28:48 -0700750 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
753 BUG_ON(p == NULL);
754 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
755}
756
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500757static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
759 char owner_name[IDMAP_NAMESZ];
760 char owner_group[IDMAP_NAMESZ];
761 int owner_namelen = 0;
762 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700763 __be32 *p;
764 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 int len;
766 uint32_t bmval0 = 0;
767 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 /*
770 * We reserve enough space to write the entire attribute buffer at once.
771 * In the worst-case, this would be
772 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
773 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000774 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 */
776 len = 16;
777
778 /* Sigh */
779 if (iap->ia_valid & ATTR_SIZE)
780 len += 8;
781 if (iap->ia_valid & ATTR_MODE)
782 len += 4;
783 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400784 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400786 dprintk("nfs: couldn't resolve uid %d to string\n",
787 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 /* XXX */
789 strcpy(owner_name, "nobody");
790 owner_namelen = sizeof("nobody") - 1;
791 /* goto out; */
792 }
793 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
794 }
795 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400796 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400798 dprintk("nfs: couldn't resolve gid %d to string\n",
799 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 strcpy(owner_group, "nobody");
801 owner_grouplen = sizeof("nobody") - 1;
802 /* goto out; */
803 }
804 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
805 }
806 if (iap->ia_valid & ATTR_ATIME_SET)
807 len += 16;
808 else if (iap->ia_valid & ATTR_ATIME)
809 len += 4;
810 if (iap->ia_valid & ATTR_MTIME_SET)
811 len += 16;
812 else if (iap->ia_valid & ATTR_MTIME)
813 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300814 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 /*
817 * We write the bitmap length now, but leave the bitmap and the attribute
818 * buffer length to be backfilled at the end of this routine.
819 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300820 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 q = p;
822 p += 3;
823
824 if (iap->ia_valid & ATTR_SIZE) {
825 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300826 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828 if (iap->ia_valid & ATTR_MODE) {
829 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300830 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832 if (iap->ia_valid & ATTR_UID) {
833 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300834 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836 if (iap->ia_valid & ATTR_GID) {
837 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300838 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
840 if (iap->ia_valid & ATTR_ATIME_SET) {
841 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300842 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
843 *p++ = cpu_to_be32(0);
844 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
845 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 }
847 else if (iap->ia_valid & ATTR_ATIME) {
848 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300849 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851 if (iap->ia_valid & ATTR_MTIME_SET) {
852 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300853 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
854 *p++ = cpu_to_be32(0);
855 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
856 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858 else if (iap->ia_valid & ATTR_MTIME) {
859 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300860 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 /*
864 * Now we backfill the bitmap and the attribute buffer length.
865 */
866 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400867 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 len, ((char *)p - (char *)q) + 4);
869 BUG();
870 }
871 len = (char *)p - (char *)q - 12;
872 *q++ = htonl(bmval0);
873 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300874 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877}
878
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500879static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
Al Viro8687b632006-10-19 23:28:48 -0700881 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Benny Halevy13c65ce2009-08-14 17:19:25 +0300883 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300884 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300885 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500886 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400887 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500890static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Al Viro8687b632006-10-19 23:28:48 -0700892 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Benny Halevy13c65ce2009-08-14 17:19:25 +0300894 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300895 *p++ = cpu_to_be32(OP_CLOSE);
896 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300897 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500898 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400899 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900}
901
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500902static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Al Viro8687b632006-10-19 23:28:48 -0700904 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500905
Benny Halevy13c65ce2009-08-14 17:19:25 +0300906 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300907 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300908 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300909 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500910 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400911 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500914static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Al Viro8687b632006-10-19 23:28:48 -0700916 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500917
Benny Halevy13c65ce2009-08-14 17:19:25 +0300918 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300920 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 switch (create->ftype) {
923 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300924 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300925 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400926 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 break;
928
929 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300930 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300931 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300932 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 break;
934
935 default:
936 break;
937 }
938
Benny Halevy811652b2009-08-14 17:19:34 +0300939 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500940 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400941 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500943 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500946static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Andy Adamson05d564f2008-12-23 16:06:15 -0500948 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Benny Halevy13c65ce2009-08-14 17:19:25 +0300950 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300951 *p++ = cpu_to_be32(OP_GETATTR);
952 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300953 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500954 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400955 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956}
957
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500958static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
Andy Adamson05d564f2008-12-23 16:06:15 -0500960 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Benny Halevy13c65ce2009-08-14 17:19:25 +0300962 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300963 *p++ = cpu_to_be32(OP_GETATTR);
964 *p++ = cpu_to_be32(2);
965 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +0300966 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500967 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400968 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500971static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500973 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
974 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500977static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500979 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
980 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500983static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400984{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500985 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
986 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400987}
988
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500989static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
Al Viro8687b632006-10-19 23:28:48 -0700991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Benny Halevy13c65ce2009-08-14 17:19:25 +0300993 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300994 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500995 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400996 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500999static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
Al Viro8687b632006-10-19 23:28:48 -07001001 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Benny Halevy13c65ce2009-08-14 17:19:25 +03001003 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001004 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001005 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001006 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001007 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001010static inline int nfs4_lock_type(struct file_lock *fl, int block)
1011{
1012 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1013 return block ? NFS4_READW_LT : NFS4_READ_LT;
1014 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1015}
1016
1017static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1018{
1019 if (fl->fl_end == OFFSET_MAX)
1020 return ~(uint64_t)0;
1021 return fl->fl_end - fl->fl_start + 1;
1022}
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024/*
1025 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1026 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1027 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001028static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029{
Al Viro8687b632006-10-19 23:28:48 -07001030 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Benny Halevy13c65ce2009-08-14 17:19:25 +03001032 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001033 *p++ = cpu_to_be32(OP_LOCK);
1034 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1035 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001036 p = xdr_encode_hyper(p, args->fl->fl_start);
1037 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001038 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001039 if (args->new_lock_owner){
Benny Halevy13c65ce2009-08-14 17:19:25 +03001040 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001041 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001042 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001043 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001044 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001045 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001046 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001047 xdr_encode_hyper(p, args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 }
1049 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001050 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001051 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001052 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Andy Adamsond0179312008-12-23 16:06:17 -05001054 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001055 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056}
1057
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001058static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Al Viro8687b632006-10-19 23:28:48 -07001060 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Benny Halevy13c65ce2009-08-14 17:19:25 +03001062 p = reserve_space(xdr, 52);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(OP_LOCKT);
1064 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001065 p = xdr_encode_hyper(p, args->fl->fl_start);
1066 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1067 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001068 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001069 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001070 xdr_encode_hyper(p, args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001071 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001072 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001075static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Al Viro8687b632006-10-19 23:28:48 -07001077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Benny Halevy13c65ce2009-08-14 17:19:25 +03001079 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001080 *p++ = cpu_to_be32(OP_LOCKU);
1081 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1082 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001083 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001084 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001085 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001087 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001093 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Benny Halevy13c65ce2009-08-14 17:19:25 +03001095 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001096 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001097 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001098 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001099 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001102static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
Al Viro8687b632006-10-19 23:28:48 -07001104 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Benny Halevy13c65ce2009-08-14 17:19:25 +03001106 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001107 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001108 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001109 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001110 break;
1111 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001112 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001113 break;
1114 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001115 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001116 break;
1117 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001118 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
Benny Halevy34558512009-08-14 17:19:30 +03001120 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
1123static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1124{
Al Viro8687b632006-10-19 23:28:48 -07001125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 /*
1127 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1128 * owner 4 = 32
1129 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001130 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001131 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001132 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001133 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001134 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001135 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001136 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001137 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001138 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
1141static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001144 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Benny Halevy13c65ce2009-08-14 17:19:25 +03001146 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001148 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001149 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001150 encode_attrs(xdr, arg->u.attrs, arg->server);
1151 break;
1152 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001153 clp = arg->server->nfs_client;
1154 if (clp->cl_minorversion > 0) {
1155 if (nfs4_has_persistent_session(clp)) {
1156 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1157 encode_attrs(xdr, arg->u.attrs, arg->server);
1158 } else {
1159 struct iattr dummy;
1160
1161 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1162 encode_nfs4_verifier(xdr, &arg->u.verifier);
1163 dummy.ia_valid = 0;
1164 encode_attrs(xdr, &dummy, arg->server);
1165 }
1166 } else {
1167 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1168 encode_nfs4_verifier(xdr, &arg->u.verifier);
1169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
1171}
1172
1173static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1174{
Al Viro8687b632006-10-19 23:28:48 -07001175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Benny Halevy13c65ce2009-08-14 17:19:25 +03001177 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001179 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001180 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001181 break;
1182 default:
1183 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001184 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001185 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
1187}
1188
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001189static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Al Viro8687b632006-10-19 23:28:48 -07001191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Benny Halevy13c65ce2009-08-14 17:19:25 +03001193 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001195 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001196 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001197 break;
1198 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001199 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001200 break;
1201 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001202 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001203 break;
1204 default:
1205 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207}
1208
1209static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1210{
Al Viro8687b632006-10-19 23:28:48 -07001211 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Benny Halevy13c65ce2009-08-14 17:19:25 +03001213 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001214 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 encode_string(xdr, name->len, name->name);
1216}
1217
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001218static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Al Viro8687b632006-10-19 23:28:48 -07001220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Benny Halevy13c65ce2009-08-14 17:19:25 +03001222 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001223 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 encode_delegation_type(xdr, type);
1225}
1226
1227static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1228{
Al Viro8687b632006-10-19 23:28:48 -07001229 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Benny Halevy13c65ce2009-08-14 17:19:25 +03001231 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001232 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001233 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 encode_string(xdr, name->len, name->name);
1235}
1236
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001237static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
1239 encode_openhdr(xdr, arg);
1240 encode_opentype(xdr, arg);
1241 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001242 case NFS4_OPEN_CLAIM_NULL:
1243 encode_claim_null(xdr, arg->name);
1244 break;
1245 case NFS4_OPEN_CLAIM_PREVIOUS:
1246 encode_claim_previous(xdr, arg->u.delegation_type);
1247 break;
1248 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1249 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1250 break;
1251 default:
1252 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
Andy Adamsond0179312008-12-23 16:06:17 -05001254 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001255 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Al Viro8687b632006-10-19 23:28:48 -07001260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Benny Halevy13c65ce2009-08-14 17:19:25 +03001262 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001263 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001264 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001266 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001267 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001270static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Al Viro8687b632006-10-19 23:28:48 -07001272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Benny Halevy13c65ce2009-08-14 17:19:25 +03001274 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001275 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001276 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001277 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001278 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001279 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001280 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void
Andy Adamsond0179312008-12-23 16:06:17 -05001284encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
1286 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Benny Halevy13c65ce2009-08-14 17:19:25 +03001289 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001290 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001291 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001292 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001293 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001296static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Andy Adamson05d564f2008-12-23 16:06:15 -05001298 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001299
Benny Halevy13c65ce2009-08-14 17:19:25 +03001300 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001301 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001302 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001303 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304}
1305
1306static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1307{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Benny Halevy13c65ce2009-08-14 17:19:25 +03001311 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (ctx->state != NULL) {
1313 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Benny Halevy34558512009-08-14 17:19:30 +03001314 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 } else
Benny Halevy34558512009-08-14 17:19:30 +03001316 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317}
1318
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001319static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
Al Viro8687b632006-10-19 23:28:48 -07001321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Benny Halevy13c65ce2009-08-14 17:19:25 +03001323 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001324 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326 encode_stateid(xdr, args->context);
1327
Benny Halevy13c65ce2009-08-14 17:19:25 +03001328 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001329 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001330 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001331 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001332 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333}
1334
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001335static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
Manoj Naik97d312d2005-06-22 17:16:39 +00001337 uint32_t attrs[2] = {
1338 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1339 FATTR4_WORD1_MOUNTED_ON_FILEID,
1340 };
Al Viro8687b632006-10-19 23:28:48 -07001341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Benny Halevy13c65ce2009-08-14 17:19:25 +03001343 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001345 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001346 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001347 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1348 *p++ = cpu_to_be32(readdir->count);
1349 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001350 /* Switch to mounted_on_fileid if the server supports it */
1351 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1352 attrs[0] &= ~FATTR4_WORD0_FILEID;
1353 else
1354 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001356 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001357 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001358 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001359 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1360 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001361 (unsigned long long)readdir->cookie,
1362 ((u32 *)readdir->verifier.data)[0],
1363 ((u32 *)readdir->verifier.data)[1],
1364 attrs[0] & readdir->bitmask[0],
1365 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366}
1367
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001368static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369{
Al Viro8687b632006-10-19 23:28:48 -07001370 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001373 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001374 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001375 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376}
1377
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001378static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Al Viro8687b632006-10-19 23:28:48 -07001380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Benny Halevy13c65ce2009-08-14 17:19:25 +03001382 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001383 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001384 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001385 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001386 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001389static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy811652b2009-08-14 17:19:34 +03001393 p = reserve_space(xdr, 4);
1394 *p = cpu_to_be32(OP_RENAME);
1395 encode_string(xdr, oldname->len, oldname->name);
1396 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001397 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001398 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399}
1400
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001401static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
Al Viro8687b632006-10-19 23:28:48 -07001403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Benny Halevy13c65ce2009-08-14 17:19:25 +03001405 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001406 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001407 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001408 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001409 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001412static void
Andy Adamsond0179312008-12-23 16:06:17 -05001413encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001414{
Al Viro8687b632006-10-19 23:28:48 -07001415 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001416
Benny Halevy13c65ce2009-08-14 17:19:25 +03001417 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001419 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001420 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001421}
1422
1423static int
Andy Adamsond0179312008-12-23 16:06:17 -05001424encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001425{
Al Viro8687b632006-10-19 23:28:48 -07001426 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001427
Benny Halevy13c65ce2009-08-14 17:19:25 +03001428 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001429 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001430 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001431 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001432 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001434 if (arg->acl_len % 4)
1435 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001438 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001439 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001440 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001441 return 0;
1442}
1443
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001444static void
Andy Adamsond0179312008-12-23 16:06:17 -05001445encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001451 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001452 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453}
1454
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001455static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Al Viro8687b632006-10-19 23:28:48 -07001457 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001458
Benny Halevy13c65ce2009-08-14 17:19:25 +03001459 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001460 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001461 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001462 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001463 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001464 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465}
1466
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001467static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Al Viro8687b632006-10-19 23:28:48 -07001469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Benny Halevy13c65ce2009-08-14 17:19:25 +03001471 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001472 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001473 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001476 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001477 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1479 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001480 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001481 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001482 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001483 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001486static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Andy Adamson05d564f2008-12-23 16:06:15 -05001488 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Benny Halevy13c65ce2009-08-14 17:19:25 +03001490 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001491 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001492 p = xdr_encode_hyper(p, client_state->cl_clientid);
Benny Halevy34558512009-08-14 17:19:30 +03001493 xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001494 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001495 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496}
1497
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001498static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Al Viro8687b632006-10-19 23:28:48 -07001500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Benny Halevy13c65ce2009-08-14 17:19:25 +03001502 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001503 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 encode_stateid(xdr, args->context);
1506
Benny Halevy13c65ce2009-08-14 17:19:25 +03001507 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001508 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001509 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001510 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001513 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001514 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518{
Al Viro8687b632006-10-19 23:28:48 -07001519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Benny Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Benny Halevye75bc1c2009-08-14 17:18:54 +03001523 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001524 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001525 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001526 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001528
Benny Halevy99fe60d2009-04-01 09:22:29 -04001529#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001530/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001531static void encode_exchange_id(struct xdr_stream *xdr,
1532 struct nfs41_exchange_id_args *args,
1533 struct compound_hdr *hdr)
1534{
1535 __be32 *p;
1536
Benny Halevy13c65ce2009-08-14 17:19:25 +03001537 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001538 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001539 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001540
1541 encode_string(xdr, args->id_len, args->id);
1542
Benny Halevy13c65ce2009-08-14 17:19:25 +03001543 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001544 *p++ = cpu_to_be32(args->flags);
1545 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001546 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001547 hdr->nops++;
1548 hdr->replen += decode_exchange_id_maxsz;
1549}
Andy Adamsonfc931582009-04-01 09:22:31 -04001550
1551static void encode_create_session(struct xdr_stream *xdr,
1552 struct nfs41_create_session_args *args,
1553 struct compound_hdr *hdr)
1554{
1555 __be32 *p;
1556 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1557 uint32_t len;
1558 struct nfs_client *clp = args->client;
1559
Andy Adamsonfc931582009-04-01 09:22:31 -04001560 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1561 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001562
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001564 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001565 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001566 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1567 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001568
Andy Adamsonfc931582009-04-01 09:22:31 -04001569 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001570 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1571 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1572 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1573 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1574 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1575 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1576 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001577
1578 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001579 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1580 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1581 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1582 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1583 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1584 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1585 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001586
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001588 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001589 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001590
1591 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001592 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001593 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(0); /* UID */
1595 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001596 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001597 hdr->nops++;
1598 hdr->replen += decode_create_session_maxsz;
1599}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001600
1601static void encode_destroy_session(struct xdr_stream *xdr,
1602 struct nfs4_session *session,
1603 struct compound_hdr *hdr)
1604{
1605 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001606 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001608 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001609 hdr->nops++;
1610 hdr->replen += decode_destroy_session_maxsz;
1611}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001612#endif /* CONFIG_NFS_V4_1 */
1613
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001614static void encode_sequence(struct xdr_stream *xdr,
1615 const struct nfs4_sequence_args *args,
1616 struct compound_hdr *hdr)
1617{
1618#if defined(CONFIG_NFS_V4_1)
1619 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001620 struct nfs4_slot_table *tp;
1621 struct nfs4_slot *slot;
1622 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001623
1624 if (!session)
1625 return;
1626
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001627 tp = &session->fc_slot_table;
1628
1629 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1630 slot = tp->slots + args->sa_slotid;
1631
Benny Halevy13c65ce2009-08-14 17:19:25 +03001632 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001633 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001634
1635 /*
1636 * Sessionid + seqid + slotid + max slotid + cache_this
1637 */
1638 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1639 "max_slotid=%d cache_this=%d\n",
1640 __func__,
1641 ((u32 *)session->sess_id.data)[0],
1642 ((u32 *)session->sess_id.data)[1],
1643 ((u32 *)session->sess_id.data)[2],
1644 ((u32 *)session->sess_id.data)[3],
1645 slot->seq_nr, args->sa_slotid,
1646 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001647 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001648 *p++ = cpu_to_be32(slot->seq_nr);
1649 *p++ = cpu_to_be32(args->sa_slotid);
1650 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001651 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001652 hdr->nops++;
1653 hdr->replen += decode_sequence_maxsz;
1654#endif /* CONFIG_NFS_V4_1 */
1655}
1656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657/*
1658 * END OF "GENERIC" ENCODE ROUTINES.
1659 */
1660
Benny Halevy66cc0422009-04-01 09:22:10 -04001661static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1662{
1663#if defined(CONFIG_NFS_V4_1)
1664 if (args->sa_session)
1665 return args->sa_session->clp->cl_minorversion;
1666#endif /* CONFIG_NFS_V4_1 */
1667 return 0;
1668}
1669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670/*
1671 * Encode an ACCESS request
1672 */
Al Viro8687b632006-10-19 23:28:48 -07001673static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674{
1675 struct xdr_stream xdr;
1676 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001677 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
1680 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001681 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001682 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683 encode_putfh(&xdr, args->fh, &hdr);
1684 encode_access(&xdr, args->access, &hdr);
1685 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001686 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001687 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
1690/*
1691 * Encode LOOKUP request
1692 */
Al Viro8687b632006-10-19 23:28:48 -07001693static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 struct xdr_stream xdr;
1696 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001697 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
1700 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001701 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001702 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001703 encode_putfh(&xdr, args->dir_fh, &hdr);
1704 encode_lookup(&xdr, args->name, &hdr);
1705 encode_getfh(&xdr, &hdr);
1706 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001707 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001708 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709}
1710
1711/*
1712 * Encode LOOKUP_ROOT request
1713 */
Al Viro8687b632006-10-19 23:28:48 -07001714static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715{
1716 struct xdr_stream xdr;
1717 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001718 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001722 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001723 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001724 encode_putrootfh(&xdr, &hdr);
1725 encode_getfh(&xdr, &hdr);
1726 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001727 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001728 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729}
1730
1731/*
1732 * Encode REMOVE request
1733 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001734static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735{
1736 struct xdr_stream xdr;
1737 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001738 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001742 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001743 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001744 encode_putfh(&xdr, args->fh, &hdr);
1745 encode_remove(&xdr, &args->name, &hdr);
1746 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001747 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001748 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
1751/*
1752 * Encode RENAME request
1753 */
Al Viro8687b632006-10-19 23:28:48 -07001754static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
1756 struct xdr_stream xdr;
1757 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001758 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001762 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001763 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001764 encode_putfh(&xdr, args->old_dir, &hdr);
1765 encode_savefh(&xdr, &hdr);
1766 encode_putfh(&xdr, args->new_dir, &hdr);
1767 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1768 encode_getfattr(&xdr, args->bitmask, &hdr);
1769 encode_restorefh(&xdr, &hdr);
1770 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001771 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001772 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773}
1774
1775/*
1776 * Encode LINK request
1777 */
Al Viro8687b632006-10-19 23:28:48 -07001778static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
1780 struct xdr_stream xdr;
1781 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001782 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
1785 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001786 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001787 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001788 encode_putfh(&xdr, args->fh, &hdr);
1789 encode_savefh(&xdr, &hdr);
1790 encode_putfh(&xdr, args->dir_fh, &hdr);
1791 encode_link(&xdr, args->name, &hdr);
1792 encode_getfattr(&xdr, args->bitmask, &hdr);
1793 encode_restorefh(&xdr, &hdr);
1794 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001795 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001796 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
1798
1799/*
1800 * Encode CREATE request
1801 */
Al Viro8687b632006-10-19 23:28:48 -07001802static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803{
1804 struct xdr_stream xdr;
1805 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001806 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
1809 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001810 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001811 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001812 encode_putfh(&xdr, args->dir_fh, &hdr);
1813 encode_savefh(&xdr, &hdr);
1814 encode_create(&xdr, args, &hdr);
1815 encode_getfh(&xdr, &hdr);
1816 encode_getfattr(&xdr, args->bitmask, &hdr);
1817 encode_restorefh(&xdr, &hdr);
1818 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001819 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001820 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821}
1822
1823/*
1824 * Encode SYMLINK request
1825 */
Al Viro8687b632006-10-19 23:28:48 -07001826static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
1828 return nfs4_xdr_enc_create(req, p, args);
1829}
1830
1831/*
1832 * Encode GETATTR request
1833 */
Al Viro8687b632006-10-19 23:28:48 -07001834static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
1836 struct xdr_stream xdr;
1837 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001838 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
1841 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001842 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001843 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001844 encode_putfh(&xdr, args->fh, &hdr);
1845 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001846 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001847 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848}
1849
1850/*
1851 * Encode a CLOSE request
1852 */
Al Viro8687b632006-10-19 23:28:48 -07001853static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854{
Andy Adamson05d564f2008-12-23 16:06:15 -05001855 struct xdr_stream xdr;
1856 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001857 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001858 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Andy Adamson05d564f2008-12-23 16:06:15 -05001860 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001861 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001862 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001863 encode_putfh(&xdr, args->fh, &hdr);
1864 encode_close(&xdr, args, &hdr);
1865 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001866 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001867 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868}
1869
1870/*
1871 * Encode an OPEN request
1872 */
Al Viro8687b632006-10-19 23:28:48 -07001873static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874{
1875 struct xdr_stream xdr;
1876 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001877 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001881 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001882 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001883 encode_putfh(&xdr, args->fh, &hdr);
1884 encode_savefh(&xdr, &hdr);
1885 encode_open(&xdr, args, &hdr);
1886 encode_getfh(&xdr, &hdr);
1887 encode_getfattr(&xdr, args->bitmask, &hdr);
1888 encode_restorefh(&xdr, &hdr);
1889 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001890 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001891 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892}
1893
1894/*
1895 * Encode an OPEN_CONFIRM request
1896 */
Al Viro8687b632006-10-19 23:28:48 -07001897static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898{
1899 struct xdr_stream xdr;
1900 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001901 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
1904 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001905 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001906 encode_putfh(&xdr, args->fh, &hdr);
1907 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001908 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001909 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910}
1911
1912/*
1913 * Encode an OPEN request with no attributes.
1914 */
Al Viro8687b632006-10-19 23:28:48 -07001915static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
1917 struct xdr_stream xdr;
1918 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001919 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001923 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001924 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001925 encode_putfh(&xdr, args->fh, &hdr);
1926 encode_open(&xdr, args, &hdr);
1927 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001928 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001929 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930}
1931
1932/*
1933 * Encode an OPEN_DOWNGRADE request
1934 */
Al Viro8687b632006-10-19 23:28:48 -07001935static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936{
1937 struct xdr_stream xdr;
1938 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
1942 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001943 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001944 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001945 encode_putfh(&xdr, args->fh, &hdr);
1946 encode_open_downgrade(&xdr, args, &hdr);
1947 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001948 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001949 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950}
1951
1952/*
1953 * Encode a LOCK request
1954 */
Al Viro8687b632006-10-19 23:28:48 -07001955static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956{
1957 struct xdr_stream xdr;
1958 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001959 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
1962 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001963 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001964 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001965 encode_putfh(&xdr, args->fh, &hdr);
1966 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001967 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001968 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969}
1970
1971/*
1972 * Encode a LOCKT request
1973 */
Al Viro8687b632006-10-19 23:28:48 -07001974static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975{
1976 struct xdr_stream xdr;
1977 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001978 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001982 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001983 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001984 encode_putfh(&xdr, args->fh, &hdr);
1985 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001986 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001987 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988}
1989
1990/*
1991 * Encode a LOCKU request
1992 */
Al Viro8687b632006-10-19 23:28:48 -07001993static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
1995 struct xdr_stream xdr;
1996 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001997 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002001 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002002 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002003 encode_putfh(&xdr, args->fh, &hdr);
2004 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002005 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002006 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
2009/*
2010 * Encode a READLINK request
2011 */
Al Viro8687b632006-10-19 23:28:48 -07002012static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013{
2014 struct xdr_stream xdr;
2015 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002016 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002020 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002021 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002022 encode_putfh(&xdr, args->fh, &hdr);
2023 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002024
Benny Halevy28f56692009-04-01 09:22:09 -04002025 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002026 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002027 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029}
2030
2031/*
2032 * Encode a READDIR request
2033 */
Al Viro8687b632006-10-19 23:28:48 -07002034static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
2036 struct xdr_stream xdr;
2037 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002038 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002042 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002043 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002044 encode_putfh(&xdr, args->fh, &hdr);
2045 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002046
Benny Halevy28f56692009-04-01 09:22:09 -04002047 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002048 args->pgbase, args->count);
2049 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002050 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002051 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002052 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002053 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054}
2055
2056/*
2057 * Encode a READ request
2058 */
Al Viro8687b632006-10-19 23:28:48 -07002059static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 struct xdr_stream xdr;
2062 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002063 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002067 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002068 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002069 encode_putfh(&xdr, args->fh, &hdr);
2070 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Benny Halevy28f56692009-04-01 09:22:09 -04002072 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002074 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002075 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002076 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077}
2078
2079/*
2080 * Encode an SETATTR request
2081 */
Al Viro8687b632006-10-19 23:28:48 -07002082static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083{
Andy Adamson05d564f2008-12-23 16:06:15 -05002084 struct xdr_stream xdr;
2085 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002086 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002087 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
Andy Adamson05d564f2008-12-23 16:06:15 -05002089 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002090 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002091 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002092 encode_putfh(&xdr, args->fh, &hdr);
2093 encode_setattr(&xdr, args, args->server, &hdr);
2094 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002095 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002096 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
2099/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002100 * Encode a GETACL request
2101 */
2102static int
Al Viro8687b632006-10-19 23:28:48 -07002103nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002104 struct nfs_getaclargs *args)
2105{
2106 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002107 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002109 };
Benny Halevy28f56692009-04-01 09:22:09 -04002110 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002111
2112 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002113 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002114 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002115 encode_putfh(&xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002116 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002117 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2118
Benny Halevy28f56692009-04-01 09:22:09 -04002119 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002120 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002121 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002122 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002123}
2124
2125/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 * Encode a WRITE request
2127 */
Al Viro8687b632006-10-19 23:28:48 -07002128static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 struct xdr_stream xdr;
2131 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
2135 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002136 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002137 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002138 encode_putfh(&xdr, args->fh, &hdr);
2139 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002140 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002141 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002142 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002143 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146/*
2147 * a COMMIT request
2148 */
Al Viro8687b632006-10-19 23:28:48 -07002149static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
2151 struct xdr_stream xdr;
2152 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
2156 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002157 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002158 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002159 encode_putfh(&xdr, args->fh, &hdr);
2160 encode_commit(&xdr, args, &hdr);
2161 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002162 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002163 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
2166/*
2167 * FSINFO request
2168 */
Al Viro8687b632006-10-19 23:28:48 -07002169static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
2171 struct xdr_stream xdr;
2172 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002173 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002177 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002178 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002179 encode_putfh(&xdr, args->fh, &hdr);
2180 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002181 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002182 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * a PATHCONF request
2187 */
Al Viro8687b632006-10-19 23:28:48 -07002188static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 struct xdr_stream xdr;
2191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
2195 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002196 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002197 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002198 encode_putfh(&xdr, args->fh, &hdr);
2199 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2200 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002202 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203}
2204
2205/*
2206 * a STATFS request
2207 */
Al Viro8687b632006-10-19 23:28:48 -07002208static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct xdr_stream xdr;
2211 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002212 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002216 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002217 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002218 encode_putfh(&xdr, args->fh, &hdr);
2219 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2220 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002221 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225/*
2226 * GETATTR_BITMAP request
2227 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002228static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2229 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
2231 struct xdr_stream xdr;
2232 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002233 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
2236 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002237 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002238 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002239 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002240 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2241 FATTR4_WORD0_LINK_SUPPORT|
2242 FATTR4_WORD0_SYMLINK_SUPPORT|
2243 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002244 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002245 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * a RENEW request
2250 */
Al Viro8687b632006-10-19 23:28:48 -07002251static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
2253 struct xdr_stream xdr;
2254 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002255 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
2257
2258 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002259 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002260 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002261 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002262 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263}
2264
2265/*
2266 * a SETCLIENTID request
2267 */
Al Viro8687b632006-10-19 23:28:48 -07002268static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269{
2270 struct xdr_stream xdr;
2271 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002272 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 };
2274
2275 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002276 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002277 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002278 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
2282/*
2283 * a SETCLIENTID_CONFIRM request
2284 */
Al Viro8687b632006-10-19 23:28:48 -07002285static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
2287 struct xdr_stream xdr;
2288 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002289 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 };
2291 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002294 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002295 encode_setclientid_confirm(&xdr, clp, &hdr);
2296 encode_putrootfh(&xdr, &hdr);
2297 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002298 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002299 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
2302/*
2303 * DELEGRETURN request
2304 */
Al Viro8687b632006-10-19 23:28:48 -07002305static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
2307 struct xdr_stream xdr;
2308 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002309 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002313 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002314 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002315 encode_putfh(&xdr, args->fhandle, &hdr);
2316 encode_delegreturn(&xdr, args->stateid, &hdr);
2317 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002318 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002319 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320}
2321
2322/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002323 * Encode FS_LOCATIONS request
2324 */
Al Viro8687b632006-10-19 23:28:48 -07002325static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002326{
2327 struct xdr_stream xdr;
2328 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002329 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002330 };
Benny Halevy28f56692009-04-01 09:22:09 -04002331 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002332
2333 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002334 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002335 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002336 encode_putfh(&xdr, args->dir_fh, &hdr);
2337 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002338 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002339 encode_fs_locations(&xdr, args->bitmask, &hdr);
2340
Benny Halevy28f56692009-04-01 09:22:09 -04002341 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002342 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002344 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002345}
2346
Benny Halevy99fe60d2009-04-01 09:22:29 -04002347#if defined(CONFIG_NFS_V4_1)
2348/*
2349 * EXCHANGE_ID request
2350 */
2351static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2352 struct nfs41_exchange_id_args *args)
2353{
2354 struct xdr_stream xdr;
2355 struct compound_hdr hdr = {
2356 .minorversion = args->client->cl_minorversion,
2357 };
2358
2359 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2360 encode_compound_hdr(&xdr, req, &hdr);
2361 encode_exchange_id(&xdr, args, &hdr);
2362 encode_nops(&hdr);
2363 return 0;
2364}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002365
2366/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002367 * a CREATE_SESSION request
2368 */
2369static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2370 struct nfs41_create_session_args *args)
2371{
2372 struct xdr_stream xdr;
2373 struct compound_hdr hdr = {
2374 .minorversion = args->client->cl_minorversion,
2375 };
2376
2377 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2378 encode_compound_hdr(&xdr, req, &hdr);
2379 encode_create_session(&xdr, args, &hdr);
2380 encode_nops(&hdr);
2381 return 0;
2382}
2383
2384/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002385 * a DESTROY_SESSION request
2386 */
2387static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2388 struct nfs4_session *session)
2389{
2390 struct xdr_stream xdr;
2391 struct compound_hdr hdr = {
2392 .minorversion = session->clp->cl_minorversion,
2393 };
2394
2395 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2396 encode_compound_hdr(&xdr, req, &hdr);
2397 encode_destroy_session(&xdr, session, &hdr);
2398 encode_nops(&hdr);
2399 return 0;
2400}
2401
2402/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002403 * a SEQUENCE request
2404 */
2405static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2406 struct nfs4_sequence_args *args)
2407{
2408 struct xdr_stream xdr;
2409 struct compound_hdr hdr = {
2410 .minorversion = nfs4_xdr_minorversion(args),
2411 };
2412
2413 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2414 encode_compound_hdr(&xdr, req, &hdr);
2415 encode_sequence(&xdr, args, &hdr);
2416 encode_nops(&hdr);
2417 return 0;
2418}
2419
2420/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002421 * a GET_LEASE_TIME request
2422 */
2423static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2424 struct nfs4_get_lease_time_args *args)
2425{
2426 struct xdr_stream xdr;
2427 struct compound_hdr hdr = {
2428 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2429 };
2430 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2431
2432 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2433 encode_compound_hdr(&xdr, req, &hdr);
2434 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2435 encode_putrootfh(&xdr, &hdr);
2436 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2437 encode_nops(&hdr);
2438 return 0;
2439}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002440#endif /* CONFIG_NFS_V4_1 */
2441
Benny Halevy686841b2009-08-14 17:19:48 +03002442static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2443{
2444 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2445 "Remaining buffer length is %tu words.\n",
2446 func, xdr->end - xdr->p);
2447}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Trond Myklebust683b57b2006-06-09 09:34:22 -04002449static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450{
Al Viro8687b632006-10-19 23:28:48 -07002451 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Benny Halevyc0eae662009-08-14 17:20:14 +03002453 p = xdr_inline_decode(xdr, 4);
2454 if (unlikely(!p))
2455 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002456 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002457 p = xdr_inline_decode(xdr, *len);
2458 if (unlikely(!p))
2459 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 *string = (char *)p;
2461 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002462out_overflow:
2463 print_overflow_msg(__func__, xdr);
2464 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465}
2466
2467static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2468{
Al Viro8687b632006-10-19 23:28:48 -07002469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
Benny Halevyc0eae662009-08-14 17:20:14 +03002471 p = xdr_inline_decode(xdr, 8);
2472 if (unlikely(!p))
2473 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002474 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002475 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002476
Benny Halevyc0eae662009-08-14 17:20:14 +03002477 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2478 if (unlikely(!p))
2479 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 hdr->tag = (char *)p;
2481 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002482 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002483 if (unlikely(hdr->nops < 1))
2484 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002486out_overflow:
2487 print_overflow_msg(__func__, xdr);
2488 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489}
2490
2491static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2492{
Al Viro8687b632006-10-19 23:28:48 -07002493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 uint32_t opnum;
2495 int32_t nfserr;
2496
Benny Halevyc0eae662009-08-14 17:20:14 +03002497 p = xdr_inline_decode(xdr, 8);
2498 if (unlikely(!p))
2499 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002500 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002502 dprintk("nfs: Server returned operation"
2503 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 opnum, expected);
2505 return -EIO;
2506 }
Benny Halevycccddf42009-08-14 17:20:19 +03002507 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002509 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002511out_overflow:
2512 print_overflow_msg(__func__, xdr);
2513 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514}
2515
2516/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002517static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
Al Viro8687b632006-10-19 23:28:48 -07002519 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002520 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 char *str;
2522
Benny Halevyc0eae662009-08-14 17:20:14 +03002523 p = xdr_inline_decode(xdr, 12);
2524 if (likely(p))
2525 return decode_opaque_inline(xdr, &strlen, &str);
2526 print_overflow_msg(__func__, xdr);
2527 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2531{
Al Viro8687b632006-10-19 23:28:48 -07002532 uint32_t bmlen;
2533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Benny Halevyc0eae662009-08-14 17:20:14 +03002535 p = xdr_inline_decode(xdr, 4);
2536 if (unlikely(!p))
2537 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002538 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
2540 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002541 p = xdr_inline_decode(xdr, (bmlen << 2));
2542 if (unlikely(!p))
2543 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002545 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002547 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 }
2549 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002550out_overflow:
2551 print_overflow_msg(__func__, xdr);
2552 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553}
2554
Al Viro8687b632006-10-19 23:28:48 -07002555static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
Al Viro8687b632006-10-19 23:28:48 -07002557 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Benny Halevyc0eae662009-08-14 17:20:14 +03002559 p = xdr_inline_decode(xdr, 4);
2560 if (unlikely(!p))
2561 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002562 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 *savep = xdr->p;
2564 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002565out_overflow:
2566 print_overflow_msg(__func__, xdr);
2567 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2571{
2572 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2573 decode_attr_bitmap(xdr, bitmask);
2574 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2575 } else
2576 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002577 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 return 0;
2579}
2580
2581static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2582{
Al Viro8687b632006-10-19 23:28:48 -07002583 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002584 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
2586 *type = 0;
2587 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2588 return -EIO;
2589 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002590 p = xdr_inline_decode(xdr, 4);
2591 if (unlikely(!p))
2592 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002593 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002595 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 return -EIO;
2597 }
2598 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002599 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002601 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002602 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002603out_overflow:
2604 print_overflow_msg(__func__, xdr);
2605 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606}
2607
2608static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2609{
Al Viro8687b632006-10-19 23:28:48 -07002610 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002611 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
2613 *change = 0;
2614 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2615 return -EIO;
2616 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002617 p = xdr_inline_decode(xdr, 8);
2618 if (unlikely(!p))
2619 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002620 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002622 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002624 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002626 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002627out_overflow:
2628 print_overflow_msg(__func__, xdr);
2629 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630}
2631
2632static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2633{
Al Viro8687b632006-10-19 23:28:48 -07002634 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002635 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
2637 *size = 0;
2638 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2639 return -EIO;
2640 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002641 p = xdr_inline_decode(xdr, 8);
2642 if (unlikely(!p))
2643 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002644 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002646 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002648 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002649 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002650out_overflow:
2651 print_overflow_msg(__func__, xdr);
2652 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653}
2654
2655static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2656{
Al Viro8687b632006-10-19 23:28:48 -07002657 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
2659 *res = 0;
2660 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2661 return -EIO;
2662 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002663 p = xdr_inline_decode(xdr, 4);
2664 if (unlikely(!p))
2665 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002666 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2668 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002669 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002671out_overflow:
2672 print_overflow_msg(__func__, xdr);
2673 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674}
2675
2676static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2677{
Al Viro8687b632006-10-19 23:28:48 -07002678 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
2680 *res = 0;
2681 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2682 return -EIO;
2683 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002684 p = xdr_inline_decode(xdr, 4);
2685 if (unlikely(!p))
2686 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002687 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002690 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002692out_overflow:
2693 print_overflow_msg(__func__, xdr);
2694 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695}
2696
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002697static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698{
Al Viro8687b632006-10-19 23:28:48 -07002699 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002700 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
2702 fsid->major = 0;
2703 fsid->minor = 0;
2704 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2705 return -EIO;
2706 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002707 p = xdr_inline_decode(xdr, 16);
2708 if (unlikely(!p))
2709 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002710 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002711 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002713 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002715 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 (unsigned long long)fsid->major,
2717 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002718 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002719out_overflow:
2720 print_overflow_msg(__func__, xdr);
2721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722}
2723
2724static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2725{
Al Viro8687b632006-10-19 23:28:48 -07002726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
2728 *res = 60;
2729 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2730 return -EIO;
2731 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002732 p = xdr_inline_decode(xdr, 4);
2733 if (unlikely(!p))
2734 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002735 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2737 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002738 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002740out_overflow:
2741 print_overflow_msg(__func__, xdr);
2742 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743}
2744
2745static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2746{
Al Viro8687b632006-10-19 23:28:48 -07002747 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
2749 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2750 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2751 return -EIO;
2752 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002753 p = xdr_inline_decode(xdr, 4);
2754 if (unlikely(!p))
2755 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002756 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2758 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002759 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002761out_overflow:
2762 print_overflow_msg(__func__, xdr);
2763 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764}
2765
2766static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2767{
Al Viro8687b632006-10-19 23:28:48 -07002768 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002769 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
2771 *fileid = 0;
2772 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2773 return -EIO;
2774 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002775 p = xdr_inline_decode(xdr, 8);
2776 if (unlikely(!p))
2777 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002778 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002780 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002782 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002783 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002784out_overflow:
2785 print_overflow_msg(__func__, xdr);
2786 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787}
2788
Manoj Naik99baf622006-06-09 09:34:24 -04002789static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2790{
Al Viro8687b632006-10-19 23:28:48 -07002791 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002792 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002793
2794 *fileid = 0;
2795 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2796 return -EIO;
2797 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002798 p = xdr_inline_decode(xdr, 8);
2799 if (unlikely(!p))
2800 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002801 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002802 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002803 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002804 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002805 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002806 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002807out_overflow:
2808 print_overflow_msg(__func__, xdr);
2809 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002810}
2811
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2813{
Al Viro8687b632006-10-19 23:28:48 -07002814 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 int status = 0;
2816
2817 *res = 0;
2818 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2819 return -EIO;
2820 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002821 p = xdr_inline_decode(xdr, 8);
2822 if (unlikely(!p))
2823 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002824 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2826 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002827 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002829out_overflow:
2830 print_overflow_msg(__func__, xdr);
2831 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832}
2833
2834static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2835{
Al Viro8687b632006-10-19 23:28:48 -07002836 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 int status = 0;
2838
2839 *res = 0;
2840 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2841 return -EIO;
2842 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002843 p = xdr_inline_decode(xdr, 8);
2844 if (unlikely(!p))
2845 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002846 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2848 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002849 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002851out_overflow:
2852 print_overflow_msg(__func__, xdr);
2853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854}
2855
2856static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2857{
Al Viro8687b632006-10-19 23:28:48 -07002858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 int status = 0;
2860
2861 *res = 0;
2862 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2863 return -EIO;
2864 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002865 p = xdr_inline_decode(xdr, 8);
2866 if (unlikely(!p))
2867 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002868 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2870 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002871 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002873out_overflow:
2874 print_overflow_msg(__func__, xdr);
2875 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876}
2877
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002878static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2879{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002880 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002881 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002882 int status = 0;
2883
Benny Halevyc0eae662009-08-14 17:20:14 +03002884 p = xdr_inline_decode(xdr, 4);
2885 if (unlikely(!p))
2886 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002887 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04002888 if (n == 0)
2889 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002890 dprintk("path ");
2891 path->ncomponents = 0;
2892 while (path->ncomponents < n) {
2893 struct nfs4_string *component = &path->components[path->ncomponents];
2894 status = decode_opaque_inline(xdr, &component->len, &component->data);
2895 if (unlikely(status != 0))
2896 goto out_eio;
2897 if (path->ncomponents != n)
2898 dprintk("/");
2899 dprintk("%s", component->data);
2900 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2901 path->ncomponents++;
2902 else {
2903 dprintk("cannot parse %d components in path\n", n);
2904 goto out_eio;
2905 }
2906 }
2907out:
2908 dprintk("\n");
2909 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002910root_path:
2911/* a root pathname is sent as a zero component4 */
2912 path->ncomponents = 1;
2913 path->components[0].len=0;
2914 path->components[0].data=NULL;
2915 dprintk("path /\n");
2916 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002917out_eio:
2918 dprintk(" status %d", status);
2919 status = -EIO;
2920 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002921out_overflow:
2922 print_overflow_msg(__func__, xdr);
2923 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002924}
2925
2926static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002927{
2928 int n;
Al Viro8687b632006-10-19 23:28:48 -07002929 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002930 int status = -EIO;
2931
2932 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2933 goto out;
2934 status = 0;
2935 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2936 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002937 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002938 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002939 if (unlikely(status != 0))
2940 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002941 p = xdr_inline_decode(xdr, 4);
2942 if (unlikely(!p))
2943 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002944 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002945 if (n <= 0)
2946 goto out_eio;
2947 res->nlocations = 0;
2948 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002949 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002950 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002951
Benny Halevyc0eae662009-08-14 17:20:14 +03002952 p = xdr_inline_decode(xdr, 4);
2953 if (unlikely(!p))
2954 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002955 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002956
2957 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002958 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002959 while (loc->nservers < m) {
2960 struct nfs4_string *server = &loc->servers[loc->nservers];
2961 status = decode_opaque_inline(xdr, &server->len, &server->data);
2962 if (unlikely(status != 0))
2963 goto out_eio;
2964 dprintk("%s ", server->data);
2965 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2966 loc->nservers++;
2967 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002968 unsigned int i;
2969 dprintk("%s: using first %u of %u servers "
2970 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002971 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002972 NFS4_FS_LOCATION_MAXSERVERS,
2973 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002974 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002975 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002976 char *data;
2977 status = decode_opaque_inline(xdr, &len, &data);
2978 if (unlikely(status != 0))
2979 goto out_eio;
2980 }
2981 }
2982 }
2983 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002984 if (unlikely(status != 0))
2985 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002986 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002987 res->nlocations++;
2988 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002989 if (res->nlocations != 0)
2990 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002991out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002992 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002993 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002994out_overflow:
2995 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002996out_eio:
2997 status = -EIO;
2998 goto out;
2999}
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3002{
Al Viro8687b632006-10-19 23:28:48 -07003003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 int status = 0;
3005
3006 *res = 0;
3007 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3008 return -EIO;
3009 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003010 p = xdr_inline_decode(xdr, 8);
3011 if (unlikely(!p))
3012 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003013 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3015 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003016 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003018out_overflow:
3019 print_overflow_msg(__func__, xdr);
3020 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021}
3022
3023static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3024{
Al Viro8687b632006-10-19 23:28:48 -07003025 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 int status = 0;
3027
3028 *maxlink = 1;
3029 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3030 return -EIO;
3031 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003032 p = xdr_inline_decode(xdr, 4);
3033 if (unlikely(!p))
3034 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003035 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3037 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003038 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003040out_overflow:
3041 print_overflow_msg(__func__, xdr);
3042 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043}
3044
3045static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3046{
Al Viro8687b632006-10-19 23:28:48 -07003047 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 int status = 0;
3049
3050 *maxname = 1024;
3051 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3052 return -EIO;
3053 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003054 p = xdr_inline_decode(xdr, 4);
3055 if (unlikely(!p))
3056 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003057 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3059 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003060 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003062out_overflow:
3063 print_overflow_msg(__func__, xdr);
3064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065}
3066
3067static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3068{
Al Viro8687b632006-10-19 23:28:48 -07003069 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 int status = 0;
3071
3072 *res = 1024;
3073 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3074 return -EIO;
3075 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3076 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003077 p = xdr_inline_decode(xdr, 8);
3078 if (unlikely(!p))
3079 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003080 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 if (maxread > 0x7FFFFFFF)
3082 maxread = 0x7FFFFFFF;
3083 *res = (uint32_t)maxread;
3084 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3085 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003086 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003088out_overflow:
3089 print_overflow_msg(__func__, xdr);
3090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
3093static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3094{
Al Viro8687b632006-10-19 23:28:48 -07003095 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 int status = 0;
3097
3098 *res = 1024;
3099 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3100 return -EIO;
3101 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3102 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003103 p = xdr_inline_decode(xdr, 8);
3104 if (unlikely(!p))
3105 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003106 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 if (maxwrite > 0x7FFFFFFF)
3108 maxwrite = 0x7FFFFFFF;
3109 *res = (uint32_t)maxwrite;
3110 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3111 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003112 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003114out_overflow:
3115 print_overflow_msg(__func__, xdr);
3116 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117}
3118
Trond Myklebustbca79472009-03-11 14:10:26 -04003119static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120{
Trond Myklebustbca79472009-03-11 14:10:26 -04003121 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003122 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003123 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 *mode = 0;
3126 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3127 return -EIO;
3128 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003129 p = xdr_inline_decode(xdr, 4);
3130 if (unlikely(!p))
3131 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003132 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003133 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003135 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003137 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003138 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003139out_overflow:
3140 print_overflow_msg(__func__, xdr);
3141 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
3144static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3145{
Al Viro8687b632006-10-19 23:28:48 -07003146 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003147 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 *nlink = 1;
3150 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3151 return -EIO;
3152 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003153 p = xdr_inline_decode(xdr, 4);
3154 if (unlikely(!p))
3155 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003156 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003158 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003160 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003161 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003162out_overflow:
3163 print_overflow_msg(__func__, xdr);
3164 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165}
3166
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003167static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3168 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
Al Viro8687b632006-10-19 23:28:48 -07003170 uint32_t len;
3171 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003172 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
3174 *uid = -2;
3175 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3176 return -EIO;
3177 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003178 p = xdr_inline_decode(xdr, 4);
3179 if (unlikely(!p))
3180 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003181 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003182 p = xdr_inline_decode(xdr, len);
3183 if (unlikely(!p))
3184 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003185 if (!may_sleep) {
3186 /* do nothing */
3187 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003188 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3189 ret = NFS_ATTR_FATTR_OWNER;
3190 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003192 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003194 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003195 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3197 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003198 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003199 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003200out_overflow:
3201 print_overflow_msg(__func__, xdr);
3202 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203}
3204
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003205static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3206 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207{
Al Viro8687b632006-10-19 23:28:48 -07003208 uint32_t len;
3209 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003210 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
3212 *gid = -2;
3213 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3214 return -EIO;
3215 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003216 p = xdr_inline_decode(xdr, 4);
3217 if (unlikely(!p))
3218 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003219 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003220 p = xdr_inline_decode(xdr, len);
3221 if (unlikely(!p))
3222 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003223 if (!may_sleep) {
3224 /* do nothing */
3225 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003226 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3227 ret = NFS_ATTR_FATTR_GROUP;
3228 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003230 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003232 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003233 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3235 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003236 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003237 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003238out_overflow:
3239 print_overflow_msg(__func__, xdr);
3240 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241}
3242
3243static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3244{
Al Viro8687b632006-10-19 23:28:48 -07003245 uint32_t major = 0, minor = 0;
3246 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003247 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
3249 *rdev = MKDEV(0,0);
3250 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3251 return -EIO;
3252 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3253 dev_t tmp;
3254
Benny Halevyc0eae662009-08-14 17:20:14 +03003255 p = xdr_inline_decode(xdr, 8);
3256 if (unlikely(!p))
3257 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003258 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003259 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 tmp = MKDEV(major, minor);
3261 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3262 *rdev = tmp;
3263 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003264 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003266 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271}
3272
3273static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 int status = 0;
3277
3278 *res = 0;
3279 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3280 return -EIO;
3281 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003282 p = xdr_inline_decode(xdr, 8);
3283 if (unlikely(!p))
3284 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003285 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3287 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003288 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003290out_overflow:
3291 print_overflow_msg(__func__, xdr);
3292 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293}
3294
3295static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 int status = 0;
3299
3300 *res = 0;
3301 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3302 return -EIO;
3303 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003304 p = xdr_inline_decode(xdr, 8);
3305 if (unlikely(!p))
3306 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003307 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3309 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003310 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315}
3316
3317static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3318{
Al Viro8687b632006-10-19 23:28:48 -07003319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 int status = 0;
3321
3322 *res = 0;
3323 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3324 return -EIO;
3325 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003326 p = xdr_inline_decode(xdr, 8);
3327 if (unlikely(!p))
3328 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003329 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3331 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003332 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003334out_overflow:
3335 print_overflow_msg(__func__, xdr);
3336 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337}
3338
3339static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3340{
Al Viro8687b632006-10-19 23:28:48 -07003341 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 *used = 0;
3345 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3346 return -EIO;
3347 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 8);
3349 if (unlikely(!p))
3350 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003351 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003357 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003358out_overflow:
3359 print_overflow_msg(__func__, xdr);
3360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361}
3362
3363static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3364{
Al Viro8687b632006-10-19 23:28:48 -07003365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 uint64_t sec;
3367 uint32_t nsec;
3368
Benny Halevyc0eae662009-08-14 17:20:14 +03003369 p = xdr_inline_decode(xdr, 12);
3370 if (unlikely(!p))
3371 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003372 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003373 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 time->tv_sec = (time_t)sec;
3375 time->tv_nsec = (long)nsec;
3376 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003377out_overflow:
3378 print_overflow_msg(__func__, xdr);
3379 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380}
3381
3382static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3383{
3384 int status = 0;
3385
3386 time->tv_sec = 0;
3387 time->tv_nsec = 0;
3388 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3389 return -EIO;
3390 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3391 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003392 if (status == 0)
3393 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3395 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003396 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 return status;
3398}
3399
3400static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3401{
3402 int status = 0;
3403
3404 time->tv_sec = 0;
3405 time->tv_nsec = 0;
3406 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3407 return -EIO;
3408 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3409 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003410 if (status == 0)
3411 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3413 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003414 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 return status;
3416}
3417
3418static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3419{
3420 int status = 0;
3421
3422 time->tv_sec = 0;
3423 time->tv_nsec = 0;
3424 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3425 return -EIO;
3426 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3427 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003428 if (status == 0)
3429 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3431 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003432 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 return status;
3434}
3435
Al Viro8687b632006-10-19 23:28:48 -07003436static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437{
3438 unsigned int attrwords = XDR_QUADLEN(attrlen);
3439 unsigned int nwords = xdr->p - savep;
3440
3441 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003442 dprintk("%s: server returned incorrect attribute length: "
3443 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003444 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 attrwords << 2,
3446 (attrwords < nwords) ? '<' : '>',
3447 nwords << 2);
3448 return -EIO;
3449 }
3450 return 0;
3451}
3452
3453static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3454{
Al Viro8687b632006-10-19 23:28:48 -07003455 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456
Benny Halevyc0eae662009-08-14 17:20:14 +03003457 p = xdr_inline_decode(xdr, 20);
3458 if (unlikely(!p))
3459 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003460 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003461 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003462 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
3469static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3470{
Al Viro8687b632006-10-19 23:28:48 -07003471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 uint32_t supp, acc;
3473 int status;
3474
3475 status = decode_op_hdr(xdr, OP_ACCESS);
3476 if (status)
3477 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003478 p = xdr_inline_decode(xdr, 8);
3479 if (unlikely(!p))
3480 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003481 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003482 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 access->supported = supp;
3484 access->access = acc;
3485 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003486out_overflow:
3487 print_overflow_msg(__func__, xdr);
3488 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489}
3490
Benny Halevy07d30432009-08-14 17:19:52 +03003491static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492{
Al Viro8687b632006-10-19 23:28:48 -07003493 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003494
3495 p = xdr_inline_decode(xdr, len);
3496 if (likely(p)) {
3497 memcpy(buf, p, len);
3498 return 0;
3499 }
3500 print_overflow_msg(__func__, xdr);
3501 return -EIO;
3502}
3503
3504static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3505{
3506 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507}
3508
3509static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3510{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 int status;
3512
3513 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003514 if (status != -EIO)
3515 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003516 if (!status)
3517 status = decode_stateid(xdr, &res->stateid);
3518 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519}
3520
Benny Halevydb942bb2009-08-14 17:19:56 +03003521static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3522{
3523 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524}
3525
3526static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3527{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 int status;
3529
3530 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003531 if (!status)
3532 status = decode_verifier(xdr, res->verf->verifier);
3533 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
3536static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3537{
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 uint32_t bmlen;
3540 int status;
3541
3542 status = decode_op_hdr(xdr, OP_CREATE);
3543 if (status)
3544 return status;
3545 if ((status = decode_change_info(xdr, cinfo)))
3546 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003547 p = xdr_inline_decode(xdr, 4);
3548 if (unlikely(!p))
3549 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003550 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003551 p = xdr_inline_decode(xdr, bmlen << 2);
3552 if (likely(p))
3553 return 0;
3554out_overflow:
3555 print_overflow_msg(__func__, xdr);
3556 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557}
3558
3559static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3560{
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003562 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 int status;
3564
3565 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3566 goto xdr_error;
3567 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3568 goto xdr_error;
3569 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3570 goto xdr_error;
3571 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3572 goto xdr_error;
3573 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3574 goto xdr_error;
3575 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3576 goto xdr_error;
3577 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3578 goto xdr_error;
3579 status = verify_attr_len(xdr, savep, attrlen);
3580xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003581 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 return status;
3583}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003584
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3586{
Al Viro8687b632006-10-19 23:28:48 -07003587 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003588 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003590
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3592 goto xdr_error;
3593 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3594 goto xdr_error;
3595 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3596 goto xdr_error;
3597
3598 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3599 goto xdr_error;
3600 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3601 goto xdr_error;
3602 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3603 goto xdr_error;
3604 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3605 goto xdr_error;
3606 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3607 goto xdr_error;
3608 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3609 goto xdr_error;
3610
3611 status = verify_attr_len(xdr, savep, attrlen);
3612xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003613 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 return status;
3615}
3616
3617static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3618{
Al Viro8687b632006-10-19 23:28:48 -07003619 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003620 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003622
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3624 goto xdr_error;
3625 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3626 goto xdr_error;
3627 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3628 goto xdr_error;
3629
3630 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3631 goto xdr_error;
3632 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3633 goto xdr_error;
3634
3635 status = verify_attr_len(xdr, savep, attrlen);
3636xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003637 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 return status;
3639}
3640
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003641static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3642 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643{
Al Viro8687b632006-10-19 23:28:48 -07003644 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 uint32_t attrlen,
3646 bitmap[2] = {0},
3647 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003648 int status;
3649 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003650 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003652 status = decode_op_hdr(xdr, OP_GETATTR);
3653 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 goto xdr_error;
3655
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003656 status = decode_attr_bitmap(xdr, bitmap);
3657 if (status < 0)
3658 goto xdr_error;
3659
3660 status = decode_attr_length(xdr, &attrlen, &savep);
3661 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 goto xdr_error;
3663
3664
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003665 status = decode_attr_type(xdr, bitmap, &type);
3666 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003668 fattr->mode = 0;
3669 if (status != 0) {
3670 fattr->mode |= nfs_type2fmt[type];
3671 fattr->valid |= status;
3672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003674 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3675 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003677 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003678
3679 status = decode_attr_size(xdr, bitmap, &fattr->size);
3680 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003682 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003683
3684 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3685 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003687 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003688
3689 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3690 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003692 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003693
3694 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003695 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003696 fattr));
3697 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003698 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003699 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003700
3701 status = decode_attr_mode(xdr, bitmap, &fmode);
3702 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003704 if (status != 0) {
3705 fattr->mode |= fmode;
3706 fattr->valid |= status;
3707 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003708
3709 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3710 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003712 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003713
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003714 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3715 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003716 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003718 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003719
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003720 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3721 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003722 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003724 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003725
3726 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3727 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003729 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003730
3731 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3732 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003734 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003735
3736 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3737 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003739 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003740
3741 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3742 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003744 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003745
3746 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3747 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003750
3751 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3752 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003753 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003754 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003755 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003756 fattr->valid |= status;
3757 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003758
3759 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003761 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 return status;
3763}
3764
3765
3766static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3767{
Al Viro8687b632006-10-19 23:28:48 -07003768 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 uint32_t attrlen, bitmap[2];
3770 int status;
3771
3772 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3773 goto xdr_error;
3774 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3775 goto xdr_error;
3776 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3777 goto xdr_error;
3778
3779 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3780
3781 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3782 goto xdr_error;
3783 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3784 goto xdr_error;
3785 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3786 goto xdr_error;
3787 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3788 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3789 goto xdr_error;
3790 fsinfo->wtpref = fsinfo->wtmax;
3791
3792 status = verify_attr_len(xdr, savep, attrlen);
3793xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003794 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 return status;
3796}
3797
3798static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3799{
Al Viro8687b632006-10-19 23:28:48 -07003800 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 uint32_t len;
3802 int status;
3803
Trond Myklebust99367812007-07-17 21:52:41 -04003804 /* Zero handle first to allow comparisons */
3805 memset(fh, 0, sizeof(*fh));
3806
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 status = decode_op_hdr(xdr, OP_GETFH);
3808 if (status)
3809 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810
Benny Halevyc0eae662009-08-14 17:20:14 +03003811 p = xdr_inline_decode(xdr, 4);
3812 if (unlikely(!p))
3813 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003814 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 if (len > NFS4_FHSIZE)
3816 return -EIO;
3817 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03003818 p = xdr_inline_decode(xdr, len);
3819 if (unlikely(!p))
3820 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03003821 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823out_overflow:
3824 print_overflow_msg(__func__, xdr);
3825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826}
3827
3828static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3829{
3830 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003831
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 status = decode_op_hdr(xdr, OP_LINK);
3833 if (status)
3834 return status;
3835 return decode_change_info(xdr, cinfo);
3836}
3837
3838/*
3839 * We create the owner, so we know a proper owner.id length is 4.
3840 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003841static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003843 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003844 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003845 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
Benny Halevyc0eae662009-08-14 17:20:14 +03003847 p = xdr_inline_decode(xdr, 32);
3848 if (unlikely(!p))
3849 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003850 p = xdr_decode_hyper(p, &offset);
3851 p = xdr_decode_hyper(p, &length);
Benny Halevy6f723f72009-08-14 17:19:37 +03003852 type = be32_to_cpup(p++);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003853 if (fl != NULL) {
3854 fl->fl_start = (loff_t)offset;
3855 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3856 if (length == ~(uint64_t)0)
3857 fl->fl_end = OFFSET_MAX;
3858 fl->fl_type = F_WRLCK;
3859 if (type & 1)
3860 fl->fl_type = F_RDLCK;
3861 fl->fl_pid = 0;
3862 }
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003863 p = xdr_decode_hyper(p, &clientid);
Benny Halevycccddf42009-08-14 17:20:19 +03003864 namelen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003865 p = xdr_inline_decode(xdr, namelen);
3866 if (likely(p))
3867 return -NFS4ERR_DENIED;
3868out_overflow:
3869 print_overflow_msg(__func__, xdr);
3870 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871}
3872
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003873static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 int status;
3876
3877 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003878 if (status == -EIO)
3879 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03003881 status = decode_stateid(xdr, &res->stateid);
3882 if (unlikely(status))
3883 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003885 status = decode_lock_denied(xdr, NULL);
3886 if (res->open_seqid != NULL)
3887 nfs_increment_open_seqid(status, res->open_seqid);
3888 nfs_increment_lock_seqid(status, res->lock_seqid);
3889out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 return status;
3891}
3892
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003893static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894{
3895 int status;
3896 status = decode_op_hdr(xdr, OP_LOCKT);
3897 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003898 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 return status;
3900}
3901
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003902static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 int status;
3905
3906 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003907 if (status != -EIO)
3908 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003909 if (status == 0)
3910 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 return status;
3912}
3913
3914static int decode_lookup(struct xdr_stream *xdr)
3915{
3916 return decode_op_hdr(xdr, OP_LOOKUP);
3917}
3918
3919/* This is too sick! */
3920static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3921{
Andy Adamson05d564f2008-12-23 16:06:15 -05003922 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 uint32_t limit_type, nblocks, blocksize;
3924
Benny Halevyc0eae662009-08-14 17:20:14 +03003925 p = xdr_inline_decode(xdr, 12);
3926 if (unlikely(!p))
3927 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003928 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003930 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03003931 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05003932 break;
3933 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03003934 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003935 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003936 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 }
3938 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003939out_overflow:
3940 print_overflow_msg(__func__, xdr);
3941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942}
3943
3944static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3945{
Andy Adamson05d564f2008-12-23 16:06:15 -05003946 __be32 *p;
3947 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03003948 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949
Benny Halevyc0eae662009-08-14 17:20:14 +03003950 p = xdr_inline_decode(xdr, 4);
3951 if (unlikely(!p))
3952 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003953 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3955 res->delegation_type = 0;
3956 return 0;
3957 }
Benny Halevy07d30432009-08-14 17:19:52 +03003958 status = decode_stateid(xdr, &res->delegation);
3959 if (unlikely(status))
3960 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003961 p = xdr_inline_decode(xdr, 4);
3962 if (unlikely(!p))
3963 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003964 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003965
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003967 case NFS4_OPEN_DELEGATE_READ:
3968 res->delegation_type = FMODE_READ;
3969 break;
3970 case NFS4_OPEN_DELEGATE_WRITE:
3971 res->delegation_type = FMODE_WRITE|FMODE_READ;
3972 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 return -EIO;
3974 }
David Howells7539bba2006-08-22 20:06:09 -04003975 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03003976out_overflow:
3977 print_overflow_msg(__func__, xdr);
3978 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979}
3980
3981static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3982{
Andy Adamson05d564f2008-12-23 16:06:15 -05003983 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003984 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003985 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986
Andy Adamson05d564f2008-12-23 16:06:15 -05003987 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003988 if (status != -EIO)
3989 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003990 if (!status)
3991 status = decode_stateid(xdr, &res->stateid);
3992 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05003993 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994
Andy Adamson05d564f2008-12-23 16:06:15 -05003995 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
Benny Halevyc0eae662009-08-14 17:20:14 +03003997 p = xdr_inline_decode(xdr, 8);
3998 if (unlikely(!p))
3999 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004000 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004001 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004002 if (bmlen > 10)
4003 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004
Benny Halevyc0eae662009-08-14 17:20:14 +03004005 p = xdr_inline_decode(xdr, bmlen << 2);
4006 if (unlikely(!p))
4007 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004008 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4009 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004010 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004011 for (; i < NFS4_BITMAP_SIZE; i++)
4012 res->attrset[i] = 0;
4013
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 return decode_delegation(xdr, res);
4015xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004016 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004018out_overflow:
4019 print_overflow_msg(__func__, xdr);
4020 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021}
4022
4023static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4024{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 int status;
4026
Andy Adamson05d564f2008-12-23 16:06:15 -05004027 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004028 if (status != -EIO)
4029 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004030 if (!status)
4031 status = decode_stateid(xdr, &res->stateid);
4032 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033}
4034
4035static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4036{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 int status;
4038
4039 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004040 if (status != -EIO)
4041 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004042 if (!status)
4043 status = decode_stateid(xdr, &res->stateid);
4044 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045}
4046
4047static int decode_putfh(struct xdr_stream *xdr)
4048{
4049 return decode_op_hdr(xdr, OP_PUTFH);
4050}
4051
4052static int decode_putrootfh(struct xdr_stream *xdr)
4053{
4054 return decode_op_hdr(xdr, OP_PUTROOTFH);
4055}
4056
4057static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4058{
4059 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004060 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 uint32_t count, eof, recvd, hdrlen;
4062 int status;
4063
4064 status = decode_op_hdr(xdr, OP_READ);
4065 if (status)
4066 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004067 p = xdr_inline_decode(xdr, 8);
4068 if (unlikely(!p))
4069 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004070 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004071 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4073 recvd = req->rq_rcv_buf.len - hdrlen;
4074 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004075 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 "count %u > recvd %u\n", count, recvd);
4077 count = recvd;
4078 eof = 0;
4079 }
4080 xdr_read_pages(xdr, count);
4081 res->eof = eof;
4082 res->count = count;
4083 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004084out_overflow:
4085 print_overflow_msg(__func__, xdr);
4086 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087}
4088
4089static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4090{
4091 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4092 struct page *page = *rcvbuf->pages;
4093 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004094 size_t hdrlen;
4095 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07004096 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004097 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04004098 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099
4100 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004101 if (!status)
4102 status = decode_verifier(xdr, readdir->verifier.data);
4103 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004105 dprintk("%s: verifier = %08x:%08x\n",
4106 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004107 ((u32 *)readdir->verifier.data)[0],
4108 ((u32 *)readdir->verifier.data)[1]);
4109
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110
Benny Halevydb942bb2009-08-14 17:19:56 +03004111 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 recvd = rcvbuf->len - hdrlen;
4113 if (pglen > recvd)
4114 pglen = recvd;
4115 xdr_read_pages(xdr, pglen);
4116
4117 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07004118 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04004119 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004121
4122 /* Make sure the packet actually has a value_follows and EOF entry */
4123 if ((entry + 1) > end)
4124 goto short_pkt;
4125
4126 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004127 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04004128 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004130 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 p += 2; /* cookie */
4132 len = ntohl(*p++); /* filename length */
4133 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004134 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4135 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 goto err_unmap;
4137 }
David Howellse8896492006-08-24 15:44:19 -04004138 xlen = XDR_QUADLEN(len);
4139 if (end - p < xlen + 1)
4140 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004141 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04004142 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04004144 if (end - p < len + 1)
4145 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04004148 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04004150 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 entry = p;
4152 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004153 /*
4154 * Apparently some server sends responses that are a valid size, but
4155 * contain no entries, and have value_follows==0 and EOF==0. For
4156 * those, just set the EOF marker.
4157 */
4158 if (!nr && entry[1] == 0) {
4159 dprintk("NFS: readdir reply truncated!\n");
4160 entry[1] = 1;
4161 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05004162out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 kunmap_atomic(kaddr, KM_USER0);
4164 return 0;
4165short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004166 /*
4167 * When we get a short packet there are 2 possibilities. We can
4168 * return an error, or fix up the response to look like a valid
4169 * response and return what we have so far. If there are no
4170 * entries and the packet was short, then return -EIO. If there
4171 * are valid entries in the response, return them and pretend that
4172 * the call was successful, but incomplete. The caller can retry the
4173 * readdir starting at the last cookie.
4174 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07004175 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004177 if (nr)
4178 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179err_unmap:
4180 kunmap_atomic(kaddr, KM_USER0);
4181 return -errno_NFSERR_IO;
4182}
4183
4184static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4185{
4186 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4187 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004188 size_t hdrlen;
4189 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004190 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 char *kaddr;
4192 int status;
4193
4194 status = decode_op_hdr(xdr, OP_READLINK);
4195 if (status)
4196 return status;
4197
4198 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004199 p = xdr_inline_decode(xdr, 4);
4200 if (unlikely(!p))
4201 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004202 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004204 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 return -ENAMETOOLONG;
4206 }
4207 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4208 recvd = req->rq_rcv_buf.len - hdrlen;
4209 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004210 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 "count %u > recvd %u\n", len, recvd);
4212 return -EIO;
4213 }
4214 xdr_read_pages(xdr, len);
4215 /*
4216 * The XDR encode routine has set things up so that
4217 * the link text will be copied directly into the
4218 * buffer. We just have to do overflow-checking,
4219 * and and null-terminate the text (the VFS expects
4220 * null-termination).
4221 */
4222 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4223 kaddr[len+rcvbuf->page_base] = '\0';
4224 kunmap_atomic(kaddr, KM_USER0);
4225 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004226out_overflow:
4227 print_overflow_msg(__func__, xdr);
4228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229}
4230
4231static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4232{
4233 int status;
4234
4235 status = decode_op_hdr(xdr, OP_REMOVE);
4236 if (status)
4237 goto out;
4238 status = decode_change_info(xdr, cinfo);
4239out:
4240 return status;
4241}
4242
4243static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4244 struct nfs4_change_info *new_cinfo)
4245{
4246 int status;
4247
4248 status = decode_op_hdr(xdr, OP_RENAME);
4249 if (status)
4250 goto out;
4251 if ((status = decode_change_info(xdr, old_cinfo)))
4252 goto out;
4253 status = decode_change_info(xdr, new_cinfo);
4254out:
4255 return status;
4256}
4257
4258static int decode_renew(struct xdr_stream *xdr)
4259{
4260 return decode_op_hdr(xdr, OP_RENEW);
4261}
4262
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004263static int
4264decode_restorefh(struct xdr_stream *xdr)
4265{
4266 return decode_op_hdr(xdr, OP_RESTOREFH);
4267}
4268
J. Bruce Fields029d1052005-06-22 17:16:22 +00004269static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4270 size_t *acl_len)
4271{
Al Viro8687b632006-10-19 23:28:48 -07004272 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004273 uint32_t attrlen,
4274 bitmap[2] = {0};
4275 struct kvec *iov = req->rq_rcv_buf.head;
4276 int status;
4277
4278 *acl_len = 0;
4279 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4280 goto out;
4281 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4282 goto out;
4283 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4284 goto out;
4285
4286 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4287 return -EIO;
4288 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004289 size_t hdrlen;
4290 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004291
4292 /* We ignore &savep and don't do consistency checks on
4293 * the attr length. Let userspace figure it out.... */
4294 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4295 recvd = req->rq_rcv_buf.len - hdrlen;
4296 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004297 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004298 " acl reply: attrlen %u > recvd %u\n",
4299 attrlen, recvd);
4300 return -EINVAL;
4301 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004302 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004303 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004304 } else
4305 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004306
4307out:
4308 return status;
4309}
4310
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311static int
4312decode_savefh(struct xdr_stream *xdr)
4313{
4314 return decode_op_hdr(xdr, OP_SAVEFH);
4315}
4316
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004317static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318{
Al Viro8687b632006-10-19 23:28:48 -07004319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 uint32_t bmlen;
4321 int status;
4322
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 status = decode_op_hdr(xdr, OP_SETATTR);
4324 if (status)
4325 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004326 p = xdr_inline_decode(xdr, 4);
4327 if (unlikely(!p))
4328 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004329 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004330 p = xdr_inline_decode(xdr, bmlen << 2);
4331 if (likely(p))
4332 return 0;
4333out_overflow:
4334 print_overflow_msg(__func__, xdr);
4335 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336}
4337
David Howellsadfa6f92006-08-22 20:06:08 -04004338static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339{
Al Viro8687b632006-10-19 23:28:48 -07004340 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341 uint32_t opnum;
4342 int32_t nfserr;
4343
Benny Halevyc0eae662009-08-14 17:20:14 +03004344 p = xdr_inline_decode(xdr, 8);
4345 if (unlikely(!p))
4346 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004347 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004349 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004350 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 return -EIO;
4352 }
Benny Halevycccddf42009-08-14 17:20:19 +03004353 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004355 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4356 if (unlikely(!p))
4357 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004358 p = xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevy99398d02009-08-14 17:20:05 +03004359 memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 } else if (nfserr == NFSERR_CLID_INUSE) {
4361 uint32_t len;
4362
4363 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004364 p = xdr_inline_decode(xdr, 4);
4365 if (unlikely(!p))
4366 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004367 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004368 p = xdr_inline_decode(xdr, len);
4369 if (unlikely(!p))
4370 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371
4372 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004373 p = xdr_inline_decode(xdr, 4);
4374 if (unlikely(!p))
4375 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004376 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004377 p = xdr_inline_decode(xdr, len);
4378 if (unlikely(!p))
4379 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 return -NFSERR_CLID_INUSE;
4381 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004382 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383
4384 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004385out_overflow:
4386 print_overflow_msg(__func__, xdr);
4387 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388}
4389
4390static int decode_setclientid_confirm(struct xdr_stream *xdr)
4391{
4392 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4393}
4394
4395static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4396{
Al Viro8687b632006-10-19 23:28:48 -07004397 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 int status;
4399
4400 status = decode_op_hdr(xdr, OP_WRITE);
4401 if (status)
4402 return status;
4403
Benny Halevyc0eae662009-08-14 17:20:14 +03004404 p = xdr_inline_decode(xdr, 16);
4405 if (unlikely(!p))
4406 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004407 res->count = be32_to_cpup(p++);
4408 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004409 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004411out_overflow:
4412 print_overflow_msg(__func__, xdr);
4413 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414}
4415
4416static int decode_delegreturn(struct xdr_stream *xdr)
4417{
4418 return decode_op_hdr(xdr, OP_DELEGRETURN);
4419}
4420
Benny Halevy99fe60d2009-04-01 09:22:29 -04004421#if defined(CONFIG_NFS_V4_1)
4422static int decode_exchange_id(struct xdr_stream *xdr,
4423 struct nfs41_exchange_id_res *res)
4424{
4425 __be32 *p;
4426 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004427 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004428 int status;
4429 struct nfs_client *clp = res->client;
4430
4431 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4432 if (status)
4433 return status;
4434
Benny Halevyc0eae662009-08-14 17:20:14 +03004435 p = xdr_inline_decode(xdr, 8);
4436 if (unlikely(!p))
4437 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004438 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004439 p = xdr_inline_decode(xdr, 12);
4440 if (unlikely(!p))
4441 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004442 clp->cl_seqid = be32_to_cpup(p++);
4443 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004444
4445 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004446 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004447 if (dummy != SP4_NONE)
4448 return -EIO;
4449
4450 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004451 p = xdr_inline_decode(xdr, 8);
4452 if (unlikely(!p))
4453 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004454
4455 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004456 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4457 if (unlikely(status))
4458 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004459
4460 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004461 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4462 if (unlikely(status))
4463 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004464
4465 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004466 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4467 if (unlikely(status))
4468 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004469
4470 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004471out_overflow:
4472 print_overflow_msg(__func__, xdr);
4473 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004474}
Andy Adamsonfc931582009-04-01 09:22:31 -04004475
4476static int decode_chan_attrs(struct xdr_stream *xdr,
4477 struct nfs4_channel_attrs *attrs)
4478{
4479 __be32 *p;
4480 u32 nr_attrs;
4481
Benny Halevyc0eae662009-08-14 17:20:14 +03004482 p = xdr_inline_decode(xdr, 28);
4483 if (unlikely(!p))
4484 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004485 attrs->headerpadsz = be32_to_cpup(p++);
4486 attrs->max_rqst_sz = be32_to_cpup(p++);
4487 attrs->max_resp_sz = be32_to_cpup(p++);
4488 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4489 attrs->max_ops = be32_to_cpup(p++);
4490 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004491 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004492 if (unlikely(nr_attrs > 1)) {
4493 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4494 __func__, nr_attrs);
4495 return -EINVAL;
4496 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004497 if (nr_attrs == 1) {
4498 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4499 if (unlikely(!p))
4500 goto out_overflow;
4501 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004502 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004503out_overflow:
4504 print_overflow_msg(__func__, xdr);
4505 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004506}
4507
Benny Halevye78291e2009-08-14 17:20:00 +03004508static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4509{
4510 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004511}
4512
4513static int decode_create_session(struct xdr_stream *xdr,
4514 struct nfs41_create_session_res *res)
4515{
4516 __be32 *p;
4517 int status;
4518 struct nfs_client *clp = res->client;
4519 struct nfs4_session *session = clp->cl_session;
4520
4521 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004522 if (!status)
4523 status = decode_sessionid(xdr, &session->sess_id);
4524 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004525 return status;
4526
Andy Adamsonfc931582009-04-01 09:22:31 -04004527 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004528 p = xdr_inline_decode(xdr, 8);
4529 if (unlikely(!p))
4530 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004531 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004532 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004533
4534 /* Channel attributes */
4535 status = decode_chan_attrs(xdr, &session->fc_attrs);
4536 if (!status)
4537 status = decode_chan_attrs(xdr, &session->bc_attrs);
4538 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004539out_overflow:
4540 print_overflow_msg(__func__, xdr);
4541 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004542}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004543
4544static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4545{
4546 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4547}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004548#endif /* CONFIG_NFS_V4_1 */
4549
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004550static int decode_sequence(struct xdr_stream *xdr,
4551 struct nfs4_sequence_res *res,
4552 struct rpc_rqst *rqstp)
4553{
4554#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004555 struct nfs4_slot *slot;
4556 struct nfs4_sessionid id;
4557 u32 dummy;
4558 int status;
4559 __be32 *p;
4560
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004561 if (!res->sr_session)
4562 return 0;
4563
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004564 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004565 if (!status)
4566 status = decode_sessionid(xdr, &id);
4567 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004568 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004569
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004570 /*
4571 * If the server returns different values for sessionID, slotID or
4572 * sequence number, the server is looney tunes.
4573 */
4574 status = -ESERVERFAULT;
4575
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004576 if (memcmp(id.data, res->sr_session->sess_id.data,
4577 NFS4_MAX_SESSIONID_LEN)) {
4578 dprintk("%s Invalid session id\n", __func__);
4579 goto out_err;
4580 }
Benny Halevye78291e2009-08-14 17:20:00 +03004581
Benny Halevyc0eae662009-08-14 17:20:14 +03004582 p = xdr_inline_decode(xdr, 20);
4583 if (unlikely(!p))
4584 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004585
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004586 /* seqid */
Benny Halevye78291e2009-08-14 17:20:00 +03004587 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
Benny Halevy6f723f72009-08-14 17:19:37 +03004588 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004589 if (dummy != slot->seq_nr) {
4590 dprintk("%s Invalid sequence number\n", __func__);
4591 goto out_err;
4592 }
4593 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004594 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004595 if (dummy != res->sr_slotid) {
4596 dprintk("%s Invalid slot id\n", __func__);
4597 goto out_err;
4598 }
4599 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004600 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004601 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004602 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004603 /* result flags - currently not processed */
Benny Halevycccddf42009-08-14 17:20:19 +03004604 dummy = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004605 status = 0;
4606out_err:
4607 res->sr_status = status;
4608 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004609out_overflow:
4610 print_overflow_msg(__func__, xdr);
4611 status = -EIO;
4612 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004613#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004614 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004615#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004616}
4617
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618/*
Benny Halevy49c25592008-12-23 16:06:16 -05004619 * END OF "GENERIC" DECODE ROUTINES.
4620 */
4621
4622/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 * Decode OPEN_DOWNGRADE response
4624 */
Al Viro8687b632006-10-19 23:28:48 -07004625static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626{
Andy Adamson05d564f2008-12-23 16:06:15 -05004627 struct xdr_stream xdr;
4628 struct compound_hdr hdr;
4629 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630
Andy Adamson05d564f2008-12-23 16:06:15 -05004631 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4632 status = decode_compound_hdr(&xdr, &hdr);
4633 if (status)
4634 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004635 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4636 if (status)
4637 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004638 status = decode_putfh(&xdr);
4639 if (status)
4640 goto out;
4641 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004642 if (status != 0)
4643 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004644 decode_getfattr(&xdr, res->fattr, res->server,
4645 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004647 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648}
4649
4650/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 * Decode ACCESS response
4652 */
Al Viro8687b632006-10-19 23:28:48 -07004653static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654{
4655 struct xdr_stream xdr;
4656 struct compound_hdr hdr;
4657 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004658
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004660 status = decode_compound_hdr(&xdr, &hdr);
4661 if (status)
4662 goto out;
4663 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4664 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004666 status = decode_putfh(&xdr);
4667 if (status != 0)
4668 goto out;
4669 status = decode_access(&xdr, res);
4670 if (status != 0)
4671 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004672 decode_getfattr(&xdr, res->fattr, res->server,
4673 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674out:
4675 return status;
4676}
4677
4678/*
4679 * Decode LOOKUP response
4680 */
Al Viro8687b632006-10-19 23:28:48 -07004681static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682{
4683 struct xdr_stream xdr;
4684 struct compound_hdr hdr;
4685 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004686
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004688 status = decode_compound_hdr(&xdr, &hdr);
4689 if (status)
4690 goto out;
4691 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4692 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 goto out;
4694 if ((status = decode_putfh(&xdr)) != 0)
4695 goto out;
4696 if ((status = decode_lookup(&xdr)) != 0)
4697 goto out;
4698 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4699 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004700 status = decode_getfattr(&xdr, res->fattr, res->server
4701 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702out:
4703 return status;
4704}
4705
4706/*
4707 * Decode LOOKUP_ROOT response
4708 */
Al Viro8687b632006-10-19 23:28:48 -07004709static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710{
4711 struct xdr_stream xdr;
4712 struct compound_hdr hdr;
4713 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004714
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004716 status = decode_compound_hdr(&xdr, &hdr);
4717 if (status)
4718 goto out;
4719 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4720 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 goto out;
4722 if ((status = decode_putrootfh(&xdr)) != 0)
4723 goto out;
4724 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004725 status = decode_getfattr(&xdr, res->fattr, res->server,
4726 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727out:
4728 return status;
4729}
4730
4731/*
4732 * Decode REMOVE response
4733 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004734static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735{
4736 struct xdr_stream xdr;
4737 struct compound_hdr hdr;
4738 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004739
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004741 status = decode_compound_hdr(&xdr, &hdr);
4742 if (status)
4743 goto out;
4744 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4745 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004747 if ((status = decode_putfh(&xdr)) != 0)
4748 goto out;
4749 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4750 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004751 decode_getfattr(&xdr, &res->dir_attr, res->server,
4752 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753out:
4754 return status;
4755}
4756
4757/*
4758 * Decode RENAME response
4759 */
Al Viro8687b632006-10-19 23:28:48 -07004760static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761{
4762 struct xdr_stream xdr;
4763 struct compound_hdr hdr;
4764 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004765
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004767 status = decode_compound_hdr(&xdr, &hdr);
4768 if (status)
4769 goto out;
4770 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4771 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 goto out;
4773 if ((status = decode_putfh(&xdr)) != 0)
4774 goto out;
4775 if ((status = decode_savefh(&xdr)) != 0)
4776 goto out;
4777 if ((status = decode_putfh(&xdr)) != 0)
4778 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004779 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4780 goto out;
4781 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004782 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4783 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004784 goto out;
4785 if ((status = decode_restorefh(&xdr)) != 0)
4786 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004787 decode_getfattr(&xdr, res->old_fattr, res->server,
4788 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789out:
4790 return status;
4791}
4792
4793/*
4794 * Decode LINK response
4795 */
Al Viro8687b632006-10-19 23:28:48 -07004796static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797{
4798 struct xdr_stream xdr;
4799 struct compound_hdr hdr;
4800 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004801
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004803 status = decode_compound_hdr(&xdr, &hdr);
4804 if (status)
4805 goto out;
4806 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4807 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 goto out;
4809 if ((status = decode_putfh(&xdr)) != 0)
4810 goto out;
4811 if ((status = decode_savefh(&xdr)) != 0)
4812 goto out;
4813 if ((status = decode_putfh(&xdr)) != 0)
4814 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004815 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4816 goto out;
4817 /*
4818 * Note order: OP_LINK leaves the directory as the current
4819 * filehandle.
4820 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004821 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4822 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004823 goto out;
4824 if ((status = decode_restorefh(&xdr)) != 0)
4825 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004826 decode_getfattr(&xdr, res->fattr, res->server,
4827 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828out:
4829 return status;
4830}
4831
4832/*
4833 * Decode CREATE response
4834 */
Al Viro8687b632006-10-19 23:28:48 -07004835static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836{
4837 struct xdr_stream xdr;
4838 struct compound_hdr hdr;
4839 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004840
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004842 status = decode_compound_hdr(&xdr, &hdr);
4843 if (status)
4844 goto out;
4845 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4846 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 goto out;
4848 if ((status = decode_putfh(&xdr)) != 0)
4849 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004850 if ((status = decode_savefh(&xdr)) != 0)
4851 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4853 goto out;
4854 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4855 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004856 if (decode_getfattr(&xdr, res->fattr, res->server,
4857 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004858 goto out;
4859 if ((status = decode_restorefh(&xdr)) != 0)
4860 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004861 decode_getfattr(&xdr, res->dir_fattr, res->server,
4862 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863out:
4864 return status;
4865}
4866
4867/*
4868 * Decode SYMLINK response
4869 */
Al Viro8687b632006-10-19 23:28:48 -07004870static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871{
4872 return nfs4_xdr_dec_create(rqstp, p, res);
4873}
4874
4875/*
4876 * Decode GETATTR response
4877 */
Al Viro8687b632006-10-19 23:28:48 -07004878static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879{
4880 struct xdr_stream xdr;
4881 struct compound_hdr hdr;
4882 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004883
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4885 status = decode_compound_hdr(&xdr, &hdr);
4886 if (status)
4887 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004888 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4889 if (status)
4890 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 status = decode_putfh(&xdr);
4892 if (status)
4893 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004894 status = decode_getfattr(&xdr, res->fattr, res->server,
4895 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896out:
4897 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898}
4899
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004900/*
4901 * Encode an SETACL request
4902 */
4903static int
Al Viro8687b632006-10-19 23:28:48 -07004904nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004905{
Andy Adamson05d564f2008-12-23 16:06:15 -05004906 struct xdr_stream xdr;
4907 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004908 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004909 };
4910 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004911
Andy Adamson05d564f2008-12-23 16:06:15 -05004912 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004913 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004914 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004915 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004916 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004917 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004918 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004919}
Andy Adamson05d564f2008-12-23 16:06:15 -05004920
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004921/*
4922 * Decode SETACL response
4923 */
4924static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004925nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4926 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004927{
4928 struct xdr_stream xdr;
4929 struct compound_hdr hdr;
4930 int status;
4931
4932 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4933 status = decode_compound_hdr(&xdr, &hdr);
4934 if (status)
4935 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004936 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4937 if (status)
4938 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004939 status = decode_putfh(&xdr);
4940 if (status)
4941 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004942 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004943out:
4944 return status;
4945}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946
4947/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004948 * Decode GETACL response
4949 */
4950static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004951nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4952 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004953{
4954 struct xdr_stream xdr;
4955 struct compound_hdr hdr;
4956 int status;
4957
4958 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4959 status = decode_compound_hdr(&xdr, &hdr);
4960 if (status)
4961 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004962 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4963 if (status)
4964 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004965 status = decode_putfh(&xdr);
4966 if (status)
4967 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004968 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004969
4970out:
4971 return status;
4972}
4973
4974/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 * Decode CLOSE response
4976 */
Al Viro8687b632006-10-19 23:28:48 -07004977static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978{
Andy Adamson05d564f2008-12-23 16:06:15 -05004979 struct xdr_stream xdr;
4980 struct compound_hdr hdr;
4981 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982
Andy Adamson05d564f2008-12-23 16:06:15 -05004983 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4984 status = decode_compound_hdr(&xdr, &hdr);
4985 if (status)
4986 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004987 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4988 if (status)
4989 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004990 status = decode_putfh(&xdr);
4991 if (status)
4992 goto out;
4993 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004994 if (status != 0)
4995 goto out;
4996 /*
4997 * Note: Server may do delete on close for this file
4998 * in which case the getattr call will fail with
4999 * an ESTALE error. Shouldn't be a problem,
5000 * though, since fattr->valid will remain unset.
5001 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005002 decode_getfattr(&xdr, res->fattr, res->server,
5003 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005005 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006}
5007
5008/*
5009 * Decode OPEN response
5010 */
Al Viro8687b632006-10-19 23:28:48 -07005011static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012{
Andy Adamson05d564f2008-12-23 16:06:15 -05005013 struct xdr_stream xdr;
5014 struct compound_hdr hdr;
5015 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016
Andy Adamson05d564f2008-12-23 16:06:15 -05005017 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5018 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005019 if (status)
5020 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005021 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5022 if (status)
5023 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005024 status = decode_putfh(&xdr);
5025 if (status)
5026 goto out;
5027 status = decode_savefh(&xdr);
5028 if (status)
5029 goto out;
5030 status = decode_open(&xdr, res);
5031 if (status)
5032 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005033 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005035 if (decode_getfattr(&xdr, res->f_attr, res->server,
5036 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005037 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005038 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005039 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005040 decode_getfattr(&xdr, res->dir_attr, res->server,
5041 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005043 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044}
5045
5046/*
5047 * Decode OPEN_CONFIRM response
5048 */
Al Viro8687b632006-10-19 23:28:48 -07005049static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050{
Andy Adamson05d564f2008-12-23 16:06:15 -05005051 struct xdr_stream xdr;
5052 struct compound_hdr hdr;
5053 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054
Andy Adamson05d564f2008-12-23 16:06:15 -05005055 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5056 status = decode_compound_hdr(&xdr, &hdr);
5057 if (status)
5058 goto out;
5059 status = decode_putfh(&xdr);
5060 if (status)
5061 goto out;
5062 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005064 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065}
5066
5067/*
5068 * Decode OPEN response
5069 */
Al Viro8687b632006-10-19 23:28:48 -07005070static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071{
Andy Adamson05d564f2008-12-23 16:06:15 -05005072 struct xdr_stream xdr;
5073 struct compound_hdr hdr;
5074 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075
Andy Adamson05d564f2008-12-23 16:06:15 -05005076 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5077 status = decode_compound_hdr(&xdr, &hdr);
5078 if (status)
5079 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005080 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5081 if (status)
5082 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005083 status = decode_putfh(&xdr);
5084 if (status)
5085 goto out;
5086 status = decode_open(&xdr, res);
5087 if (status)
5088 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005089 decode_getfattr(&xdr, res->f_attr, res->server,
5090 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005092 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093}
5094
5095/*
5096 * Decode SETATTR response
5097 */
Al Viro8687b632006-10-19 23:28:48 -07005098static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099{
Andy Adamson05d564f2008-12-23 16:06:15 -05005100 struct xdr_stream xdr;
5101 struct compound_hdr hdr;
5102 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103
Andy Adamson05d564f2008-12-23 16:06:15 -05005104 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5105 status = decode_compound_hdr(&xdr, &hdr);
5106 if (status)
5107 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005108 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5109 if (status)
5110 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005111 status = decode_putfh(&xdr);
5112 if (status)
5113 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005114 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005115 if (status)
5116 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005117 decode_getfattr(&xdr, res->fattr, res->server,
5118 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005120 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121}
5122
5123/*
5124 * Decode LOCK response
5125 */
Al Viro8687b632006-10-19 23:28:48 -07005126static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127{
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 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005136 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5137 if (status)
5138 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 status = decode_putfh(&xdr);
5140 if (status)
5141 goto out;
5142 status = decode_lock(&xdr, res);
5143out:
5144 return status;
5145}
5146
5147/*
5148 * Decode LOCKT response
5149 */
Al Viro8687b632006-10-19 23:28:48 -07005150static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151{
5152 struct xdr_stream xdr;
5153 struct compound_hdr hdr;
5154 int status;
5155
5156 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5157 status = decode_compound_hdr(&xdr, &hdr);
5158 if (status)
5159 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005160 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5161 if (status)
5162 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 status = decode_putfh(&xdr);
5164 if (status)
5165 goto out;
5166 status = decode_lockt(&xdr, res);
5167out:
5168 return status;
5169}
5170
5171/*
5172 * Decode LOCKU response
5173 */
Al Viro8687b632006-10-19 23:28:48 -07005174static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175{
5176 struct xdr_stream xdr;
5177 struct compound_hdr hdr;
5178 int status;
5179
5180 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5181 status = decode_compound_hdr(&xdr, &hdr);
5182 if (status)
5183 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005184 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5185 if (status)
5186 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 status = decode_putfh(&xdr);
5188 if (status)
5189 goto out;
5190 status = decode_locku(&xdr, res);
5191out:
5192 return status;
5193}
5194
5195/*
5196 * Decode READLINK response
5197 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005198static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5199 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200{
5201 struct xdr_stream xdr;
5202 struct compound_hdr hdr;
5203 int status;
5204
5205 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5206 status = decode_compound_hdr(&xdr, &hdr);
5207 if (status)
5208 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005209 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5210 if (status)
5211 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 status = decode_putfh(&xdr);
5213 if (status)
5214 goto out;
5215 status = decode_readlink(&xdr, rqstp);
5216out:
5217 return status;
5218}
5219
5220/*
5221 * Decode READDIR response
5222 */
Al Viro8687b632006-10-19 23:28:48 -07005223static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224{
5225 struct xdr_stream xdr;
5226 struct compound_hdr hdr;
5227 int status;
5228
5229 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5230 status = decode_compound_hdr(&xdr, &hdr);
5231 if (status)
5232 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005233 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5234 if (status)
5235 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 status = decode_putfh(&xdr);
5237 if (status)
5238 goto out;
5239 status = decode_readdir(&xdr, rqstp, res);
5240out:
5241 return status;
5242}
5243
5244/*
5245 * Decode Read response
5246 */
Al Viro8687b632006-10-19 23:28:48 -07005247static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248{
5249 struct xdr_stream xdr;
5250 struct compound_hdr hdr;
5251 int status;
5252
5253 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5254 status = decode_compound_hdr(&xdr, &hdr);
5255 if (status)
5256 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005257 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5258 if (status)
5259 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 status = decode_putfh(&xdr);
5261 if (status)
5262 goto out;
5263 status = decode_read(&xdr, rqstp, res);
5264 if (!status)
5265 status = res->count;
5266out:
5267 return status;
5268}
5269
5270/*
5271 * Decode WRITE response
5272 */
Al Viro8687b632006-10-19 23:28:48 -07005273static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274{
5275 struct xdr_stream xdr;
5276 struct compound_hdr hdr;
5277 int status;
5278
5279 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5280 status = decode_compound_hdr(&xdr, &hdr);
5281 if (status)
5282 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005283 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5284 if (status)
5285 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 status = decode_putfh(&xdr);
5287 if (status)
5288 goto out;
5289 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005290 if (status)
5291 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005292 decode_getfattr(&xdr, res->fattr, res->server,
5293 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 if (!status)
5295 status = res->count;
5296out:
5297 return status;
5298}
5299
5300/*
5301 * Decode COMMIT response
5302 */
Al Viro8687b632006-10-19 23:28:48 -07005303static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304{
5305 struct xdr_stream xdr;
5306 struct compound_hdr hdr;
5307 int status;
5308
5309 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5310 status = decode_compound_hdr(&xdr, &hdr);
5311 if (status)
5312 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005313 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5314 if (status)
5315 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316 status = decode_putfh(&xdr);
5317 if (status)
5318 goto out;
5319 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005320 if (status)
5321 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005322 decode_getfattr(&xdr, res->fattr, res->server,
5323 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324out:
5325 return status;
5326}
5327
5328/*
5329 * FSINFO request
5330 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005331static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5332 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333{
5334 struct xdr_stream xdr;
5335 struct compound_hdr hdr;
5336 int status;
5337
5338 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5339 status = decode_compound_hdr(&xdr, &hdr);
5340 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005341 status = decode_sequence(&xdr, &res->seq_res, req);
5342 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 status = decode_putfh(&xdr);
5344 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005345 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346 return status;
5347}
5348
5349/*
5350 * PATHCONF request
5351 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005352static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5353 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354{
5355 struct xdr_stream xdr;
5356 struct compound_hdr hdr;
5357 int status;
5358
5359 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5360 status = decode_compound_hdr(&xdr, &hdr);
5361 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005362 status = decode_sequence(&xdr, &res->seq_res, req);
5363 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364 status = decode_putfh(&xdr);
5365 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005366 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367 return status;
5368}
5369
5370/*
5371 * STATFS request
5372 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005373static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5374 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375{
5376 struct xdr_stream xdr;
5377 struct compound_hdr hdr;
5378 int status;
5379
5380 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5381 status = decode_compound_hdr(&xdr, &hdr);
5382 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005383 status = decode_sequence(&xdr, &res->seq_res, req);
5384 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 status = decode_putfh(&xdr);
5386 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005387 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 return status;
5389}
5390
5391/*
5392 * GETATTR_BITMAP request
5393 */
Al Viro8687b632006-10-19 23:28:48 -07005394static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005395{
5396 struct xdr_stream xdr;
5397 struct compound_hdr hdr;
5398 int status;
5399
5400 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005401 status = decode_compound_hdr(&xdr, &hdr);
5402 if (status)
5403 goto out;
5404 status = decode_sequence(&xdr, &res->seq_res, req);
5405 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 goto out;
5407 if ((status = decode_putfh(&xdr)) != 0)
5408 goto out;
5409 status = decode_server_caps(&xdr, res);
5410out:
5411 return status;
5412}
5413
5414/*
5415 * Decode RENEW response
5416 */
Al Viro8687b632006-10-19 23:28:48 -07005417static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418{
5419 struct xdr_stream xdr;
5420 struct compound_hdr hdr;
5421 int status;
5422
5423 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5424 status = decode_compound_hdr(&xdr, &hdr);
5425 if (!status)
5426 status = decode_renew(&xdr);
5427 return status;
5428}
5429
5430/*
5431 * a SETCLIENTID request
5432 */
Al Viro8687b632006-10-19 23:28:48 -07005433static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005434 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435{
5436 struct xdr_stream xdr;
5437 struct compound_hdr hdr;
5438 int status;
5439
5440 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5441 status = decode_compound_hdr(&xdr, &hdr);
5442 if (!status)
5443 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 return status;
5445}
5446
5447/*
5448 * a SETCLIENTID_CONFIRM request
5449 */
Al Viro8687b632006-10-19 23:28:48 -07005450static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451{
5452 struct xdr_stream xdr;
5453 struct compound_hdr hdr;
5454 int status;
5455
5456 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5457 status = decode_compound_hdr(&xdr, &hdr);
5458 if (!status)
5459 status = decode_setclientid_confirm(&xdr);
5460 if (!status)
5461 status = decode_putrootfh(&xdr);
5462 if (!status)
5463 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 return status;
5465}
5466
5467/*
5468 * DELEGRETURN request
5469 */
Al Viro8687b632006-10-19 23:28:48 -07005470static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471{
5472 struct xdr_stream xdr;
5473 struct compound_hdr hdr;
5474 int status;
5475
5476 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5477 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005478 if (status)
5479 goto out;
5480 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5481 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005482 goto out;
5483 status = decode_putfh(&xdr);
5484 if (status != 0)
5485 goto out;
5486 status = decode_delegreturn(&xdr);
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005487 decode_getfattr(&xdr, res->fattr, res->server,
5488 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005489out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490 return status;
5491}
5492
Trond Myklebust683b57b2006-06-09 09:34:22 -04005493/*
5494 * FS_LOCATIONS request
5495 */
Benny Halevy22958462009-04-01 09:22:02 -04005496static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5497 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005498{
5499 struct xdr_stream xdr;
5500 struct compound_hdr hdr;
5501 int status;
5502
5503 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5504 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005505 if (status)
5506 goto out;
5507 status = decode_sequence(&xdr, &res->seq_res, req);
5508 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005509 goto out;
5510 if ((status = decode_putfh(&xdr)) != 0)
5511 goto out;
5512 if ((status = decode_lookup(&xdr)) != 0)
5513 goto out;
5514 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005515 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005516 res->fs_locations->server,
5517 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005518out:
5519 return status;
5520}
5521
Benny Halevy99fe60d2009-04-01 09:22:29 -04005522#if defined(CONFIG_NFS_V4_1)
5523/*
5524 * EXCHANGE_ID request
5525 */
5526static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5527 void *res)
5528{
5529 struct xdr_stream xdr;
5530 struct compound_hdr hdr;
5531 int status;
5532
5533 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5534 status = decode_compound_hdr(&xdr, &hdr);
5535 if (!status)
5536 status = decode_exchange_id(&xdr, res);
5537 return status;
5538}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005539
5540/*
Andy Adamsonfc931582009-04-01 09:22:31 -04005541 * a CREATE_SESSION request
5542 */
5543static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5544 struct nfs41_create_session_res *res)
5545{
5546 struct xdr_stream xdr;
5547 struct compound_hdr hdr;
5548 int status;
5549
5550 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5551 status = decode_compound_hdr(&xdr, &hdr);
5552 if (!status)
5553 status = decode_create_session(&xdr, res);
5554 return status;
5555}
5556
5557/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005558 * a DESTROY_SESSION request
5559 */
5560static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5561 void *dummy)
5562{
5563 struct xdr_stream xdr;
5564 struct compound_hdr hdr;
5565 int status;
5566
5567 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5568 status = decode_compound_hdr(&xdr, &hdr);
5569 if (!status)
5570 status = decode_destroy_session(&xdr, dummy);
5571 return status;
5572}
5573
5574/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005575 * a SEQUENCE request
5576 */
5577static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5578 struct nfs4_sequence_res *res)
5579{
5580 struct xdr_stream xdr;
5581 struct compound_hdr hdr;
5582 int status;
5583
5584 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5585 status = decode_compound_hdr(&xdr, &hdr);
5586 if (!status)
5587 status = decode_sequence(&xdr, res, rqstp);
5588 return status;
5589}
5590
5591/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04005592 * a GET_LEASE_TIME request
5593 */
5594static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5595 struct nfs4_get_lease_time_res *res)
5596{
5597 struct xdr_stream xdr;
5598 struct compound_hdr hdr;
5599 int status;
5600
5601 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5602 status = decode_compound_hdr(&xdr, &hdr);
5603 if (!status)
5604 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5605 if (!status)
5606 status = decode_putrootfh(&xdr);
5607 if (!status)
5608 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5609 return status;
5610}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005611#endif /* CONFIG_NFS_V4_1 */
5612
Al Viro0dbb4c62006-10-19 23:28:49 -07005613__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614{
5615 uint32_t bitmap[2] = {0};
5616 uint32_t len;
5617
5618 if (!*p++) {
5619 if (!*p)
5620 return ERR_PTR(-EAGAIN);
5621 entry->eof = 1;
5622 return ERR_PTR(-EBADCOOKIE);
5623 }
5624
5625 entry->prev_cookie = entry->cookie;
5626 p = xdr_decode_hyper(p, &entry->cookie);
5627 entry->len = ntohl(*p++);
5628 entry->name = (const char *) p;
5629 p += XDR_QUADLEN(entry->len);
5630
5631 /*
5632 * In case the server doesn't return an inode number,
5633 * we fake one here. (We don't use inode number 0,
5634 * since glibc seems to choke on it...)
5635 */
5636 entry->ino = 1;
5637
5638 len = ntohl(*p++); /* bitmap length */
5639 if (len-- > 0) {
5640 bitmap[0] = ntohl(*p++);
5641 if (len-- > 0) {
5642 bitmap[1] = ntohl(*p++);
5643 p += len;
5644 }
5645 }
5646 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5647 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005648 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5649 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5650 /* Ignore the return value of rdattr_error for now */
5651 p++;
5652 len--;
5653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5655 xdr_decode_hyper(p, &entry->ino);
5656 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5657 xdr_decode_hyper(p, &entry->ino);
5658 p += len;
5659 }
5660
5661 entry->eof = !p[0] && p[1];
5662 return p;
5663}
5664
5665/*
5666 * We need to translate between nfs status return values and
5667 * the local errno values which may not be the same.
5668 */
5669static struct {
5670 int stat;
5671 int errno;
5672} nfs_errtbl[] = {
5673 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005674 { NFS4ERR_PERM, -EPERM },
5675 { NFS4ERR_NOENT, -ENOENT },
5676 { NFS4ERR_IO, -errno_NFSERR_IO},
5677 { NFS4ERR_NXIO, -ENXIO },
5678 { NFS4ERR_ACCESS, -EACCES },
5679 { NFS4ERR_EXIST, -EEXIST },
5680 { NFS4ERR_XDEV, -EXDEV },
5681 { NFS4ERR_NOTDIR, -ENOTDIR },
5682 { NFS4ERR_ISDIR, -EISDIR },
5683 { NFS4ERR_INVAL, -EINVAL },
5684 { NFS4ERR_FBIG, -EFBIG },
5685 { NFS4ERR_NOSPC, -ENOSPC },
5686 { NFS4ERR_ROFS, -EROFS },
5687 { NFS4ERR_MLINK, -EMLINK },
5688 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5689 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5690 { NFS4ERR_DQUOT, -EDQUOT },
5691 { NFS4ERR_STALE, -ESTALE },
5692 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5693 { NFS4ERR_BADOWNER, -EINVAL },
5694 { NFS4ERR_BADNAME, -EINVAL },
5695 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5696 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5697 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5698 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5699 { NFS4ERR_BADTYPE, -EBADTYPE },
5700 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005701 { NFS4ERR_SYMLINK, -ELOOP },
5702 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5703 { NFS4ERR_DEADLOCK, -EDEADLK },
5704 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705 * to be handled by a
5706 * middle-layer.
5707 */
Benny Halevy856dff32008-03-31 17:39:06 +03005708 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709};
5710
5711/*
5712 * Convert an NFS error code to a local one.
5713 * This one is used jointly by NFSv2 and NFSv3.
5714 */
5715static int
David Howells0a8ea432006-08-22 20:06:08 -04005716nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717{
5718 int i;
5719 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5720 if (nfs_errtbl[i].stat == stat)
5721 return nfs_errtbl[i].errno;
5722 }
5723 if (stat <= 10000 || stat > 10100) {
5724 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005725 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 }
5727 /* If we cannot translate the error, the recovery routines should
5728 * handle it.
5729 * Note: remaining NFSv4 error codes have values > 10000, so should
5730 * not conflict with native Linux error codes.
5731 */
Benny Halevy856dff32008-03-31 17:39:06 +03005732 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733}
5734
Linus Torvalds1da177e2005-04-16 15:20:36 -07005735#define PROC(proc, argtype, restype) \
5736[NFSPROC4_CLNT_##proc] = { \
5737 .p_proc = NFSPROC4_COMPOUND, \
5738 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5739 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005740 .p_arglen = NFS4_##argtype##_sz, \
5741 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005742 .p_statidx = NFSPROC4_CLNT_##proc, \
5743 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005744}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745
5746struct rpc_procinfo nfs4_procedures[] = {
5747 PROC(READ, enc_read, dec_read),
5748 PROC(WRITE, enc_write, dec_write),
5749 PROC(COMMIT, enc_commit, dec_commit),
5750 PROC(OPEN, enc_open, dec_open),
5751 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5752 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5753 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5754 PROC(CLOSE, enc_close, dec_close),
5755 PROC(SETATTR, enc_setattr, dec_setattr),
5756 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5757 PROC(RENEW, enc_renew, dec_renew),
5758 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5759 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5760 PROC(LOCK, enc_lock, dec_lock),
5761 PROC(LOCKT, enc_lockt, dec_lockt),
5762 PROC(LOCKU, enc_locku, dec_locku),
5763 PROC(ACCESS, enc_access, dec_access),
5764 PROC(GETATTR, enc_getattr, dec_getattr),
5765 PROC(LOOKUP, enc_lookup, dec_lookup),
5766 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5767 PROC(REMOVE, enc_remove, dec_remove),
5768 PROC(RENAME, enc_rename, dec_rename),
5769 PROC(LINK, enc_link, dec_link),
5770 PROC(SYMLINK, enc_symlink, dec_symlink),
5771 PROC(CREATE, enc_create, dec_create),
5772 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5773 PROC(STATFS, enc_statfs, dec_statfs),
5774 PROC(READLINK, enc_readlink, dec_readlink),
5775 PROC(READDIR, enc_readdir, dec_readdir),
5776 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5777 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005778 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005779 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005780 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005781#if defined(CONFIG_NFS_V4_1)
5782 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005783 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005784 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005785 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005786 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005787#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788};
5789
5790struct rpc_version nfs_version4 = {
5791 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005792 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 .procs = nfs4_procedures
5794};
5795
5796/*
5797 * Local variables:
5798 * c-basic-offset: 8
5799 * End:
5800 */