blob: 38f3b582e7c246c4552b2b1b11a618b8eff93f26 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#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)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500303#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
304#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400305#else /* CONFIG_NFS_V4_1 */
306#define encode_sequence_maxsz 0
307#define decode_sequence_maxsz 0
308#endif /* CONFIG_NFS_V4_1 */
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
311#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
312#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400313 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400315 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400317 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400319 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400321 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400323 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400325 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400327 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400329 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400331 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400333 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400335 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400337 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400339 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400340 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400342 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400344 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400345 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400347 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400349 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400350 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400352 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400354 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400355 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400357 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400358 encode_putfh_maxsz + \
359 encode_savefh_maxsz + \
360 encode_open_maxsz + \
361 encode_getfh_maxsz + \
362 encode_getattr_maxsz + \
363 encode_restorefh_maxsz + \
364 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400366 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400367 decode_putfh_maxsz + \
368 decode_savefh_maxsz + \
369 decode_open_maxsz + \
370 decode_getfh_maxsz + \
371 decode_getattr_maxsz + \
372 decode_restorefh_maxsz + \
373 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400374#define NFS4_enc_open_confirm_sz \
375 (compound_encode_hdr_maxsz + \
376 encode_putfh_maxsz + \
377 encode_open_confirm_maxsz)
378#define NFS4_dec_open_confirm_sz \
379 (compound_decode_hdr_maxsz + \
380 decode_putfh_maxsz + \
381 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400383 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400385 encode_open_maxsz + \
386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400390 decode_open_maxsz + \
391 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define NFS4_enc_open_downgrade_sz \
393 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400394 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 encode_putfh_maxsz + \
396 encode_open_downgrade_maxsz + \
397 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#define NFS4_dec_open_downgrade_sz \
399 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400401 decode_putfh_maxsz + \
402 decode_open_downgrade_maxsz + \
403 decode_getattr_maxsz)
404#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_putfh_maxsz + \
407 encode_close_maxsz + \
408 encode_getattr_maxsz)
409#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400410 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400411 decode_putfh_maxsz + \
412 decode_close_maxsz + \
413 decode_getattr_maxsz)
414#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400415 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400416 encode_putfh_maxsz + \
417 encode_setattr_maxsz + \
418 encode_getattr_maxsz)
419#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400421 decode_putfh_maxsz + \
422 decode_setattr_maxsz + \
423 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 encode_putfh_maxsz + \
427 encode_fsinfo_maxsz)
428#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 decode_putfh_maxsz + \
431 decode_fsinfo_maxsz)
432#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
433 encode_renew_maxsz)
434#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
435 decode_renew_maxsz)
436#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
437 encode_setclientid_maxsz)
438#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
439 decode_setclientid_maxsz)
440#define NFS4_enc_setclientid_confirm_sz \
441 (compound_encode_hdr_maxsz + \
442 encode_setclientid_confirm_maxsz + \
443 encode_putrootfh_maxsz + \
444 encode_fsinfo_maxsz)
445#define NFS4_dec_setclientid_confirm_sz \
446 (compound_decode_hdr_maxsz + \
447 decode_setclientid_confirm_maxsz + \
448 decode_putrootfh_maxsz + \
449 decode_fsinfo_maxsz)
450#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400461 encode_lockt_maxsz)
462#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 decode_putfh_maxsz + \
465 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400469 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400473 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400477 encode_access_maxsz + \
478 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400482 decode_access_maxsz + \
483 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 encode_putfh_maxsz + \
487 encode_getattr_maxsz)
488#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 decode_putfh_maxsz + \
491 decode_getattr_maxsz)
492#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 encode_putfh_maxsz + \
495 encode_lookup_maxsz + \
496 encode_getattr_maxsz + \
497 encode_getfh_maxsz)
498#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400501 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 decode_getattr_maxsz + \
503 decode_getfh_maxsz)
504#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 encode_putrootfh_maxsz + \
507 encode_getattr_maxsz + \
508 encode_getfh_maxsz)
509#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 decode_putrootfh_maxsz + \
512 decode_getattr_maxsz + \
513 decode_getfh_maxsz)
514#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400517 encode_remove_maxsz + \
518 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400522 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400523 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 encode_putfh_maxsz + \
527 encode_savefh_maxsz + \
528 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400529 encode_rename_maxsz + \
530 encode_getattr_maxsz + \
531 encode_restorefh_maxsz + \
532 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_savefh_maxsz + \
537 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400538 decode_rename_maxsz + \
539 decode_getattr_maxsz + \
540 decode_restorefh_maxsz + \
541 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 encode_putfh_maxsz + \
545 encode_savefh_maxsz + \
546 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400547 encode_link_maxsz + \
548 decode_getattr_maxsz + \
549 encode_restorefh_maxsz + \
550 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 decode_putfh_maxsz + \
554 decode_savefh_maxsz + \
555 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400556 decode_link_maxsz + \
557 decode_getattr_maxsz + \
558 decode_restorefh_maxsz + \
559 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 encode_putfh_maxsz + \
563 encode_symlink_maxsz + \
564 encode_getattr_maxsz + \
565 encode_getfh_maxsz)
566#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 decode_putfh_maxsz + \
569 decode_symlink_maxsz + \
570 decode_getattr_maxsz + \
571 decode_getfh_maxsz)
572#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400573 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400575 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400577 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400579 encode_restorefh_maxsz + \
580 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400584 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400586 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400588 decode_restorefh_maxsz + \
589 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 encode_putfh_maxsz + \
593 encode_getattr_maxsz)
594#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
597 decode_getattr_maxsz)
598#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400601 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400605 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800608 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_getattr_maxsz)
610#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800612 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_getattr_maxsz)
614#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100617 encode_delegreturn_maxsz + \
618 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100621 decode_delegreturn_maxsz + \
622 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000623#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000625 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400626 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000627#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000629 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400630 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000631#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000633 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400634 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000635#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000637 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400638 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400639#define NFS4_enc_fs_locations_sz \
640 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400641 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400642 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400643 encode_lookup_maxsz + \
644 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400645#define NFS4_dec_fs_locations_sz \
646 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400647 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400648 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400649 decode_lookup_maxsz + \
650 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400651#if defined(CONFIG_NFS_V4_1)
652#define NFS4_enc_exchange_id_sz \
653 (compound_encode_hdr_maxsz + \
654 encode_exchange_id_maxsz)
655#define NFS4_dec_exchange_id_sz \
656 (compound_decode_hdr_maxsz + \
657 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400658#define NFS4_enc_create_session_sz \
659 (compound_encode_hdr_maxsz + \
660 encode_create_session_maxsz)
661#define NFS4_dec_create_session_sz \
662 (compound_decode_hdr_maxsz + \
663 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400664#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
665 encode_destroy_session_maxsz)
666#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
667 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400668#define NFS4_enc_sequence_sz \
669 (compound_decode_hdr_maxsz + \
670 encode_sequence_maxsz)
671#define NFS4_dec_sequence_sz \
672 (compound_decode_hdr_maxsz + \
673 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400674#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
675 encode_sequence_maxsz + \
676 encode_putrootfh_maxsz + \
677 encode_fsinfo_maxsz)
678#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
679 decode_sequence_maxsz + \
680 decode_putrootfh_maxsz + \
681 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500682#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
683 encode_sequence_maxsz + \
684 encode_reclaim_complete_maxsz)
685#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
686 decode_sequence_maxsz + \
687 decode_reclaim_complete_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500688
689const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
690 compound_encode_hdr_maxsz +
691 encode_sequence_maxsz +
692 encode_putfh_maxsz +
693 encode_getattr_maxsz) *
694 XDR_UNIT);
695
696const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
697 compound_decode_hdr_maxsz +
698 decode_sequence_maxsz +
699 decode_putfh_maxsz) *
700 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400701#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Trond Myklebustbca79472009-03-11 14:10:26 -0400703static const umode_t nfs_type2fmt[] = {
704 [NF4BAD] = 0,
705 [NF4REG] = S_IFREG,
706 [NF4DIR] = S_IFDIR,
707 [NF4BLK] = S_IFBLK,
708 [NF4CHR] = S_IFCHR,
709 [NF4LNK] = S_IFLNK,
710 [NF4SOCK] = S_IFSOCK,
711 [NF4FIFO] = S_IFIFO,
712 [NF4ATTRDIR] = 0,
713 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714};
715
716struct compound_hdr {
717 int32_t status;
718 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500719 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 uint32_t taglen;
721 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400722 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400723 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724};
725
Benny Halevy13c65ce2009-08-14 17:19:25 +0300726static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
727{
728 __be32 *p = xdr_reserve_space(xdr, nbytes);
729 BUG_ON(!p);
730 return p;
731}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
734{
Al Viro8687b632006-10-19 23:28:48 -0700735 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 p = xdr_reserve_space(xdr, 4 + len);
738 BUG_ON(p == NULL);
739 xdr_encode_opaque(p, str, len);
740}
741
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400742static void encode_compound_hdr(struct xdr_stream *xdr,
743 struct rpc_rqst *req,
744 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
Al Viro8687b632006-10-19 23:28:48 -0700746 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400747 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
748
749 /* initialize running count of expected bytes in reply.
750 * NOTE: the replied tag SHOULD be the same is the one sent,
751 * but this is not required as a MUST for the server to do so. */
752 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
755 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300756 p = reserve_space(xdr, 4 + hdr->taglen + 8);
757 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300758 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500759 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300760 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500761}
762
763static void encode_nops(struct compound_hdr *hdr)
764{
Andy Adamsonfc931582009-04-01 09:22:31 -0400765 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500766 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
769static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
770{
Al Viro8687b632006-10-19 23:28:48 -0700771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
774 BUG_ON(p == NULL);
775 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
776}
777
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500778static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 char owner_name[IDMAP_NAMESZ];
781 char owner_group[IDMAP_NAMESZ];
782 int owner_namelen = 0;
783 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700784 __be32 *p;
785 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 int len;
787 uint32_t bmval0 = 0;
788 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 /*
791 * We reserve enough space to write the entire attribute buffer at once.
792 * In the worst-case, this would be
793 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
794 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000795 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 */
797 len = 16;
798
799 /* Sigh */
800 if (iap->ia_valid & ATTR_SIZE)
801 len += 8;
802 if (iap->ia_valid & ATTR_MODE)
803 len += 4;
804 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400805 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400807 dprintk("nfs: couldn't resolve uid %d to string\n",
808 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 /* XXX */
810 strcpy(owner_name, "nobody");
811 owner_namelen = sizeof("nobody") - 1;
812 /* goto out; */
813 }
814 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
815 }
816 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400817 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400819 dprintk("nfs: couldn't resolve gid %d to string\n",
820 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 strcpy(owner_group, "nobody");
822 owner_grouplen = sizeof("nobody") - 1;
823 /* goto out; */
824 }
825 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
826 }
827 if (iap->ia_valid & ATTR_ATIME_SET)
828 len += 16;
829 else if (iap->ia_valid & ATTR_ATIME)
830 len += 4;
831 if (iap->ia_valid & ATTR_MTIME_SET)
832 len += 16;
833 else if (iap->ia_valid & ATTR_MTIME)
834 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300835 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 /*
838 * We write the bitmap length now, but leave the bitmap and the attribute
839 * buffer length to be backfilled at the end of this routine.
840 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300841 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 q = p;
843 p += 3;
844
845 if (iap->ia_valid & ATTR_SIZE) {
846 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300847 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849 if (iap->ia_valid & ATTR_MODE) {
850 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300851 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853 if (iap->ia_valid & ATTR_UID) {
854 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300855 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
857 if (iap->ia_valid & ATTR_GID) {
858 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300859 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 }
861 if (iap->ia_valid & ATTR_ATIME_SET) {
862 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300863 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
864 *p++ = cpu_to_be32(0);
865 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
866 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868 else if (iap->ia_valid & ATTR_ATIME) {
869 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300870 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
872 if (iap->ia_valid & ATTR_MTIME_SET) {
873 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300874 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
875 *p++ = cpu_to_be32(0);
876 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
877 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 }
879 else if (iap->ia_valid & ATTR_MTIME) {
880 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300881 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 /*
885 * Now we backfill the bitmap and the attribute buffer length.
886 */
887 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400888 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 len, ((char *)p - (char *)q) + 4);
890 BUG();
891 }
892 len = (char *)p - (char *)q - 12;
893 *q++ = htonl(bmval0);
894 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300895 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898}
899
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500900static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
Al Viro8687b632006-10-19 23:28:48 -0700902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Benny Halevy13c65ce2009-08-14 17:19:25 +0300904 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300905 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300906 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500907 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400908 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909}
910
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500911static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Al Viro8687b632006-10-19 23:28:48 -0700913 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Benny Halevy13c65ce2009-08-14 17:19:25 +0300915 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300916 *p++ = cpu_to_be32(OP_CLOSE);
917 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300918 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500919 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400920 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500923static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924{
Al Viro8687b632006-10-19 23:28:48 -0700925 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500926
Benny Halevy13c65ce2009-08-14 17:19:25 +0300927 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300928 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300929 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300930 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500931 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400932 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500935static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Al Viro8687b632006-10-19 23:28:48 -0700937 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500938
Benny Halevy13c65ce2009-08-14 17:19:25 +0300939 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300940 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300941 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 switch (create->ftype) {
944 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300945 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300946 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400947 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 break;
949
950 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300951 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300952 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300953 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 break;
955
956 default:
957 break;
958 }
959
Benny Halevy811652b2009-08-14 17:19:34 +0300960 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500961 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400962 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500964 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500967static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Andy Adamson05d564f2008-12-23 16:06:15 -0500969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Benny Halevy13c65ce2009-08-14 17:19:25 +0300971 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300972 *p++ = cpu_to_be32(OP_GETATTR);
973 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300974 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500975 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400976 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}
978
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500979static 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 -0700980{
Andy Adamson05d564f2008-12-23 16:06:15 -0500981 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Benny Halevy13c65ce2009-08-14 17:19:25 +0300983 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300984 *p++ = cpu_to_be32(OP_GETATTR);
985 *p++ = cpu_to_be32(2);
986 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +0300987 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500988 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400989 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500992static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500994 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
995 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500998static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001000 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1001 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001004static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001005{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1007 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001008}
1009
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001010static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
Al Viro8687b632006-10-19 23:28:48 -07001012 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Benny Halevy13c65ce2009-08-14 17:19:25 +03001014 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001015 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001016 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001017 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001020static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Al Viro8687b632006-10-19 23:28:48 -07001022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Benny Halevy13c65ce2009-08-14 17:19:25 +03001024 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001026 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001027 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001028 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029}
1030
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001031static inline int nfs4_lock_type(struct file_lock *fl, int block)
1032{
1033 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1034 return block ? NFS4_READW_LT : NFS4_READ_LT;
1035 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1036}
1037
1038static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1039{
1040 if (fl->fl_end == OFFSET_MAX)
1041 return ~(uint64_t)0;
1042 return fl->fl_end - fl->fl_start + 1;
1043}
1044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045/*
1046 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1047 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1048 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001049static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Al Viro8687b632006-10-19 23:28:48 -07001051 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Benny Halevy13c65ce2009-08-14 17:19:25 +03001053 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001054 *p++ = cpu_to_be32(OP_LOCK);
1055 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1056 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001057 p = xdr_encode_hyper(p, args->fl->fl_start);
1058 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001059 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001060 if (args->new_lock_owner){
Benny Halevy13c65ce2009-08-14 17:19:25 +03001061 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001062 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001063 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001064 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001065 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001066 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001067 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001068 xdr_encode_hyper(p, args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
1070 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001071 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001072 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001073 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
Andy Adamsond0179312008-12-23 16:06:17 -05001075 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001076 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001079static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Al Viro8687b632006-10-19 23:28:48 -07001081 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Benny Halevy13c65ce2009-08-14 17:19:25 +03001083 p = reserve_space(xdr, 52);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001084 *p++ = cpu_to_be32(OP_LOCKT);
1085 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001086 p = xdr_encode_hyper(p, args->fl->fl_start);
1087 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1088 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001089 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001090 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001091 xdr_encode_hyper(p, args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001092 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001093 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001096static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Al Viro8687b632006-10-19 23:28:48 -07001098 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Benny Halevy13c65ce2009-08-14 17:19:25 +03001100 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001101 *p++ = cpu_to_be32(OP_LOCKU);
1102 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1103 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001104 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001105 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001106 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001107 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001108 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001111static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
1113 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001114 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Benny Halevy13c65ce2009-08-14 17:19:25 +03001116 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001117 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001118 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001119 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001120 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001123static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Al Viro8687b632006-10-19 23:28:48 -07001125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Benny Halevy13c65ce2009-08-14 17:19:25 +03001127 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001128 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001129 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001130 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001131 break;
1132 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001133 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001134 break;
1135 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001136 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001137 break;
1138 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001139 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
Benny Halevy34558512009-08-14 17:19:30 +03001141 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
1144static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1145{
Al Viro8687b632006-10-19 23:28:48 -07001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 /*
1148 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1149 * owner 4 = 32
1150 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001151 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001152 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001153 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001154 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001155 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001156 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001157 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001158 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001159 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
1162static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1163{
Al Viro8687b632006-10-19 23:28:48 -07001164 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001165 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Benny Halevy13c65ce2009-08-14 17:19:25 +03001167 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001169 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001170 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001171 encode_attrs(xdr, arg->u.attrs, arg->server);
1172 break;
1173 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001174 clp = arg->server->nfs_client;
1175 if (clp->cl_minorversion > 0) {
1176 if (nfs4_has_persistent_session(clp)) {
1177 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1178 encode_attrs(xdr, arg->u.attrs, arg->server);
1179 } else {
1180 struct iattr dummy;
1181
1182 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1183 encode_nfs4_verifier(xdr, &arg->u.verifier);
1184 dummy.ia_valid = 0;
1185 encode_attrs(xdr, &dummy, arg->server);
1186 }
1187 } else {
1188 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1189 encode_nfs4_verifier(xdr, &arg->u.verifier);
1190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192}
1193
1194static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1195{
Al Viro8687b632006-10-19 23:28:48 -07001196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Benny Halevy13c65ce2009-08-14 17:19:25 +03001198 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001200 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001201 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001202 break;
1203 default:
1204 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001205 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001206 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
1208}
1209
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001210static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
Al Viro8687b632006-10-19 23:28:48 -07001212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Benny Halevy13c65ce2009-08-14 17:19:25 +03001214 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001216 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001217 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001218 break;
1219 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001220 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001221 break;
1222 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001223 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001224 break;
1225 default:
1226 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 }
1228}
1229
1230static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1231{
Al Viro8687b632006-10-19 23:28:48 -07001232 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Benny Halevy13c65ce2009-08-14 17:19:25 +03001234 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001235 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 encode_string(xdr, name->len, name->name);
1237}
1238
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001239static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240{
Al Viro8687b632006-10-19 23:28:48 -07001241 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Benny Halevy13c65ce2009-08-14 17:19:25 +03001243 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001244 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 encode_delegation_type(xdr, type);
1246}
1247
1248static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1249{
Al Viro8687b632006-10-19 23:28:48 -07001250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Benny Halevy13c65ce2009-08-14 17:19:25 +03001252 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001254 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 encode_string(xdr, name->len, name->name);
1256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
1260 encode_openhdr(xdr, arg);
1261 encode_opentype(xdr, arg);
1262 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001263 case NFS4_OPEN_CLAIM_NULL:
1264 encode_claim_null(xdr, arg->name);
1265 break;
1266 case NFS4_OPEN_CLAIM_PREVIOUS:
1267 encode_claim_previous(xdr, arg->u.delegation_type);
1268 break;
1269 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1270 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1271 break;
1272 default:
1273 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 }
Andy Adamsond0179312008-12-23 16:06:17 -05001275 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001276 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279static 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 -07001280{
Al Viro8687b632006-10-19 23:28:48 -07001281 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
Benny Halevy13c65ce2009-08-14 17:19:25 +03001283 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001284 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001285 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001286 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001287 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001288 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Benny Halevy13c65ce2009-08-14 17:19:25 +03001295 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001296 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001297 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001298 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001299 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001300 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001301 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001304static void
Andy Adamsond0179312008-12-23 16:06:17 -05001305encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
1307 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Benny Halevy13c65ce2009-08-14 17:19:25 +03001310 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001311 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001312 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001313 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001314 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315}
1316
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001317static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
Andy Adamson05d564f2008-12-23 16:06:15 -05001319 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001320
Benny Halevy13c65ce2009-08-14 17:19:25 +03001321 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001322 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001323 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001324 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
1327static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1328{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Benny Halevy13c65ce2009-08-14 17:19:25 +03001332 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 if (ctx->state != NULL) {
1334 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Benny Halevy34558512009-08-14 17:19:30 +03001335 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 } else
Benny Halevy34558512009-08-14 17:19:30 +03001337 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001340static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Al Viro8687b632006-10-19 23:28:48 -07001342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Benny Halevy13c65ce2009-08-14 17:19:25 +03001344 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001345 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347 encode_stateid(xdr, args->context);
1348
Benny Halevy13c65ce2009-08-14 17:19:25 +03001349 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001350 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001351 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001352 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001353 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354}
1355
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001356static 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 -07001357{
Manoj Naik97d312d2005-06-22 17:16:39 +00001358 uint32_t attrs[2] = {
1359 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1360 FATTR4_WORD1_MOUNTED_ON_FILEID,
1361 };
Al Viro8687b632006-10-19 23:28:48 -07001362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Benny Halevy13c65ce2009-08-14 17:19:25 +03001364 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001365 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001366 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001367 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001368 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1369 *p++ = cpu_to_be32(readdir->count);
1370 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001371 /* Switch to mounted_on_fileid if the server supports it */
1372 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1373 attrs[0] &= ~FATTR4_WORD0_FILEID;
1374 else
1375 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001376 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001377 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001378 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001379 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001380 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1381 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001382 (unsigned long long)readdir->cookie,
1383 ((u32 *)readdir->verifier.data)[0],
1384 ((u32 *)readdir->verifier.data)[1],
1385 attrs[0] & readdir->bitmask[0],
1386 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001389static 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 -07001390{
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy13c65ce2009-08-14 17:19:25 +03001393 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001394 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001395 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001396 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001399static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001404 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001405 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001406 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001407 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408}
1409
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001410static 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 -07001411{
Al Viro8687b632006-10-19 23:28:48 -07001412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Benny Halevy811652b2009-08-14 17:19:34 +03001414 p = reserve_space(xdr, 4);
1415 *p = cpu_to_be32(OP_RENAME);
1416 encode_string(xdr, oldname->len, oldname->name);
1417 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001418 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001419 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001422static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Al Viro8687b632006-10-19 23:28:48 -07001424 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Benny Halevy13c65ce2009-08-14 17:19:25 +03001426 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001427 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001428 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001429 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001430 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001433static void
Andy Adamsond0179312008-12-23 16:06:17 -05001434encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001435{
Al Viro8687b632006-10-19 23:28:48 -07001436 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001437
Benny Halevy13c65ce2009-08-14 17:19:25 +03001438 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001440 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001441 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001442}
1443
1444static int
Andy Adamsond0179312008-12-23 16:06:17 -05001445encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001450 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001451 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001452 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001453 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001454 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001455 if (arg->acl_len % 4)
1456 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001458 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001459 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001460 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001461 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001462 return 0;
1463}
1464
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001465static void
Andy Adamsond0179312008-12-23 16:06:17 -05001466encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Al Viro8687b632006-10-19 23:28:48 -07001468 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Benny Halevy13c65ce2009-08-14 17:19:25 +03001470 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001471 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001472 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001473 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001476static 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 -07001477{
Al Viro8687b632006-10-19 23:28:48 -07001478 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001479
Benny Halevy13c65ce2009-08-14 17:19:25 +03001480 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001481 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001482 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001483 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001484 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001485 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486}
1487
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001488static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Al Viro8687b632006-10-19 23:28:48 -07001490 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Benny Halevy13c65ce2009-08-14 17:19:25 +03001492 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001493 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001494 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
1496 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001497 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001498 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1500 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001501 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001502 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001503 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001504 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static 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 -07001508{
Andy Adamson05d564f2008-12-23 16:06:15 -05001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001512 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001513 p = xdr_encode_hyper(p, client_state->cl_clientid);
Benny Halevy34558512009-08-14 17:19:30 +03001514 xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001515 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001516 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001519static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
Al Viro8687b632006-10-19 23:28:48 -07001521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Benny Halevy13c65ce2009-08-14 17:19:25 +03001523 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001524 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 encode_stateid(xdr, args->context);
1527
Benny Halevy13c65ce2009-08-14 17:19:25 +03001528 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001529 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001530 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001531 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
1533 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001534 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001535 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Al Viro8687b632006-10-19 23:28:48 -07001540 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Benny Halevy13c65ce2009-08-14 17:19:25 +03001542 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Benny Halevye75bc1c2009-08-14 17:18:54 +03001544 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001545 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001546 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001547 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001549
Benny Halevy99fe60d2009-04-01 09:22:29 -04001550#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001551/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001552static void encode_exchange_id(struct xdr_stream *xdr,
1553 struct nfs41_exchange_id_args *args,
1554 struct compound_hdr *hdr)
1555{
1556 __be32 *p;
1557
Benny Halevy13c65ce2009-08-14 17:19:25 +03001558 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001559 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001560 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001561
1562 encode_string(xdr, args->id_len, args->id);
1563
Benny Halevy13c65ce2009-08-14 17:19:25 +03001564 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001565 *p++ = cpu_to_be32(args->flags);
1566 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001567 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001568 hdr->nops++;
1569 hdr->replen += decode_exchange_id_maxsz;
1570}
Andy Adamsonfc931582009-04-01 09:22:31 -04001571
1572static void encode_create_session(struct xdr_stream *xdr,
1573 struct nfs41_create_session_args *args,
1574 struct compound_hdr *hdr)
1575{
1576 __be32 *p;
1577 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1578 uint32_t len;
1579 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001580 u32 max_resp_sz_cached;
1581
1582 /*
1583 * Assumes OPEN is the biggest non-idempotent compound.
1584 * 2 is the verifier.
1585 */
1586 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1587 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001588
Andy Adamsonfc931582009-04-01 09:22:31 -04001589 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1590 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001591
Benny Halevy13c65ce2009-08-14 17:19:25 +03001592 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001593 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001594 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001595 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1596 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001597
Andy Adamsonfc931582009-04-01 09:22:31 -04001598 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001599 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1600 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1601 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001602 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1604 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1605 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001606
1607 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001608 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1609 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1610 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1611 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1612 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1613 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1614 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001615
Benny Halevye75bc1c2009-08-14 17:18:54 +03001616 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001617 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001618 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001619
1620 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001621 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001622 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001623 *p++ = cpu_to_be32(0); /* UID */
1624 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001625 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001626 hdr->nops++;
1627 hdr->replen += decode_create_session_maxsz;
1628}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001629
1630static void encode_destroy_session(struct xdr_stream *xdr,
1631 struct nfs4_session *session,
1632 struct compound_hdr *hdr)
1633{
1634 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001635 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001636 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001637 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001638 hdr->nops++;
1639 hdr->replen += decode_destroy_session_maxsz;
1640}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001641
1642static void encode_reclaim_complete(struct xdr_stream *xdr,
1643 struct nfs41_reclaim_complete_args *args,
1644 struct compound_hdr *hdr)
1645{
1646 __be32 *p;
1647
1648 p = reserve_space(xdr, 8);
1649 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1650 *p++ = cpu_to_be32(args->one_fs);
1651 hdr->nops++;
1652 hdr->replen += decode_reclaim_complete_maxsz;
1653}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001654#endif /* CONFIG_NFS_V4_1 */
1655
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001656static void encode_sequence(struct xdr_stream *xdr,
1657 const struct nfs4_sequence_args *args,
1658 struct compound_hdr *hdr)
1659{
1660#if defined(CONFIG_NFS_V4_1)
1661 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001662 struct nfs4_slot_table *tp;
1663 struct nfs4_slot *slot;
1664 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001665
1666 if (!session)
1667 return;
1668
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001669 tp = &session->fc_slot_table;
1670
1671 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1672 slot = tp->slots + args->sa_slotid;
1673
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001675 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001676
1677 /*
1678 * Sessionid + seqid + slotid + max slotid + cache_this
1679 */
1680 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1681 "max_slotid=%d cache_this=%d\n",
1682 __func__,
1683 ((u32 *)session->sess_id.data)[0],
1684 ((u32 *)session->sess_id.data)[1],
1685 ((u32 *)session->sess_id.data)[2],
1686 ((u32 *)session->sess_id.data)[3],
1687 slot->seq_nr, args->sa_slotid,
1688 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001689 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001690 *p++ = cpu_to_be32(slot->seq_nr);
1691 *p++ = cpu_to_be32(args->sa_slotid);
1692 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001693 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001694 hdr->nops++;
1695 hdr->replen += decode_sequence_maxsz;
1696#endif /* CONFIG_NFS_V4_1 */
1697}
1698
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699/*
1700 * END OF "GENERIC" ENCODE ROUTINES.
1701 */
1702
Benny Halevy66cc0422009-04-01 09:22:10 -04001703static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1704{
1705#if defined(CONFIG_NFS_V4_1)
1706 if (args->sa_session)
1707 return args->sa_session->clp->cl_minorversion;
1708#endif /* CONFIG_NFS_V4_1 */
1709 return 0;
1710}
1711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712/*
1713 * Encode an ACCESS request
1714 */
Al Viro8687b632006-10-19 23:28:48 -07001715static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 struct xdr_stream xdr;
1718 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001719 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001723 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001724 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001725 encode_putfh(&xdr, args->fh, &hdr);
1726 encode_access(&xdr, args->access, &hdr);
1727 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001728 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001729 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
1732/*
1733 * Encode LOOKUP request
1734 */
Al Viro8687b632006-10-19 23:28:48 -07001735static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
1737 struct xdr_stream xdr;
1738 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001739 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001743 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001744 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001745 encode_putfh(&xdr, args->dir_fh, &hdr);
1746 encode_lookup(&xdr, args->name, &hdr);
1747 encode_getfh(&xdr, &hdr);
1748 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001749 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001750 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
1753/*
1754 * Encode LOOKUP_ROOT request
1755 */
Al Viro8687b632006-10-19 23:28:48 -07001756static 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 -07001757{
1758 struct xdr_stream xdr;
1759 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001760 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001764 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001765 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001766 encode_putrootfh(&xdr, &hdr);
1767 encode_getfh(&xdr, &hdr);
1768 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001769 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001770 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
1773/*
1774 * Encode REMOVE request
1775 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001776static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777{
1778 struct xdr_stream xdr;
1779 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001780 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001784 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001785 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001786 encode_putfh(&xdr, args->fh, &hdr);
1787 encode_remove(&xdr, &args->name, &hdr);
1788 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001789 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001790 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791}
1792
1793/*
1794 * Encode RENAME request
1795 */
Al Viro8687b632006-10-19 23:28:48 -07001796static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
1798 struct xdr_stream xdr;
1799 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001800 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001804 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001805 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001806 encode_putfh(&xdr, args->old_dir, &hdr);
1807 encode_savefh(&xdr, &hdr);
1808 encode_putfh(&xdr, args->new_dir, &hdr);
1809 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1810 encode_getfattr(&xdr, args->bitmask, &hdr);
1811 encode_restorefh(&xdr, &hdr);
1812 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001813 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001814 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
1817/*
1818 * Encode LINK request
1819 */
Al Viro8687b632006-10-19 23:28:48 -07001820static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821{
1822 struct xdr_stream xdr;
1823 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001824 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001828 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001829 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001830 encode_putfh(&xdr, args->fh, &hdr);
1831 encode_savefh(&xdr, &hdr);
1832 encode_putfh(&xdr, args->dir_fh, &hdr);
1833 encode_link(&xdr, args->name, &hdr);
1834 encode_getfattr(&xdr, args->bitmask, &hdr);
1835 encode_restorefh(&xdr, &hdr);
1836 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001837 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001838 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839}
1840
1841/*
1842 * Encode CREATE request
1843 */
Al Viro8687b632006-10-19 23:28:48 -07001844static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845{
1846 struct xdr_stream xdr;
1847 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001848 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001852 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001853 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001854 encode_putfh(&xdr, args->dir_fh, &hdr);
1855 encode_savefh(&xdr, &hdr);
1856 encode_create(&xdr, args, &hdr);
1857 encode_getfh(&xdr, &hdr);
1858 encode_getfattr(&xdr, args->bitmask, &hdr);
1859 encode_restorefh(&xdr, &hdr);
1860 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001861 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001862 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863}
1864
1865/*
1866 * Encode SYMLINK request
1867 */
Al Viro8687b632006-10-19 23:28:48 -07001868static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
1870 return nfs4_xdr_enc_create(req, p, args);
1871}
1872
1873/*
1874 * Encode GETATTR request
1875 */
Al Viro8687b632006-10-19 23:28:48 -07001876static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
1878 struct xdr_stream xdr;
1879 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001880 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001884 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001885 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001886 encode_putfh(&xdr, args->fh, &hdr);
1887 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001888 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001889 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890}
1891
1892/*
1893 * Encode a CLOSE request
1894 */
Al Viro8687b632006-10-19 23:28:48 -07001895static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896{
Andy Adamson05d564f2008-12-23 16:06:15 -05001897 struct xdr_stream xdr;
1898 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001899 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001900 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
Andy Adamson05d564f2008-12-23 16:06:15 -05001902 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001903 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001904 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001905 encode_putfh(&xdr, args->fh, &hdr);
1906 encode_close(&xdr, args, &hdr);
1907 encode_getfattr(&xdr, args->bitmask, &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
1914 */
Al Viro8687b632006-10-19 23:28:48 -07001915static int nfs4_xdr_enc_open(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_savefh(&xdr, &hdr);
1927 encode_open(&xdr, args, &hdr);
1928 encode_getfh(&xdr, &hdr);
1929 encode_getfattr(&xdr, args->bitmask, &hdr);
1930 encode_restorefh(&xdr, &hdr);
1931 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001932 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001933 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934}
1935
1936/*
1937 * Encode an OPEN_CONFIRM request
1938 */
Al Viro8687b632006-10-19 23:28:48 -07001939static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940{
1941 struct xdr_stream xdr;
1942 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001943 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
1946 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001947 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001948 encode_putfh(&xdr, args->fh, &hdr);
1949 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001950 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001951 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952}
1953
1954/*
1955 * Encode an OPEN request with no attributes.
1956 */
Al Viro8687b632006-10-19 23:28:48 -07001957static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
1959 struct xdr_stream xdr;
1960 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001961 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001965 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001966 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001967 encode_putfh(&xdr, args->fh, &hdr);
1968 encode_open(&xdr, args, &hdr);
1969 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001970 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001971 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974/*
1975 * Encode an OPEN_DOWNGRADE request
1976 */
Al Viro8687b632006-10-19 23:28:48 -07001977static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978{
1979 struct xdr_stream xdr;
1980 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001981 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001985 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001986 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001987 encode_putfh(&xdr, args->fh, &hdr);
1988 encode_open_downgrade(&xdr, args, &hdr);
1989 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001990 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001991 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
1994/*
1995 * Encode a LOCK request
1996 */
Al Viro8687b632006-10-19 23:28:48 -07001997static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998{
1999 struct xdr_stream xdr;
2000 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
2004 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002005 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002006 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002007 encode_putfh(&xdr, args->fh, &hdr);
2008 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002009 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002010 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011}
2012
2013/*
2014 * Encode a LOCKT request
2015 */
Al Viro8687b632006-10-19 23:28:48 -07002016static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017{
2018 struct xdr_stream xdr;
2019 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002020 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
2023 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002024 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002025 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002026 encode_putfh(&xdr, args->fh, &hdr);
2027 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002028 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002029 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030}
2031
2032/*
2033 * Encode a LOCKU request
2034 */
Al Viro8687b632006-10-19 23:28:48 -07002035static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036{
2037 struct xdr_stream xdr;
2038 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002039 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
2042 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002043 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002044 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002045 encode_putfh(&xdr, args->fh, &hdr);
2046 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002047 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002048 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
2051/*
2052 * Encode a READLINK request
2053 */
Al Viro8687b632006-10-19 23:28:48 -07002054static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
2056 struct xdr_stream xdr;
2057 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002058 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002062 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002063 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002064 encode_putfh(&xdr, args->fh, &hdr);
2065 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002066
Benny Halevy28f56692009-04-01 09:22:09 -04002067 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002068 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002069 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
2073/*
2074 * Encode a READDIR request
2075 */
Al Viro8687b632006-10-19 23:28:48 -07002076static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 struct xdr_stream xdr;
2079 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002084 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002085 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002086 encode_putfh(&xdr, args->fh, &hdr);
2087 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002088
Benny Halevy28f56692009-04-01 09:22:09 -04002089 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002090 args->pgbase, args->count);
2091 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002092 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002093 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002094 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002095 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
2098/*
2099 * Encode a READ request
2100 */
Al Viro8687b632006-10-19 23:28:48 -07002101static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct xdr_stream xdr;
2104 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002105 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002109 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002110 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002111 encode_putfh(&xdr, args->fh, &hdr);
2112 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Benny Halevy28f56692009-04-01 09:22:09 -04002114 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002116 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002117 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002118 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120
2121/*
2122 * Encode an SETATTR request
2123 */
Al Viro8687b632006-10-19 23:28:48 -07002124static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
Andy Adamson05d564f2008-12-23 16:06:15 -05002126 struct xdr_stream xdr;
2127 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002129 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Andy Adamson05d564f2008-12-23 16:06:15 -05002131 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002132 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002133 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002134 encode_putfh(&xdr, args->fh, &hdr);
2135 encode_setattr(&xdr, args, args->server, &hdr);
2136 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002137 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002138 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139}
2140
2141/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002142 * Encode a GETACL request
2143 */
2144static int
Al Viro8687b632006-10-19 23:28:48 -07002145nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002146 struct nfs_getaclargs *args)
2147{
2148 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002149 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002150 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002151 };
Benny Halevy28f56692009-04-01 09:22:09 -04002152 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002153
2154 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002155 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002156 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002157 encode_putfh(&xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002158 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002159 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2160
Benny Halevy28f56692009-04-01 09:22:09 -04002161 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002162 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002163 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002164 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002165}
2166
2167/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 * Encode a WRITE request
2169 */
Al Viro8687b632006-10-19 23:28:48 -07002170static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171{
2172 struct xdr_stream xdr;
2173 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002174 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
2177 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002178 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002179 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002180 encode_putfh(&xdr, args->fh, &hdr);
2181 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002182 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002183 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002184 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * a COMMIT request
2190 */
Al Viro8687b632006-10-19 23:28:48 -07002191static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
2193 struct xdr_stream xdr;
2194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
2198 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002199 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002200 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002201 encode_putfh(&xdr, args->fh, &hdr);
2202 encode_commit(&xdr, args, &hdr);
2203 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002204 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002205 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206}
2207
2208/*
2209 * FSINFO request
2210 */
Al Viro8687b632006-10-19 23:28:48 -07002211static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
2213 struct xdr_stream xdr;
2214 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002215 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
2218 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002219 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002220 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002221 encode_putfh(&xdr, args->fh, &hdr);
2222 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225}
2226
2227/*
2228 * a PATHCONF request
2229 */
Al Viro8687b632006-10-19 23:28:48 -07002230static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 struct xdr_stream xdr;
2233 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002234 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002238 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002239 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002240 encode_putfh(&xdr, args->fh, &hdr);
2241 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2242 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002243 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245}
2246
2247/*
2248 * a STATFS request
2249 */
Al Viro8687b632006-10-19 23:28:48 -07002250static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 struct xdr_stream xdr;
2253 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002254 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002258 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002259 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002260 encode_putfh(&xdr, args->fh, &hdr);
2261 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2262 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002264 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265}
2266
2267/*
2268 * GETATTR_BITMAP request
2269 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002270static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2271 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272{
2273 struct xdr_stream xdr;
2274 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002275 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002279 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002280 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002281 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002282 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2283 FATTR4_WORD0_LINK_SUPPORT|
2284 FATTR4_WORD0_SYMLINK_SUPPORT|
2285 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002286 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002287 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288}
2289
2290/*
2291 * a RENEW request
2292 */
Al Viro8687b632006-10-19 23:28:48 -07002293static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
2295 struct xdr_stream xdr;
2296 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002297 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
2299
2300 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002301 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002302 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002304 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * a SETCLIENTID request
2309 */
Al Viro8687b632006-10-19 23:28:48 -07002310static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
2312 struct xdr_stream xdr;
2313 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002314 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 };
2316
2317 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002318 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002319 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002320 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002321 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * a SETCLIENTID_CONFIRM request
2326 */
Al Viro8687b632006-10-19 23:28:48 -07002327static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
2329 struct xdr_stream xdr;
2330 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002331 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
2333 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
2335 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002336 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002337 encode_setclientid_confirm(&xdr, clp, &hdr);
2338 encode_putrootfh(&xdr, &hdr);
2339 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002340 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002341 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342}
2343
2344/*
2345 * DELEGRETURN request
2346 */
Al Viro8687b632006-10-19 23:28:48 -07002347static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348{
2349 struct xdr_stream xdr;
2350 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002351 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
2354 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002355 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002356 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002357 encode_putfh(&xdr, args->fhandle, &hdr);
2358 encode_delegreturn(&xdr, args->stateid, &hdr);
2359 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002361 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
2364/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002365 * Encode FS_LOCATIONS request
2366 */
Al Viro8687b632006-10-19 23:28:48 -07002367static 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 -04002368{
2369 struct xdr_stream xdr;
2370 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002371 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002372 };
Benny Halevy28f56692009-04-01 09:22:09 -04002373 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002374
2375 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002376 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002377 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002378 encode_putfh(&xdr, args->dir_fh, &hdr);
2379 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002380 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002381 encode_fs_locations(&xdr, args->bitmask, &hdr);
2382
Benny Halevy28f56692009-04-01 09:22:09 -04002383 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002384 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002385 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002386 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002387}
2388
Benny Halevy99fe60d2009-04-01 09:22:29 -04002389#if defined(CONFIG_NFS_V4_1)
2390/*
2391 * EXCHANGE_ID request
2392 */
2393static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2394 struct nfs41_exchange_id_args *args)
2395{
2396 struct xdr_stream xdr;
2397 struct compound_hdr hdr = {
2398 .minorversion = args->client->cl_minorversion,
2399 };
2400
2401 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2402 encode_compound_hdr(&xdr, req, &hdr);
2403 encode_exchange_id(&xdr, args, &hdr);
2404 encode_nops(&hdr);
2405 return 0;
2406}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002407
2408/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002409 * a CREATE_SESSION request
2410 */
2411static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2412 struct nfs41_create_session_args *args)
2413{
2414 struct xdr_stream xdr;
2415 struct compound_hdr hdr = {
2416 .minorversion = args->client->cl_minorversion,
2417 };
2418
2419 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2420 encode_compound_hdr(&xdr, req, &hdr);
2421 encode_create_session(&xdr, args, &hdr);
2422 encode_nops(&hdr);
2423 return 0;
2424}
2425
2426/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002427 * a DESTROY_SESSION request
2428 */
2429static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2430 struct nfs4_session *session)
2431{
2432 struct xdr_stream xdr;
2433 struct compound_hdr hdr = {
2434 .minorversion = session->clp->cl_minorversion,
2435 };
2436
2437 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2438 encode_compound_hdr(&xdr, req, &hdr);
2439 encode_destroy_session(&xdr, session, &hdr);
2440 encode_nops(&hdr);
2441 return 0;
2442}
2443
2444/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002445 * a SEQUENCE request
2446 */
2447static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2448 struct nfs4_sequence_args *args)
2449{
2450 struct xdr_stream xdr;
2451 struct compound_hdr hdr = {
2452 .minorversion = nfs4_xdr_minorversion(args),
2453 };
2454
2455 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2456 encode_compound_hdr(&xdr, req, &hdr);
2457 encode_sequence(&xdr, args, &hdr);
2458 encode_nops(&hdr);
2459 return 0;
2460}
2461
2462/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002463 * a GET_LEASE_TIME request
2464 */
2465static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2466 struct nfs4_get_lease_time_args *args)
2467{
2468 struct xdr_stream xdr;
2469 struct compound_hdr hdr = {
2470 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2471 };
2472 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2473
2474 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2475 encode_compound_hdr(&xdr, req, &hdr);
2476 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2477 encode_putrootfh(&xdr, &hdr);
2478 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2479 encode_nops(&hdr);
2480 return 0;
2481}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002482
2483/*
2484 * a RECLAIM_COMPLETE request
2485 */
2486static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2487 struct nfs41_reclaim_complete_args *args)
2488{
2489 struct xdr_stream xdr;
2490 struct compound_hdr hdr = {
2491 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2492 };
2493
2494 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2495 encode_compound_hdr(&xdr, req, &hdr);
2496 encode_sequence(&xdr, &args->seq_args, &hdr);
2497 encode_reclaim_complete(&xdr, args, &hdr);
2498 encode_nops(&hdr);
2499 return 0;
2500}
2501
Benny Halevy99fe60d2009-04-01 09:22:29 -04002502#endif /* CONFIG_NFS_V4_1 */
2503
Benny Halevy686841b2009-08-14 17:19:48 +03002504static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2505{
2506 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2507 "Remaining buffer length is %tu words.\n",
2508 func, xdr->end - xdr->p);
2509}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Trond Myklebust683b57b2006-06-09 09:34:22 -04002511static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512{
Al Viro8687b632006-10-19 23:28:48 -07002513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514
Benny Halevyc0eae662009-08-14 17:20:14 +03002515 p = xdr_inline_decode(xdr, 4);
2516 if (unlikely(!p))
2517 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002518 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002519 p = xdr_inline_decode(xdr, *len);
2520 if (unlikely(!p))
2521 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 *string = (char *)p;
2523 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002524out_overflow:
2525 print_overflow_msg(__func__, xdr);
2526 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527}
2528
2529static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2530{
Al Viro8687b632006-10-19 23:28:48 -07002531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Benny Halevyc0eae662009-08-14 17:20:14 +03002533 p = xdr_inline_decode(xdr, 8);
2534 if (unlikely(!p))
2535 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002536 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002537 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002538
Benny Halevyc0eae662009-08-14 17:20:14 +03002539 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2540 if (unlikely(!p))
2541 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 hdr->tag = (char *)p;
2543 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002544 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002545 if (unlikely(hdr->nops < 1))
2546 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002548out_overflow:
2549 print_overflow_msg(__func__, xdr);
2550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
2553static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2554{
Al Viro8687b632006-10-19 23:28:48 -07002555 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 uint32_t opnum;
2557 int32_t nfserr;
2558
Benny Halevyc0eae662009-08-14 17:20:14 +03002559 p = xdr_inline_decode(xdr, 8);
2560 if (unlikely(!p))
2561 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002562 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002564 dprintk("nfs: Server returned operation"
2565 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 opnum, expected);
2567 return -EIO;
2568 }
Benny Halevycccddf42009-08-14 17:20:19 +03002569 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002571 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002573out_overflow:
2574 print_overflow_msg(__func__, xdr);
2575 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002579static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
Al Viro8687b632006-10-19 23:28:48 -07002581 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002582 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 char *str;
2584
Benny Halevyc0eae662009-08-14 17:20:14 +03002585 p = xdr_inline_decode(xdr, 12);
2586 if (likely(p))
2587 return decode_opaque_inline(xdr, &strlen, &str);
2588 print_overflow_msg(__func__, xdr);
2589 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590}
2591
2592static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2593{
Al Viro8687b632006-10-19 23:28:48 -07002594 uint32_t bmlen;
2595 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
Benny Halevyc0eae662009-08-14 17:20:14 +03002597 p = xdr_inline_decode(xdr, 4);
2598 if (unlikely(!p))
2599 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002600 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
2602 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002603 p = xdr_inline_decode(xdr, (bmlen << 2));
2604 if (unlikely(!p))
2605 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002607 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002609 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 }
2611 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002612out_overflow:
2613 print_overflow_msg(__func__, xdr);
2614 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615}
2616
Al Viro8687b632006-10-19 23:28:48 -07002617static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Al Viro8687b632006-10-19 23:28:48 -07002619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
Benny Halevyc0eae662009-08-14 17:20:14 +03002621 p = xdr_inline_decode(xdr, 4);
2622 if (unlikely(!p))
2623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002624 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 *savep = xdr->p;
2626 return 0;
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_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2633{
2634 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2635 decode_attr_bitmap(xdr, bitmask);
2636 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2637 } else
2638 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002639 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 return 0;
2641}
2642
2643static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2644{
Al Viro8687b632006-10-19 23:28:48 -07002645 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002646 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 *type = 0;
2649 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2650 return -EIO;
2651 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002652 p = xdr_inline_decode(xdr, 4);
2653 if (unlikely(!p))
2654 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002655 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002657 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 return -EIO;
2659 }
2660 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002661 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002663 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002664 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002665out_overflow:
2666 print_overflow_msg(__func__, xdr);
2667 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668}
2669
2670static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2671{
Al Viro8687b632006-10-19 23:28:48 -07002672 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002673 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
2675 *change = 0;
2676 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2677 return -EIO;
2678 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002679 p = xdr_inline_decode(xdr, 8);
2680 if (unlikely(!p))
2681 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002682 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002684 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002686 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002688 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002689out_overflow:
2690 print_overflow_msg(__func__, xdr);
2691 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692}
2693
2694static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2695{
Al Viro8687b632006-10-19 23:28:48 -07002696 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002697 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 *size = 0;
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2701 return -EIO;
2702 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002703 p = xdr_inline_decode(xdr, 8);
2704 if (unlikely(!p))
2705 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002706 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002708 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002710 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002711 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002712out_overflow:
2713 print_overflow_msg(__func__, xdr);
2714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715}
2716
2717static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2718{
Al Viro8687b632006-10-19 23:28:48 -07002719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
2721 *res = 0;
2722 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2723 return -EIO;
2724 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002725 p = xdr_inline_decode(xdr, 4);
2726 if (unlikely(!p))
2727 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002728 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2730 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002731 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002733out_overflow:
2734 print_overflow_msg(__func__, xdr);
2735 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736}
2737
2738static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2739{
Al Viro8687b632006-10-19 23:28:48 -07002740 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
2742 *res = 0;
2743 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2744 return -EIO;
2745 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002746 p = xdr_inline_decode(xdr, 4);
2747 if (unlikely(!p))
2748 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002749 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002752 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002754out_overflow:
2755 print_overflow_msg(__func__, xdr);
2756 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757}
2758
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002759static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760{
Al Viro8687b632006-10-19 23:28:48 -07002761 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002762 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763
2764 fsid->major = 0;
2765 fsid->minor = 0;
2766 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2767 return -EIO;
2768 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002769 p = xdr_inline_decode(xdr, 16);
2770 if (unlikely(!p))
2771 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002772 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002773 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002775 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002777 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 (unsigned long long)fsid->major,
2779 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002780 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002781out_overflow:
2782 print_overflow_msg(__func__, xdr);
2783 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784}
2785
2786static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2787{
Al Viro8687b632006-10-19 23:28:48 -07002788 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
2790 *res = 60;
2791 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2792 return -EIO;
2793 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002794 p = xdr_inline_decode(xdr, 4);
2795 if (unlikely(!p))
2796 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002797 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2799 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002800 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002802out_overflow:
2803 print_overflow_msg(__func__, xdr);
2804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805}
2806
2807static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2808{
Al Viro8687b632006-10-19 23:28:48 -07002809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
2811 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2812 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2813 return -EIO;
2814 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002815 p = xdr_inline_decode(xdr, 4);
2816 if (unlikely(!p))
2817 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002818 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002821 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002823out_overflow:
2824 print_overflow_msg(__func__, xdr);
2825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826}
2827
2828static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2829{
Al Viro8687b632006-10-19 23:28:48 -07002830 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002831 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
2833 *fileid = 0;
2834 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2835 return -EIO;
2836 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002837 p = xdr_inline_decode(xdr, 8);
2838 if (unlikely(!p))
2839 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002840 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002842 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002844 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002845 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002846out_overflow:
2847 print_overflow_msg(__func__, xdr);
2848 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849}
2850
Manoj Naik99baf622006-06-09 09:34:24 -04002851static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2852{
Al Viro8687b632006-10-19 23:28:48 -07002853 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002854 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002855
2856 *fileid = 0;
2857 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2858 return -EIO;
2859 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002860 p = xdr_inline_decode(xdr, 8);
2861 if (unlikely(!p))
2862 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002863 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002864 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002865 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002866 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002867 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002868 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002869out_overflow:
2870 print_overflow_msg(__func__, xdr);
2871 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002872}
2873
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2875{
Al Viro8687b632006-10-19 23:28:48 -07002876 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 int status = 0;
2878
2879 *res = 0;
2880 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2881 return -EIO;
2882 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002883 p = xdr_inline_decode(xdr, 8);
2884 if (unlikely(!p))
2885 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002886 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2888 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002889 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002891out_overflow:
2892 print_overflow_msg(__func__, xdr);
2893 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
2896static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2897{
Al Viro8687b632006-10-19 23:28:48 -07002898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 int status = 0;
2900
2901 *res = 0;
2902 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2903 return -EIO;
2904 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002905 p = xdr_inline_decode(xdr, 8);
2906 if (unlikely(!p))
2907 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002908 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2910 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002911 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002913out_overflow:
2914 print_overflow_msg(__func__, xdr);
2915 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916}
2917
2918static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2919{
Al Viro8687b632006-10-19 23:28:48 -07002920 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 int status = 0;
2922
2923 *res = 0;
2924 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2925 return -EIO;
2926 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002927 p = xdr_inline_decode(xdr, 8);
2928 if (unlikely(!p))
2929 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002930 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2932 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002933 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002935out_overflow:
2936 print_overflow_msg(__func__, xdr);
2937 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938}
2939
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002940static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2941{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002942 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002943 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002944 int status = 0;
2945
Benny Halevyc0eae662009-08-14 17:20:14 +03002946 p = xdr_inline_decode(xdr, 4);
2947 if (unlikely(!p))
2948 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002949 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04002950 if (n == 0)
2951 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002952 dprintk("path ");
2953 path->ncomponents = 0;
2954 while (path->ncomponents < n) {
2955 struct nfs4_string *component = &path->components[path->ncomponents];
2956 status = decode_opaque_inline(xdr, &component->len, &component->data);
2957 if (unlikely(status != 0))
2958 goto out_eio;
2959 if (path->ncomponents != n)
2960 dprintk("/");
2961 dprintk("%s", component->data);
2962 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2963 path->ncomponents++;
2964 else {
2965 dprintk("cannot parse %d components in path\n", n);
2966 goto out_eio;
2967 }
2968 }
2969out:
2970 dprintk("\n");
2971 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002972root_path:
2973/* a root pathname is sent as a zero component4 */
2974 path->ncomponents = 1;
2975 path->components[0].len=0;
2976 path->components[0].data=NULL;
2977 dprintk("path /\n");
2978 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002979out_eio:
2980 dprintk(" status %d", status);
2981 status = -EIO;
2982 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002983out_overflow:
2984 print_overflow_msg(__func__, xdr);
2985 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002986}
2987
2988static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002989{
2990 int n;
Al Viro8687b632006-10-19 23:28:48 -07002991 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002992 int status = -EIO;
2993
2994 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2995 goto out;
2996 status = 0;
2997 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2998 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002999 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003000 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003001 if (unlikely(status != 0))
3002 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003003 p = xdr_inline_decode(xdr, 4);
3004 if (unlikely(!p))
3005 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003006 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003007 if (n <= 0)
3008 goto out_eio;
3009 res->nlocations = 0;
3010 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003011 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003012 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003013
Benny Halevyc0eae662009-08-14 17:20:14 +03003014 p = xdr_inline_decode(xdr, 4);
3015 if (unlikely(!p))
3016 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003017 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003018
3019 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003020 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003021 while (loc->nservers < m) {
3022 struct nfs4_string *server = &loc->servers[loc->nservers];
3023 status = decode_opaque_inline(xdr, &server->len, &server->data);
3024 if (unlikely(status != 0))
3025 goto out_eio;
3026 dprintk("%s ", server->data);
3027 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3028 loc->nservers++;
3029 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003030 unsigned int i;
3031 dprintk("%s: using first %u of %u servers "
3032 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003033 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003034 NFS4_FS_LOCATION_MAXSERVERS,
3035 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003036 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003037 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003038 char *data;
3039 status = decode_opaque_inline(xdr, &len, &data);
3040 if (unlikely(status != 0))
3041 goto out_eio;
3042 }
3043 }
3044 }
3045 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003046 if (unlikely(status != 0))
3047 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003048 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003049 res->nlocations++;
3050 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003051 if (res->nlocations != 0)
3052 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003053out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003054 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003055 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003056out_overflow:
3057 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003058out_eio:
3059 status = -EIO;
3060 goto out;
3061}
3062
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3064{
Al Viro8687b632006-10-19 23:28:48 -07003065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 int status = 0;
3067
3068 *res = 0;
3069 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3070 return -EIO;
3071 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003072 p = xdr_inline_decode(xdr, 8);
3073 if (unlikely(!p))
3074 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003075 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3077 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003078 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003080out_overflow:
3081 print_overflow_msg(__func__, xdr);
3082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083}
3084
3085static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3086{
Al Viro8687b632006-10-19 23:28:48 -07003087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 int status = 0;
3089
3090 *maxlink = 1;
3091 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3092 return -EIO;
3093 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003094 p = xdr_inline_decode(xdr, 4);
3095 if (unlikely(!p))
3096 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003097 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3099 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003100 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003102out_overflow:
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
3107static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3108{
Al Viro8687b632006-10-19 23:28:48 -07003109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 int status = 0;
3111
3112 *maxname = 1024;
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003116 p = xdr_inline_decode(xdr, 4);
3117 if (unlikely(!p))
3118 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003119 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3121 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003122 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003124out_overflow:
3125 print_overflow_msg(__func__, xdr);
3126 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
3129static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3130{
Al Viro8687b632006-10-19 23:28:48 -07003131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 int status = 0;
3133
3134 *res = 1024;
3135 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3136 return -EIO;
3137 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3138 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003139 p = xdr_inline_decode(xdr, 8);
3140 if (unlikely(!p))
3141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003142 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 if (maxread > 0x7FFFFFFF)
3144 maxread = 0x7FFFFFFF;
3145 *res = (uint32_t)maxread;
3146 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3147 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003148 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003150out_overflow:
3151 print_overflow_msg(__func__, xdr);
3152 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153}
3154
3155static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3156{
Al Viro8687b632006-10-19 23:28:48 -07003157 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 int status = 0;
3159
3160 *res = 1024;
3161 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3162 return -EIO;
3163 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3164 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003165 p = xdr_inline_decode(xdr, 8);
3166 if (unlikely(!p))
3167 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003168 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 if (maxwrite > 0x7FFFFFFF)
3170 maxwrite = 0x7FFFFFFF;
3171 *res = (uint32_t)maxwrite;
3172 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3173 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003174 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003176out_overflow:
3177 print_overflow_msg(__func__, xdr);
3178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179}
3180
Trond Myklebustbca79472009-03-11 14:10:26 -04003181static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182{
Trond Myklebustbca79472009-03-11 14:10:26 -04003183 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003184 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003185 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
3187 *mode = 0;
3188 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3189 return -EIO;
3190 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003191 p = xdr_inline_decode(xdr, 4);
3192 if (unlikely(!p))
3193 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003194 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003195 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003197 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003199 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003200 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003201out_overflow:
3202 print_overflow_msg(__func__, xdr);
3203 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204}
3205
3206static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3207{
Al Viro8687b632006-10-19 23:28:48 -07003208 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003209 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
3211 *nlink = 1;
3212 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3213 return -EIO;
3214 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003215 p = xdr_inline_decode(xdr, 4);
3216 if (unlikely(!p))
3217 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003218 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003222 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003223 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003224out_overflow:
3225 print_overflow_msg(__func__, xdr);
3226 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227}
3228
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003229static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3230 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231{
Al Viro8687b632006-10-19 23:28:48 -07003232 uint32_t len;
3233 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003234 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235
3236 *uid = -2;
3237 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3238 return -EIO;
3239 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003240 p = xdr_inline_decode(xdr, 4);
3241 if (unlikely(!p))
3242 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003243 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003244 p = xdr_inline_decode(xdr, len);
3245 if (unlikely(!p))
3246 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003247 if (!may_sleep) {
3248 /* do nothing */
3249 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003250 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3251 ret = NFS_ATTR_FATTR_OWNER;
3252 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003254 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003256 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003257 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3259 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003260 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003261 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003262out_overflow:
3263 print_overflow_msg(__func__, xdr);
3264 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265}
3266
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003267static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3268 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269{
Al Viro8687b632006-10-19 23:28:48 -07003270 uint32_t len;
3271 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003272 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
3274 *gid = -2;
3275 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3276 return -EIO;
3277 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003278 p = xdr_inline_decode(xdr, 4);
3279 if (unlikely(!p))
3280 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003281 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003282 p = xdr_inline_decode(xdr, len);
3283 if (unlikely(!p))
3284 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003285 if (!may_sleep) {
3286 /* do nothing */
3287 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003288 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3289 ret = NFS_ATTR_FATTR_GROUP;
3290 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003292 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003294 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3297 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003298 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003299 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003300out_overflow:
3301 print_overflow_msg(__func__, xdr);
3302 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303}
3304
3305static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3306{
Al Viro8687b632006-10-19 23:28:48 -07003307 uint32_t major = 0, minor = 0;
3308 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003309 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
3311 *rdev = MKDEV(0,0);
3312 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3313 return -EIO;
3314 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3315 dev_t tmp;
3316
Benny Halevyc0eae662009-08-14 17:20:14 +03003317 p = xdr_inline_decode(xdr, 8);
3318 if (unlikely(!p))
3319 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003320 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003321 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 tmp = MKDEV(major, minor);
3323 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3324 *rdev = tmp;
3325 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003326 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003328 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003329 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003330out_overflow:
3331 print_overflow_msg(__func__, xdr);
3332 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
3335static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3336{
Al Viro8687b632006-10-19 23:28:48 -07003337 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 int status = 0;
3339
3340 *res = 0;
3341 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3342 return -EIO;
3343 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003344 p = xdr_inline_decode(xdr, 8);
3345 if (unlikely(!p))
3346 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003347 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3349 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003350 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003352out_overflow:
3353 print_overflow_msg(__func__, xdr);
3354 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355}
3356
3357static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3358{
Al Viro8687b632006-10-19 23:28:48 -07003359 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 int status = 0;
3361
3362 *res = 0;
3363 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3364 return -EIO;
3365 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003366 p = xdr_inline_decode(xdr, 8);
3367 if (unlikely(!p))
3368 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003369 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3371 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003372 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003374out_overflow:
3375 print_overflow_msg(__func__, xdr);
3376 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377}
3378
3379static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3380{
Al Viro8687b632006-10-19 23:28:48 -07003381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 int status = 0;
3383
3384 *res = 0;
3385 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3386 return -EIO;
3387 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003388 p = xdr_inline_decode(xdr, 8);
3389 if (unlikely(!p))
3390 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003391 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3393 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003394 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003396out_overflow:
3397 print_overflow_msg(__func__, xdr);
3398 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399}
3400
3401static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3402{
Al Viro8687b632006-10-19 23:28:48 -07003403 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003404 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
3406 *used = 0;
3407 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3408 return -EIO;
3409 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003410 p = xdr_inline_decode(xdr, 8);
3411 if (unlikely(!p))
3412 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003413 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003415 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003417 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003419 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003420out_overflow:
3421 print_overflow_msg(__func__, xdr);
3422 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423}
3424
3425static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3426{
Al Viro8687b632006-10-19 23:28:48 -07003427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 uint64_t sec;
3429 uint32_t nsec;
3430
Benny Halevyc0eae662009-08-14 17:20:14 +03003431 p = xdr_inline_decode(xdr, 12);
3432 if (unlikely(!p))
3433 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003434 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003435 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 time->tv_sec = (time_t)sec;
3437 time->tv_nsec = (long)nsec;
3438 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003439out_overflow:
3440 print_overflow_msg(__func__, xdr);
3441 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442}
3443
3444static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3445{
3446 int status = 0;
3447
3448 time->tv_sec = 0;
3449 time->tv_nsec = 0;
3450 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3451 return -EIO;
3452 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3453 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003454 if (status == 0)
3455 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3457 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 return status;
3460}
3461
3462static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3463{
3464 int status = 0;
3465
3466 time->tv_sec = 0;
3467 time->tv_nsec = 0;
3468 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3469 return -EIO;
3470 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3471 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003472 if (status == 0)
3473 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3475 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003476 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 return status;
3478}
3479
3480static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3481{
3482 int status = 0;
3483
3484 time->tv_sec = 0;
3485 time->tv_nsec = 0;
3486 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3487 return -EIO;
3488 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3489 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003490 if (status == 0)
3491 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3493 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003494 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 return status;
3496}
3497
Al Viro8687b632006-10-19 23:28:48 -07003498static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499{
3500 unsigned int attrwords = XDR_QUADLEN(attrlen);
3501 unsigned int nwords = xdr->p - savep;
3502
3503 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003504 dprintk("%s: server returned incorrect attribute length: "
3505 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003506 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 attrwords << 2,
3508 (attrwords < nwords) ? '<' : '>',
3509 nwords << 2);
3510 return -EIO;
3511 }
3512 return 0;
3513}
3514
3515static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3516{
Al Viro8687b632006-10-19 23:28:48 -07003517 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518
Benny Halevyc0eae662009-08-14 17:20:14 +03003519 p = xdr_inline_decode(xdr, 20);
3520 if (unlikely(!p))
3521 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003522 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003523 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003524 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003526out_overflow:
3527 print_overflow_msg(__func__, xdr);
3528 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529}
3530
3531static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3532{
Al Viro8687b632006-10-19 23:28:48 -07003533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 uint32_t supp, acc;
3535 int status;
3536
3537 status = decode_op_hdr(xdr, OP_ACCESS);
3538 if (status)
3539 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003540 p = xdr_inline_decode(xdr, 8);
3541 if (unlikely(!p))
3542 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003543 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003544 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 access->supported = supp;
3546 access->access = acc;
3547 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003548out_overflow:
3549 print_overflow_msg(__func__, xdr);
3550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551}
3552
Benny Halevy07d30432009-08-14 17:19:52 +03003553static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554{
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003556
3557 p = xdr_inline_decode(xdr, len);
3558 if (likely(p)) {
3559 memcpy(buf, p, len);
3560 return 0;
3561 }
3562 print_overflow_msg(__func__, xdr);
3563 return -EIO;
3564}
3565
3566static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3567{
3568 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569}
3570
3571static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 int status;
3574
3575 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003576 if (status != -EIO)
3577 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003578 if (!status)
3579 status = decode_stateid(xdr, &res->stateid);
3580 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581}
3582
Benny Halevydb942bb2009-08-14 17:19:56 +03003583static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3584{
3585 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586}
3587
3588static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3589{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 int status;
3591
3592 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003593 if (!status)
3594 status = decode_verifier(xdr, res->verf->verifier);
3595 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596}
3597
3598static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3599{
Al Viro8687b632006-10-19 23:28:48 -07003600 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 uint32_t bmlen;
3602 int status;
3603
3604 status = decode_op_hdr(xdr, OP_CREATE);
3605 if (status)
3606 return status;
3607 if ((status = decode_change_info(xdr, cinfo)))
3608 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003609 p = xdr_inline_decode(xdr, 4);
3610 if (unlikely(!p))
3611 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003612 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003613 p = xdr_inline_decode(xdr, bmlen << 2);
3614 if (likely(p))
3615 return 0;
3616out_overflow:
3617 print_overflow_msg(__func__, xdr);
3618 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619}
3620
3621static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3622{
Al Viro8687b632006-10-19 23:28:48 -07003623 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003624 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 int status;
3626
3627 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3628 goto xdr_error;
3629 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3630 goto xdr_error;
3631 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3632 goto xdr_error;
3633 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3634 goto xdr_error;
3635 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3636 goto xdr_error;
3637 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3638 goto xdr_error;
3639 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3640 goto xdr_error;
3641 status = verify_attr_len(xdr, savep, attrlen);
3642xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003643 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 return status;
3645}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003646
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3648{
Al Viro8687b632006-10-19 23:28:48 -07003649 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003650 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003652
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3654 goto xdr_error;
3655 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3656 goto xdr_error;
3657 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3658 goto xdr_error;
3659
3660 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3661 goto xdr_error;
3662 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3663 goto xdr_error;
3664 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3665 goto xdr_error;
3666 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3667 goto xdr_error;
3668 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3669 goto xdr_error;
3670 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3671 goto xdr_error;
3672
3673 status = verify_attr_len(xdr, savep, attrlen);
3674xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003675 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 return status;
3677}
3678
3679static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3680{
Al Viro8687b632006-10-19 23:28:48 -07003681 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003682 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003684
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3686 goto xdr_error;
3687 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3688 goto xdr_error;
3689 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3690 goto xdr_error;
3691
3692 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3693 goto xdr_error;
3694 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3695 goto xdr_error;
3696
3697 status = verify_attr_len(xdr, savep, attrlen);
3698xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003699 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 return status;
3701}
3702
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003703static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3704 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705{
Al Viro8687b632006-10-19 23:28:48 -07003706 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 uint32_t attrlen,
3708 bitmap[2] = {0},
3709 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003710 int status;
3711 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003712 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003714 status = decode_op_hdr(xdr, OP_GETATTR);
3715 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 goto xdr_error;
3717
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003718 status = decode_attr_bitmap(xdr, bitmap);
3719 if (status < 0)
3720 goto xdr_error;
3721
3722 status = decode_attr_length(xdr, &attrlen, &savep);
3723 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 goto xdr_error;
3725
3726
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003727 status = decode_attr_type(xdr, bitmap, &type);
3728 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003730 fattr->mode = 0;
3731 if (status != 0) {
3732 fattr->mode |= nfs_type2fmt[type];
3733 fattr->valid |= status;
3734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003736 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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_size(xdr, bitmap, &fattr->size);
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_fsid(xdr, bitmap, &fattr->fsid);
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_fileid(xdr, bitmap, &fattr->fileid);
3752 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003754 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003755
3756 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003757 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003758 fattr));
3759 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003760 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003761 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003762
3763 status = decode_attr_mode(xdr, bitmap, &fmode);
3764 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003766 if (status != 0) {
3767 fattr->mode |= fmode;
3768 fattr->valid |= status;
3769 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003770
3771 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3772 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003775
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003776 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3777 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003778 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003780 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003781
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003782 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3783 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003784 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003786 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003787
3788 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3789 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003792
3793 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3794 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003796 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003797
3798 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3799 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003801 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003802
3803 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3804 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003806 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003807
3808 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3809 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003811 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003812
3813 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3814 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003815 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003816 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003817 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 fattr->valid |= status;
3819 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003820
3821 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003823 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 return status;
3825}
3826
3827
3828static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3829{
Al Viro8687b632006-10-19 23:28:48 -07003830 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 uint32_t attrlen, bitmap[2];
3832 int status;
3833
3834 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3835 goto xdr_error;
3836 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3837 goto xdr_error;
3838 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3839 goto xdr_error;
3840
3841 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3842
3843 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3844 goto xdr_error;
3845 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3846 goto xdr_error;
3847 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3848 goto xdr_error;
3849 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3850 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3851 goto xdr_error;
3852 fsinfo->wtpref = fsinfo->wtmax;
3853
3854 status = verify_attr_len(xdr, savep, attrlen);
3855xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003856 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 return status;
3858}
3859
3860static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3861{
Al Viro8687b632006-10-19 23:28:48 -07003862 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 uint32_t len;
3864 int status;
3865
Trond Myklebust99367812007-07-17 21:52:41 -04003866 /* Zero handle first to allow comparisons */
3867 memset(fh, 0, sizeof(*fh));
3868
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 status = decode_op_hdr(xdr, OP_GETFH);
3870 if (status)
3871 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872
Benny Halevyc0eae662009-08-14 17:20:14 +03003873 p = xdr_inline_decode(xdr, 4);
3874 if (unlikely(!p))
3875 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003876 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 if (len > NFS4_FHSIZE)
3878 return -EIO;
3879 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03003880 p = xdr_inline_decode(xdr, len);
3881 if (unlikely(!p))
3882 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03003883 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003885out_overflow:
3886 print_overflow_msg(__func__, xdr);
3887 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888}
3889
3890static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3891{
3892 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003893
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 status = decode_op_hdr(xdr, OP_LINK);
3895 if (status)
3896 return status;
3897 return decode_change_info(xdr, cinfo);
3898}
3899
3900/*
3901 * We create the owner, so we know a proper owner.id length is 4.
3902 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003903static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003905 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003906 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003907 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
Benny Halevyc0eae662009-08-14 17:20:14 +03003909 p = xdr_inline_decode(xdr, 32);
3910 if (unlikely(!p))
3911 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003912 p = xdr_decode_hyper(p, &offset);
3913 p = xdr_decode_hyper(p, &length);
Benny Halevy6f723f72009-08-14 17:19:37 +03003914 type = be32_to_cpup(p++);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003915 if (fl != NULL) {
3916 fl->fl_start = (loff_t)offset;
3917 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3918 if (length == ~(uint64_t)0)
3919 fl->fl_end = OFFSET_MAX;
3920 fl->fl_type = F_WRLCK;
3921 if (type & 1)
3922 fl->fl_type = F_RDLCK;
3923 fl->fl_pid = 0;
3924 }
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003925 p = xdr_decode_hyper(p, &clientid);
Benny Halevycccddf42009-08-14 17:20:19 +03003926 namelen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003927 p = xdr_inline_decode(xdr, namelen);
3928 if (likely(p))
3929 return -NFS4ERR_DENIED;
3930out_overflow:
3931 print_overflow_msg(__func__, xdr);
3932 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933}
3934
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003935static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 int status;
3938
3939 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003940 if (status == -EIO)
3941 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03003943 status = decode_stateid(xdr, &res->stateid);
3944 if (unlikely(status))
3945 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003947 status = decode_lock_denied(xdr, NULL);
3948 if (res->open_seqid != NULL)
3949 nfs_increment_open_seqid(status, res->open_seqid);
3950 nfs_increment_lock_seqid(status, res->lock_seqid);
3951out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 return status;
3953}
3954
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003955static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956{
3957 int status;
3958 status = decode_op_hdr(xdr, OP_LOCKT);
3959 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003960 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 return status;
3962}
3963
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003964static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 int status;
3967
3968 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003969 if (status != -EIO)
3970 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003971 if (status == 0)
3972 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 return status;
3974}
3975
3976static int decode_lookup(struct xdr_stream *xdr)
3977{
3978 return decode_op_hdr(xdr, OP_LOOKUP);
3979}
3980
3981/* This is too sick! */
3982static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3983{
Andy Adamson05d564f2008-12-23 16:06:15 -05003984 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 uint32_t limit_type, nblocks, blocksize;
3986
Benny Halevyc0eae662009-08-14 17:20:14 +03003987 p = xdr_inline_decode(xdr, 12);
3988 if (unlikely(!p))
3989 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003990 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003992 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03003993 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05003994 break;
3995 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03003996 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003997 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003998 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 }
4000 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004001out_overflow:
4002 print_overflow_msg(__func__, xdr);
4003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004}
4005
4006static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4007{
Andy Adamson05d564f2008-12-23 16:06:15 -05004008 __be32 *p;
4009 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004010 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011
Benny Halevyc0eae662009-08-14 17:20:14 +03004012 p = xdr_inline_decode(xdr, 4);
4013 if (unlikely(!p))
4014 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004015 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4017 res->delegation_type = 0;
4018 return 0;
4019 }
Benny Halevy07d30432009-08-14 17:19:52 +03004020 status = decode_stateid(xdr, &res->delegation);
4021 if (unlikely(status))
4022 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004023 p = xdr_inline_decode(xdr, 4);
4024 if (unlikely(!p))
4025 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004026 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004027
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004029 case NFS4_OPEN_DELEGATE_READ:
4030 res->delegation_type = FMODE_READ;
4031 break;
4032 case NFS4_OPEN_DELEGATE_WRITE:
4033 res->delegation_type = FMODE_WRITE|FMODE_READ;
4034 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 return -EIO;
4036 }
David Howells7539bba2006-08-22 20:06:09 -04004037 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004038out_overflow:
4039 print_overflow_msg(__func__, xdr);
4040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041}
4042
4043static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4044{
Andy Adamson05d564f2008-12-23 16:06:15 -05004045 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004046 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004047 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048
Andy Adamson05d564f2008-12-23 16:06:15 -05004049 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004050 if (status != -EIO)
4051 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004052 if (!status)
4053 status = decode_stateid(xdr, &res->stateid);
4054 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004055 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056
Andy Adamson05d564f2008-12-23 16:06:15 -05004057 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058
Benny Halevyc0eae662009-08-14 17:20:14 +03004059 p = xdr_inline_decode(xdr, 8);
4060 if (unlikely(!p))
4061 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004062 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004063 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004064 if (bmlen > 10)
4065 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Benny Halevyc0eae662009-08-14 17:20:14 +03004067 p = xdr_inline_decode(xdr, bmlen << 2);
4068 if (unlikely(!p))
4069 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004070 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4071 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004072 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004073 for (; i < NFS4_BITMAP_SIZE; i++)
4074 res->attrset[i] = 0;
4075
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 return decode_delegation(xdr, res);
4077xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004078 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004080out_overflow:
4081 print_overflow_msg(__func__, xdr);
4082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083}
4084
4085static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 int status;
4088
Andy Adamson05d564f2008-12-23 16:06:15 -05004089 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004090 if (status != -EIO)
4091 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004092 if (!status)
4093 status = decode_stateid(xdr, &res->stateid);
4094 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095}
4096
4097static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 int status;
4100
4101 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004102 if (status != -EIO)
4103 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004104 if (!status)
4105 status = decode_stateid(xdr, &res->stateid);
4106 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107}
4108
4109static int decode_putfh(struct xdr_stream *xdr)
4110{
4111 return decode_op_hdr(xdr, OP_PUTFH);
4112}
4113
4114static int decode_putrootfh(struct xdr_stream *xdr)
4115{
4116 return decode_op_hdr(xdr, OP_PUTROOTFH);
4117}
4118
4119static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4120{
4121 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 uint32_t count, eof, recvd, hdrlen;
4124 int status;
4125
4126 status = decode_op_hdr(xdr, OP_READ);
4127 if (status)
4128 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004129 p = xdr_inline_decode(xdr, 8);
4130 if (unlikely(!p))
4131 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004132 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004133 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4135 recvd = req->rq_rcv_buf.len - hdrlen;
4136 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004137 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 "count %u > recvd %u\n", count, recvd);
4139 count = recvd;
4140 eof = 0;
4141 }
4142 xdr_read_pages(xdr, count);
4143 res->eof = eof;
4144 res->count = count;
4145 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004146out_overflow:
4147 print_overflow_msg(__func__, xdr);
4148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149}
4150
4151static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4152{
4153 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4154 struct page *page = *rcvbuf->pages;
4155 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004156 size_t hdrlen;
4157 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07004158 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004159 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04004160 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161
4162 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004163 if (!status)
4164 status = decode_verifier(xdr, readdir->verifier.data);
4165 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004167 dprintk("%s: verifier = %08x:%08x\n",
4168 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004169 ((u32 *)readdir->verifier.data)[0],
4170 ((u32 *)readdir->verifier.data)[1]);
4171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172
Benny Halevydb942bb2009-08-14 17:19:56 +03004173 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 recvd = rcvbuf->len - hdrlen;
4175 if (pglen > recvd)
4176 pglen = recvd;
4177 xdr_read_pages(xdr, pglen);
4178
4179 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07004180 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04004181 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004183
4184 /* Make sure the packet actually has a value_follows and EOF entry */
4185 if ((entry + 1) > end)
4186 goto short_pkt;
4187
4188 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004189 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04004190 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004192 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 p += 2; /* cookie */
4194 len = ntohl(*p++); /* filename length */
4195 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004196 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4197 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 goto err_unmap;
4199 }
David Howellse8896492006-08-24 15:44:19 -04004200 xlen = XDR_QUADLEN(len);
4201 if (end - p < xlen + 1)
4202 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004203 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04004204 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04004206 if (end - p < len + 1)
4207 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04004210 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04004212 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 entry = p;
4214 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004215 /*
4216 * Apparently some server sends responses that are a valid size, but
4217 * contain no entries, and have value_follows==0 and EOF==0. For
4218 * those, just set the EOF marker.
4219 */
4220 if (!nr && entry[1] == 0) {
4221 dprintk("NFS: readdir reply truncated!\n");
4222 entry[1] = 1;
4223 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05004224out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 kunmap_atomic(kaddr, KM_USER0);
4226 return 0;
4227short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004228 /*
4229 * When we get a short packet there are 2 possibilities. We can
4230 * return an error, or fix up the response to look like a valid
4231 * response and return what we have so far. If there are no
4232 * entries and the packet was short, then return -EIO. If there
4233 * are valid entries in the response, return them and pretend that
4234 * the call was successful, but incomplete. The caller can retry the
4235 * readdir starting at the last cookie.
4236 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07004237 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004239 if (nr)
4240 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241err_unmap:
4242 kunmap_atomic(kaddr, KM_USER0);
4243 return -errno_NFSERR_IO;
4244}
4245
4246static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4247{
4248 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4249 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004250 size_t hdrlen;
4251 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004252 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 char *kaddr;
4254 int status;
4255
4256 status = decode_op_hdr(xdr, OP_READLINK);
4257 if (status)
4258 return status;
4259
4260 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004261 p = xdr_inline_decode(xdr, 4);
4262 if (unlikely(!p))
4263 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004264 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004266 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 return -ENAMETOOLONG;
4268 }
4269 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4270 recvd = req->rq_rcv_buf.len - hdrlen;
4271 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004272 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 "count %u > recvd %u\n", len, recvd);
4274 return -EIO;
4275 }
4276 xdr_read_pages(xdr, len);
4277 /*
4278 * The XDR encode routine has set things up so that
4279 * the link text will be copied directly into the
4280 * buffer. We just have to do overflow-checking,
4281 * and and null-terminate the text (the VFS expects
4282 * null-termination).
4283 */
4284 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4285 kaddr[len+rcvbuf->page_base] = '\0';
4286 kunmap_atomic(kaddr, KM_USER0);
4287 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004288out_overflow:
4289 print_overflow_msg(__func__, xdr);
4290 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291}
4292
4293static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4294{
4295 int status;
4296
4297 status = decode_op_hdr(xdr, OP_REMOVE);
4298 if (status)
4299 goto out;
4300 status = decode_change_info(xdr, cinfo);
4301out:
4302 return status;
4303}
4304
4305static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4306 struct nfs4_change_info *new_cinfo)
4307{
4308 int status;
4309
4310 status = decode_op_hdr(xdr, OP_RENAME);
4311 if (status)
4312 goto out;
4313 if ((status = decode_change_info(xdr, old_cinfo)))
4314 goto out;
4315 status = decode_change_info(xdr, new_cinfo);
4316out:
4317 return status;
4318}
4319
4320static int decode_renew(struct xdr_stream *xdr)
4321{
4322 return decode_op_hdr(xdr, OP_RENEW);
4323}
4324
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004325static int
4326decode_restorefh(struct xdr_stream *xdr)
4327{
4328 return decode_op_hdr(xdr, OP_RESTOREFH);
4329}
4330
J. Bruce Fields029d1052005-06-22 17:16:22 +00004331static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4332 size_t *acl_len)
4333{
Al Viro8687b632006-10-19 23:28:48 -07004334 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004335 uint32_t attrlen,
4336 bitmap[2] = {0};
4337 struct kvec *iov = req->rq_rcv_buf.head;
4338 int status;
4339
4340 *acl_len = 0;
4341 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4342 goto out;
4343 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4344 goto out;
4345 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4346 goto out;
4347
4348 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4349 return -EIO;
4350 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004351 size_t hdrlen;
4352 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004353
4354 /* We ignore &savep and don't do consistency checks on
4355 * the attr length. Let userspace figure it out.... */
4356 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4357 recvd = req->rq_rcv_buf.len - hdrlen;
4358 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004359 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004360 " acl reply: attrlen %u > recvd %u\n",
4361 attrlen, recvd);
4362 return -EINVAL;
4363 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004364 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004365 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004366 } else
4367 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004368
4369out:
4370 return status;
4371}
4372
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373static int
4374decode_savefh(struct xdr_stream *xdr)
4375{
4376 return decode_op_hdr(xdr, OP_SAVEFH);
4377}
4378
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004379static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380{
Al Viro8687b632006-10-19 23:28:48 -07004381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 uint32_t bmlen;
4383 int status;
4384
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 status = decode_op_hdr(xdr, OP_SETATTR);
4386 if (status)
4387 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004388 p = xdr_inline_decode(xdr, 4);
4389 if (unlikely(!p))
4390 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004391 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004392 p = xdr_inline_decode(xdr, bmlen << 2);
4393 if (likely(p))
4394 return 0;
4395out_overflow:
4396 print_overflow_msg(__func__, xdr);
4397 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398}
4399
David Howellsadfa6f92006-08-22 20:06:08 -04004400static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401{
Al Viro8687b632006-10-19 23:28:48 -07004402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 uint32_t opnum;
4404 int32_t nfserr;
4405
Benny Halevyc0eae662009-08-14 17:20:14 +03004406 p = xdr_inline_decode(xdr, 8);
4407 if (unlikely(!p))
4408 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004409 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004411 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004412 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 return -EIO;
4414 }
Benny Halevycccddf42009-08-14 17:20:19 +03004415 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004417 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4418 if (unlikely(!p))
4419 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004420 p = xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevy99398d02009-08-14 17:20:05 +03004421 memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 } else if (nfserr == NFSERR_CLID_INUSE) {
4423 uint32_t len;
4424
4425 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004426 p = xdr_inline_decode(xdr, 4);
4427 if (unlikely(!p))
4428 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004429 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004430 p = xdr_inline_decode(xdr, len);
4431 if (unlikely(!p))
4432 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433
4434 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004435 p = xdr_inline_decode(xdr, 4);
4436 if (unlikely(!p))
4437 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004438 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004439 p = xdr_inline_decode(xdr, len);
4440 if (unlikely(!p))
4441 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 return -NFSERR_CLID_INUSE;
4443 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004444 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445
4446 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004447out_overflow:
4448 print_overflow_msg(__func__, xdr);
4449 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450}
4451
4452static int decode_setclientid_confirm(struct xdr_stream *xdr)
4453{
4454 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4455}
4456
4457static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4458{
Al Viro8687b632006-10-19 23:28:48 -07004459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 int status;
4461
4462 status = decode_op_hdr(xdr, OP_WRITE);
4463 if (status)
4464 return status;
4465
Benny Halevyc0eae662009-08-14 17:20:14 +03004466 p = xdr_inline_decode(xdr, 16);
4467 if (unlikely(!p))
4468 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004469 res->count = be32_to_cpup(p++);
4470 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004471 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004473out_overflow:
4474 print_overflow_msg(__func__, xdr);
4475 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476}
4477
4478static int decode_delegreturn(struct xdr_stream *xdr)
4479{
4480 return decode_op_hdr(xdr, OP_DELEGRETURN);
4481}
4482
Benny Halevy99fe60d2009-04-01 09:22:29 -04004483#if defined(CONFIG_NFS_V4_1)
4484static int decode_exchange_id(struct xdr_stream *xdr,
4485 struct nfs41_exchange_id_res *res)
4486{
4487 __be32 *p;
4488 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004489 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004490 int status;
4491 struct nfs_client *clp = res->client;
4492
4493 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4494 if (status)
4495 return status;
4496
Benny Halevyc0eae662009-08-14 17:20:14 +03004497 p = xdr_inline_decode(xdr, 8);
4498 if (unlikely(!p))
4499 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004500 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004501 p = xdr_inline_decode(xdr, 12);
4502 if (unlikely(!p))
4503 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004504 clp->cl_seqid = be32_to_cpup(p++);
4505 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004506
4507 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004508 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004509 if (dummy != SP4_NONE)
4510 return -EIO;
4511
4512 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004513 p = xdr_inline_decode(xdr, 8);
4514 if (unlikely(!p))
4515 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004516
4517 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004518 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4519 if (unlikely(status))
4520 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004521
4522 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004523 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4524 if (unlikely(status))
4525 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004526
4527 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004528 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4529 if (unlikely(status))
4530 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004531
4532 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004533out_overflow:
4534 print_overflow_msg(__func__, xdr);
4535 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004536}
Andy Adamsonfc931582009-04-01 09:22:31 -04004537
4538static int decode_chan_attrs(struct xdr_stream *xdr,
4539 struct nfs4_channel_attrs *attrs)
4540{
4541 __be32 *p;
4542 u32 nr_attrs;
4543
Benny Halevyc0eae662009-08-14 17:20:14 +03004544 p = xdr_inline_decode(xdr, 28);
4545 if (unlikely(!p))
4546 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004547 attrs->headerpadsz = be32_to_cpup(p++);
4548 attrs->max_rqst_sz = be32_to_cpup(p++);
4549 attrs->max_resp_sz = be32_to_cpup(p++);
4550 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4551 attrs->max_ops = be32_to_cpup(p++);
4552 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004553 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004554 if (unlikely(nr_attrs > 1)) {
4555 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4556 __func__, nr_attrs);
4557 return -EINVAL;
4558 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004559 if (nr_attrs == 1) {
4560 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4561 if (unlikely(!p))
4562 goto out_overflow;
4563 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004564 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004565out_overflow:
4566 print_overflow_msg(__func__, xdr);
4567 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004568}
4569
Benny Halevye78291e2009-08-14 17:20:00 +03004570static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4571{
4572 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004573}
4574
4575static int decode_create_session(struct xdr_stream *xdr,
4576 struct nfs41_create_session_res *res)
4577{
4578 __be32 *p;
4579 int status;
4580 struct nfs_client *clp = res->client;
4581 struct nfs4_session *session = clp->cl_session;
4582
4583 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004584 if (!status)
4585 status = decode_sessionid(xdr, &session->sess_id);
4586 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004587 return status;
4588
Andy Adamsonfc931582009-04-01 09:22:31 -04004589 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004590 p = xdr_inline_decode(xdr, 8);
4591 if (unlikely(!p))
4592 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004593 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004594 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004595
4596 /* Channel attributes */
4597 status = decode_chan_attrs(xdr, &session->fc_attrs);
4598 if (!status)
4599 status = decode_chan_attrs(xdr, &session->bc_attrs);
4600 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004601out_overflow:
4602 print_overflow_msg(__func__, xdr);
4603 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004604}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004605
4606static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4607{
4608 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4609}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004610
4611static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4612{
4613 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4614}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004615#endif /* CONFIG_NFS_V4_1 */
4616
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004617static int decode_sequence(struct xdr_stream *xdr,
4618 struct nfs4_sequence_res *res,
4619 struct rpc_rqst *rqstp)
4620{
4621#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004622 struct nfs4_slot *slot;
4623 struct nfs4_sessionid id;
4624 u32 dummy;
4625 int status;
4626 __be32 *p;
4627
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004628 if (!res->sr_session)
4629 return 0;
4630
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004631 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004632 if (!status)
4633 status = decode_sessionid(xdr, &id);
4634 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004635 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004636
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004637 /*
4638 * If the server returns different values for sessionID, slotID or
4639 * sequence number, the server is looney tunes.
4640 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004641 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004642
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004643 if (memcmp(id.data, res->sr_session->sess_id.data,
4644 NFS4_MAX_SESSIONID_LEN)) {
4645 dprintk("%s Invalid session id\n", __func__);
4646 goto out_err;
4647 }
Benny Halevye78291e2009-08-14 17:20:00 +03004648
Benny Halevyc0eae662009-08-14 17:20:14 +03004649 p = xdr_inline_decode(xdr, 20);
4650 if (unlikely(!p))
4651 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004652
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004653 /* seqid */
Benny Halevye78291e2009-08-14 17:20:00 +03004654 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
Benny Halevy6f723f72009-08-14 17:19:37 +03004655 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004656 if (dummy != slot->seq_nr) {
4657 dprintk("%s Invalid sequence number\n", __func__);
4658 goto out_err;
4659 }
4660 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004661 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004662 if (dummy != res->sr_slotid) {
4663 dprintk("%s Invalid slot id\n", __func__);
4664 goto out_err;
4665 }
4666 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004667 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004668 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004669 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004670 /* result flags */
4671 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004672 status = 0;
4673out_err:
4674 res->sr_status = status;
4675 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004676out_overflow:
4677 print_overflow_msg(__func__, xdr);
4678 status = -EIO;
4679 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004680#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004681 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004682#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004683}
4684
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685/*
Benny Halevy49c25592008-12-23 16:06:16 -05004686 * END OF "GENERIC" DECODE ROUTINES.
4687 */
4688
4689/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690 * Decode OPEN_DOWNGRADE response
4691 */
Al Viro8687b632006-10-19 23:28:48 -07004692static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693{
Andy Adamson05d564f2008-12-23 16:06:15 -05004694 struct xdr_stream xdr;
4695 struct compound_hdr hdr;
4696 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697
Andy Adamson05d564f2008-12-23 16:06:15 -05004698 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4699 status = decode_compound_hdr(&xdr, &hdr);
4700 if (status)
4701 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004702 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4703 if (status)
4704 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004705 status = decode_putfh(&xdr);
4706 if (status)
4707 goto out;
4708 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004709 if (status != 0)
4710 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004711 decode_getfattr(&xdr, res->fattr, res->server,
4712 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004714 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715}
4716
4717/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 * Decode ACCESS response
4719 */
Al Viro8687b632006-10-19 23:28:48 -07004720static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721{
4722 struct xdr_stream xdr;
4723 struct compound_hdr hdr;
4724 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004725
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004727 status = decode_compound_hdr(&xdr, &hdr);
4728 if (status)
4729 goto out;
4730 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4731 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004733 status = decode_putfh(&xdr);
4734 if (status != 0)
4735 goto out;
4736 status = decode_access(&xdr, res);
4737 if (status != 0)
4738 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004739 decode_getfattr(&xdr, res->fattr, res->server,
4740 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741out:
4742 return status;
4743}
4744
4745/*
4746 * Decode LOOKUP response
4747 */
Al Viro8687b632006-10-19 23:28:48 -07004748static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749{
4750 struct xdr_stream xdr;
4751 struct compound_hdr hdr;
4752 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004753
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004755 status = decode_compound_hdr(&xdr, &hdr);
4756 if (status)
4757 goto out;
4758 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4759 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 goto out;
4761 if ((status = decode_putfh(&xdr)) != 0)
4762 goto out;
4763 if ((status = decode_lookup(&xdr)) != 0)
4764 goto out;
4765 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4766 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004767 status = decode_getfattr(&xdr, res->fattr, res->server
4768 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769out:
4770 return status;
4771}
4772
4773/*
4774 * Decode LOOKUP_ROOT response
4775 */
Al Viro8687b632006-10-19 23:28:48 -07004776static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777{
4778 struct xdr_stream xdr;
4779 struct compound_hdr hdr;
4780 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004781
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004783 status = decode_compound_hdr(&xdr, &hdr);
4784 if (status)
4785 goto out;
4786 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4787 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 goto out;
4789 if ((status = decode_putrootfh(&xdr)) != 0)
4790 goto out;
4791 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004792 status = decode_getfattr(&xdr, res->fattr, res->server,
4793 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794out:
4795 return status;
4796}
4797
4798/*
4799 * Decode REMOVE response
4800 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004801static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802{
4803 struct xdr_stream xdr;
4804 struct compound_hdr hdr;
4805 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004806
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004808 status = decode_compound_hdr(&xdr, &hdr);
4809 if (status)
4810 goto out;
4811 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4812 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004814 if ((status = decode_putfh(&xdr)) != 0)
4815 goto out;
4816 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4817 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004818 decode_getfattr(&xdr, &res->dir_attr, res->server,
4819 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820out:
4821 return status;
4822}
4823
4824/*
4825 * Decode RENAME response
4826 */
Al Viro8687b632006-10-19 23:28:48 -07004827static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828{
4829 struct xdr_stream xdr;
4830 struct compound_hdr hdr;
4831 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004832
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004834 status = decode_compound_hdr(&xdr, &hdr);
4835 if (status)
4836 goto out;
4837 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4838 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839 goto out;
4840 if ((status = decode_putfh(&xdr)) != 0)
4841 goto out;
4842 if ((status = decode_savefh(&xdr)) != 0)
4843 goto out;
4844 if ((status = decode_putfh(&xdr)) != 0)
4845 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004846 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4847 goto out;
4848 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004849 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4850 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004851 goto out;
4852 if ((status = decode_restorefh(&xdr)) != 0)
4853 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004854 decode_getfattr(&xdr, res->old_fattr, res->server,
4855 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856out:
4857 return status;
4858}
4859
4860/*
4861 * Decode LINK response
4862 */
Al Viro8687b632006-10-19 23:28:48 -07004863static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864{
4865 struct xdr_stream xdr;
4866 struct compound_hdr hdr;
4867 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004868
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004870 status = decode_compound_hdr(&xdr, &hdr);
4871 if (status)
4872 goto out;
4873 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4874 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 goto out;
4876 if ((status = decode_putfh(&xdr)) != 0)
4877 goto out;
4878 if ((status = decode_savefh(&xdr)) != 0)
4879 goto out;
4880 if ((status = decode_putfh(&xdr)) != 0)
4881 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004882 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4883 goto out;
4884 /*
4885 * Note order: OP_LINK leaves the directory as the current
4886 * filehandle.
4887 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004888 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4889 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004890 goto out;
4891 if ((status = decode_restorefh(&xdr)) != 0)
4892 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004893 decode_getfattr(&xdr, res->fattr, res->server,
4894 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895out:
4896 return status;
4897}
4898
4899/*
4900 * Decode CREATE response
4901 */
Al Viro8687b632006-10-19 23:28:48 -07004902static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903{
4904 struct xdr_stream xdr;
4905 struct compound_hdr hdr;
4906 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004907
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004909 status = decode_compound_hdr(&xdr, &hdr);
4910 if (status)
4911 goto out;
4912 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4913 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 goto out;
4915 if ((status = decode_putfh(&xdr)) != 0)
4916 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004917 if ((status = decode_savefh(&xdr)) != 0)
4918 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4920 goto out;
4921 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4922 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004923 if (decode_getfattr(&xdr, res->fattr, res->server,
4924 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004925 goto out;
4926 if ((status = decode_restorefh(&xdr)) != 0)
4927 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004928 decode_getfattr(&xdr, res->dir_fattr, res->server,
4929 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930out:
4931 return status;
4932}
4933
4934/*
4935 * Decode SYMLINK response
4936 */
Al Viro8687b632006-10-19 23:28:48 -07004937static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938{
4939 return nfs4_xdr_dec_create(rqstp, p, res);
4940}
4941
4942/*
4943 * Decode GETATTR response
4944 */
Al Viro8687b632006-10-19 23:28:48 -07004945static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946{
4947 struct xdr_stream xdr;
4948 struct compound_hdr hdr;
4949 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004950
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4952 status = decode_compound_hdr(&xdr, &hdr);
4953 if (status)
4954 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004955 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4956 if (status)
4957 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 status = decode_putfh(&xdr);
4959 if (status)
4960 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004961 status = decode_getfattr(&xdr, res->fattr, res->server,
4962 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963out:
4964 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965}
4966
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004967/*
4968 * Encode an SETACL request
4969 */
4970static int
Al Viro8687b632006-10-19 23:28:48 -07004971nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004972{
Andy Adamson05d564f2008-12-23 16:06:15 -05004973 struct xdr_stream xdr;
4974 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004975 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004976 };
4977 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004978
Andy Adamson05d564f2008-12-23 16:06:15 -05004979 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004980 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004981 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004982 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004983 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004984 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004985 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004986}
Andy Adamson05d564f2008-12-23 16:06:15 -05004987
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004988/*
4989 * Decode SETACL response
4990 */
4991static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004992nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4993 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004994{
4995 struct xdr_stream xdr;
4996 struct compound_hdr hdr;
4997 int status;
4998
4999 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5000 status = decode_compound_hdr(&xdr, &hdr);
5001 if (status)
5002 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005003 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5004 if (status)
5005 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005006 status = decode_putfh(&xdr);
5007 if (status)
5008 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005009 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005010out:
5011 return status;
5012}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013
5014/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005015 * Decode GETACL response
5016 */
5017static int
Benny Halevy663c79b2009-04-01 09:21:59 -04005018nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
5019 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005020{
5021 struct xdr_stream xdr;
5022 struct compound_hdr hdr;
5023 int status;
5024
5025 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5026 status = decode_compound_hdr(&xdr, &hdr);
5027 if (status)
5028 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005029 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5030 if (status)
5031 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005032 status = decode_putfh(&xdr);
5033 if (status)
5034 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04005035 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005036
5037out:
5038 return status;
5039}
5040
5041/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 * Decode CLOSE response
5043 */
Al Viro8687b632006-10-19 23:28:48 -07005044static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045{
Andy Adamson05d564f2008-12-23 16:06:15 -05005046 struct xdr_stream xdr;
5047 struct compound_hdr hdr;
5048 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049
Andy Adamson05d564f2008-12-23 16:06:15 -05005050 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5051 status = decode_compound_hdr(&xdr, &hdr);
5052 if (status)
5053 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005054 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5055 if (status)
5056 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005057 status = decode_putfh(&xdr);
5058 if (status)
5059 goto out;
5060 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005061 if (status != 0)
5062 goto out;
5063 /*
5064 * Note: Server may do delete on close for this file
5065 * in which case the getattr call will fail with
5066 * an ESTALE error. Shouldn't be a problem,
5067 * though, since fattr->valid will remain unset.
5068 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005069 decode_getfattr(&xdr, res->fattr, res->server,
5070 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005072 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073}
5074
5075/*
5076 * Decode OPEN response
5077 */
Al Viro8687b632006-10-19 23:28:48 -07005078static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079{
Andy Adamson05d564f2008-12-23 16:06:15 -05005080 struct xdr_stream xdr;
5081 struct compound_hdr hdr;
5082 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083
Andy Adamson05d564f2008-12-23 16:06:15 -05005084 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5085 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005086 if (status)
5087 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005088 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5089 if (status)
5090 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005091 status = decode_putfh(&xdr);
5092 if (status)
5093 goto out;
5094 status = decode_savefh(&xdr);
5095 if (status)
5096 goto out;
5097 status = decode_open(&xdr, res);
5098 if (status)
5099 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005100 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005102 if (decode_getfattr(&xdr, res->f_attr, res->server,
5103 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005104 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005105 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005106 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005107 decode_getfattr(&xdr, res->dir_attr, res->server,
5108 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005110 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111}
5112
5113/*
5114 * Decode OPEN_CONFIRM response
5115 */
Al Viro8687b632006-10-19 23:28:48 -07005116static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117{
Andy Adamson05d564f2008-12-23 16:06:15 -05005118 struct xdr_stream xdr;
5119 struct compound_hdr hdr;
5120 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121
Andy Adamson05d564f2008-12-23 16:06:15 -05005122 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5123 status = decode_compound_hdr(&xdr, &hdr);
5124 if (status)
5125 goto out;
5126 status = decode_putfh(&xdr);
5127 if (status)
5128 goto out;
5129 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005131 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132}
5133
5134/*
5135 * Decode OPEN response
5136 */
Al Viro8687b632006-10-19 23:28:48 -07005137static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138{
Andy Adamson05d564f2008-12-23 16:06:15 -05005139 struct xdr_stream xdr;
5140 struct compound_hdr hdr;
5141 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142
Andy Adamson05d564f2008-12-23 16:06:15 -05005143 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5144 status = decode_compound_hdr(&xdr, &hdr);
5145 if (status)
5146 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005147 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5148 if (status)
5149 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005150 status = decode_putfh(&xdr);
5151 if (status)
5152 goto out;
5153 status = decode_open(&xdr, res);
5154 if (status)
5155 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005156 decode_getfattr(&xdr, res->f_attr, res->server,
5157 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005159 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160}
5161
5162/*
5163 * Decode SETATTR response
5164 */
Al Viro8687b632006-10-19 23:28:48 -07005165static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166{
Andy Adamson05d564f2008-12-23 16:06:15 -05005167 struct xdr_stream xdr;
5168 struct compound_hdr hdr;
5169 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170
Andy Adamson05d564f2008-12-23 16:06:15 -05005171 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5172 status = decode_compound_hdr(&xdr, &hdr);
5173 if (status)
5174 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005175 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5176 if (status)
5177 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005178 status = decode_putfh(&xdr);
5179 if (status)
5180 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005181 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005182 if (status)
5183 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005184 decode_getfattr(&xdr, res->fattr, res->server,
5185 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005187 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188}
5189
5190/*
5191 * Decode LOCK response
5192 */
Al Viro8687b632006-10-19 23:28:48 -07005193static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194{
5195 struct xdr_stream xdr;
5196 struct compound_hdr hdr;
5197 int status;
5198
5199 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5200 status = decode_compound_hdr(&xdr, &hdr);
5201 if (status)
5202 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005203 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5204 if (status)
5205 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 status = decode_putfh(&xdr);
5207 if (status)
5208 goto out;
5209 status = decode_lock(&xdr, res);
5210out:
5211 return status;
5212}
5213
5214/*
5215 * Decode LOCKT response
5216 */
Al Viro8687b632006-10-19 23:28:48 -07005217static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218{
5219 struct xdr_stream xdr;
5220 struct compound_hdr hdr;
5221 int status;
5222
5223 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5224 status = decode_compound_hdr(&xdr, &hdr);
5225 if (status)
5226 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005227 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5228 if (status)
5229 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 status = decode_putfh(&xdr);
5231 if (status)
5232 goto out;
5233 status = decode_lockt(&xdr, res);
5234out:
5235 return status;
5236}
5237
5238/*
5239 * Decode LOCKU response
5240 */
Al Viro8687b632006-10-19 23:28:48 -07005241static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242{
5243 struct xdr_stream xdr;
5244 struct compound_hdr hdr;
5245 int status;
5246
5247 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5248 status = decode_compound_hdr(&xdr, &hdr);
5249 if (status)
5250 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005251 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5252 if (status)
5253 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 status = decode_putfh(&xdr);
5255 if (status)
5256 goto out;
5257 status = decode_locku(&xdr, res);
5258out:
5259 return status;
5260}
5261
5262/*
5263 * Decode READLINK response
5264 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005265static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5266 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267{
5268 struct xdr_stream xdr;
5269 struct compound_hdr hdr;
5270 int status;
5271
5272 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5273 status = decode_compound_hdr(&xdr, &hdr);
5274 if (status)
5275 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005276 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5277 if (status)
5278 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 status = decode_putfh(&xdr);
5280 if (status)
5281 goto out;
5282 status = decode_readlink(&xdr, rqstp);
5283out:
5284 return status;
5285}
5286
5287/*
5288 * Decode READDIR response
5289 */
Al Viro8687b632006-10-19 23:28:48 -07005290static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291{
5292 struct xdr_stream xdr;
5293 struct compound_hdr hdr;
5294 int status;
5295
5296 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5297 status = decode_compound_hdr(&xdr, &hdr);
5298 if (status)
5299 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005300 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5301 if (status)
5302 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 status = decode_putfh(&xdr);
5304 if (status)
5305 goto out;
5306 status = decode_readdir(&xdr, rqstp, res);
5307out:
5308 return status;
5309}
5310
5311/*
5312 * Decode Read response
5313 */
Al Viro8687b632006-10-19 23:28:48 -07005314static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315{
5316 struct xdr_stream xdr;
5317 struct compound_hdr hdr;
5318 int status;
5319
5320 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5321 status = decode_compound_hdr(&xdr, &hdr);
5322 if (status)
5323 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005324 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5325 if (status)
5326 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 status = decode_putfh(&xdr);
5328 if (status)
5329 goto out;
5330 status = decode_read(&xdr, rqstp, res);
5331 if (!status)
5332 status = res->count;
5333out:
5334 return status;
5335}
5336
5337/*
5338 * Decode WRITE response
5339 */
Al Viro8687b632006-10-19 23:28:48 -07005340static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341{
5342 struct xdr_stream xdr;
5343 struct compound_hdr hdr;
5344 int status;
5345
5346 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5347 status = decode_compound_hdr(&xdr, &hdr);
5348 if (status)
5349 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005350 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5351 if (status)
5352 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 status = decode_putfh(&xdr);
5354 if (status)
5355 goto out;
5356 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005357 if (status)
5358 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005359 decode_getfattr(&xdr, res->fattr, res->server,
5360 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 if (!status)
5362 status = res->count;
5363out:
5364 return status;
5365}
5366
5367/*
5368 * Decode COMMIT response
5369 */
Al Viro8687b632006-10-19 23:28:48 -07005370static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371{
5372 struct xdr_stream xdr;
5373 struct compound_hdr hdr;
5374 int status;
5375
5376 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5377 status = decode_compound_hdr(&xdr, &hdr);
5378 if (status)
5379 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005380 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5381 if (status)
5382 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 status = decode_putfh(&xdr);
5384 if (status)
5385 goto out;
5386 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005387 if (status)
5388 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005389 decode_getfattr(&xdr, res->fattr, res->server,
5390 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391out:
5392 return status;
5393}
5394
5395/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005396 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005397 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005398static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5399 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400{
5401 struct xdr_stream xdr;
5402 struct compound_hdr hdr;
5403 int status;
5404
5405 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5406 status = decode_compound_hdr(&xdr, &hdr);
5407 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005408 status = decode_sequence(&xdr, &res->seq_res, req);
5409 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410 status = decode_putfh(&xdr);
5411 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005412 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 return status;
5414}
5415
5416/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005417 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005419static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5420 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421{
5422 struct xdr_stream xdr;
5423 struct compound_hdr hdr;
5424 int status;
5425
5426 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5427 status = decode_compound_hdr(&xdr, &hdr);
5428 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005429 status = decode_sequence(&xdr, &res->seq_res, req);
5430 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005431 status = decode_putfh(&xdr);
5432 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005433 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434 return status;
5435}
5436
5437/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005438 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005440static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5441 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442{
5443 struct xdr_stream xdr;
5444 struct compound_hdr hdr;
5445 int status;
5446
5447 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5448 status = decode_compound_hdr(&xdr, &hdr);
5449 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005450 status = decode_sequence(&xdr, &res->seq_res, req);
5451 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452 status = decode_putfh(&xdr);
5453 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005454 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455 return status;
5456}
5457
5458/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005459 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 */
Al Viro8687b632006-10-19 23:28:48 -07005461static 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 -07005462{
5463 struct xdr_stream xdr;
5464 struct compound_hdr hdr;
5465 int status;
5466
5467 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005468 status = decode_compound_hdr(&xdr, &hdr);
5469 if (status)
5470 goto out;
5471 status = decode_sequence(&xdr, &res->seq_res, req);
5472 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005473 goto out;
5474 if ((status = decode_putfh(&xdr)) != 0)
5475 goto out;
5476 status = decode_server_caps(&xdr, res);
5477out:
5478 return status;
5479}
5480
5481/*
5482 * Decode RENEW response
5483 */
Al Viro8687b632006-10-19 23:28:48 -07005484static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485{
5486 struct xdr_stream xdr;
5487 struct compound_hdr hdr;
5488 int status;
5489
5490 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5491 status = decode_compound_hdr(&xdr, &hdr);
5492 if (!status)
5493 status = decode_renew(&xdr);
5494 return status;
5495}
5496
5497/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005498 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499 */
Al Viro8687b632006-10-19 23:28:48 -07005500static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005501 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502{
5503 struct xdr_stream xdr;
5504 struct compound_hdr hdr;
5505 int status;
5506
5507 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5508 status = decode_compound_hdr(&xdr, &hdr);
5509 if (!status)
5510 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005511 return status;
5512}
5513
5514/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005515 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 */
Al Viro8687b632006-10-19 23:28:48 -07005517static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518{
5519 struct xdr_stream xdr;
5520 struct compound_hdr hdr;
5521 int status;
5522
5523 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5524 status = decode_compound_hdr(&xdr, &hdr);
5525 if (!status)
5526 status = decode_setclientid_confirm(&xdr);
5527 if (!status)
5528 status = decode_putrootfh(&xdr);
5529 if (!status)
5530 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005531 return status;
5532}
5533
5534/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005535 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 */
Al Viro8687b632006-10-19 23:28:48 -07005537static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538{
5539 struct xdr_stream xdr;
5540 struct compound_hdr hdr;
5541 int status;
5542
5543 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5544 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005545 if (status)
5546 goto out;
5547 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5548 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005549 goto out;
5550 status = decode_putfh(&xdr);
5551 if (status != 0)
5552 goto out;
5553 status = decode_delegreturn(&xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005554 if (status != 0)
5555 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005556 decode_getfattr(&xdr, res->fattr, res->server,
5557 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005558out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559 return status;
5560}
5561
Trond Myklebust683b57b2006-06-09 09:34:22 -04005562/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005563 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005564 */
Benny Halevy22958462009-04-01 09:22:02 -04005565static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5566 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005567{
5568 struct xdr_stream xdr;
5569 struct compound_hdr hdr;
5570 int status;
5571
5572 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5573 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005574 if (status)
5575 goto out;
5576 status = decode_sequence(&xdr, &res->seq_res, req);
5577 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005578 goto out;
5579 if ((status = decode_putfh(&xdr)) != 0)
5580 goto out;
5581 if ((status = decode_lookup(&xdr)) != 0)
5582 goto out;
5583 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005584 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005585 res->fs_locations->server,
5586 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005587out:
5588 return status;
5589}
5590
Benny Halevy99fe60d2009-04-01 09:22:29 -04005591#if defined(CONFIG_NFS_V4_1)
5592/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005593 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005594 */
5595static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5596 void *res)
5597{
5598 struct xdr_stream xdr;
5599 struct compound_hdr hdr;
5600 int status;
5601
5602 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5603 status = decode_compound_hdr(&xdr, &hdr);
5604 if (!status)
5605 status = decode_exchange_id(&xdr, res);
5606 return status;
5607}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005608
5609/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005610 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005611 */
5612static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5613 struct nfs41_create_session_res *res)
5614{
5615 struct xdr_stream xdr;
5616 struct compound_hdr hdr;
5617 int status;
5618
5619 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5620 status = decode_compound_hdr(&xdr, &hdr);
5621 if (!status)
5622 status = decode_create_session(&xdr, res);
5623 return status;
5624}
5625
5626/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005627 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005628 */
5629static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5630 void *dummy)
5631{
5632 struct xdr_stream xdr;
5633 struct compound_hdr hdr;
5634 int status;
5635
5636 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5637 status = decode_compound_hdr(&xdr, &hdr);
5638 if (!status)
5639 status = decode_destroy_session(&xdr, dummy);
5640 return status;
5641}
5642
5643/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005644 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005645 */
5646static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5647 struct nfs4_sequence_res *res)
5648{
5649 struct xdr_stream xdr;
5650 struct compound_hdr hdr;
5651 int status;
5652
5653 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5654 status = decode_compound_hdr(&xdr, &hdr);
5655 if (!status)
5656 status = decode_sequence(&xdr, res, rqstp);
5657 return status;
5658}
5659
5660/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005661 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005662 */
5663static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5664 struct nfs4_get_lease_time_res *res)
5665{
5666 struct xdr_stream xdr;
5667 struct compound_hdr hdr;
5668 int status;
5669
5670 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5671 status = decode_compound_hdr(&xdr, &hdr);
5672 if (!status)
5673 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5674 if (!status)
5675 status = decode_putrootfh(&xdr);
5676 if (!status)
5677 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5678 return status;
5679}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005680
5681/*
5682 * Decode RECLAIM_COMPLETE response
5683 */
5684static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p,
5685 struct nfs41_reclaim_complete_res *res)
5686{
5687 struct xdr_stream xdr;
5688 struct compound_hdr hdr;
5689 int status;
5690
5691 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5692 status = decode_compound_hdr(&xdr, &hdr);
5693 if (!status)
5694 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5695 if (!status)
5696 status = decode_reclaim_complete(&xdr, (void *)NULL);
5697 return status;
5698}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005699#endif /* CONFIG_NFS_V4_1 */
5700
Al Viro0dbb4c62006-10-19 23:28:49 -07005701__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702{
5703 uint32_t bitmap[2] = {0};
5704 uint32_t len;
5705
5706 if (!*p++) {
5707 if (!*p)
5708 return ERR_PTR(-EAGAIN);
5709 entry->eof = 1;
5710 return ERR_PTR(-EBADCOOKIE);
5711 }
5712
5713 entry->prev_cookie = entry->cookie;
5714 p = xdr_decode_hyper(p, &entry->cookie);
5715 entry->len = ntohl(*p++);
5716 entry->name = (const char *) p;
5717 p += XDR_QUADLEN(entry->len);
5718
5719 /*
5720 * In case the server doesn't return an inode number,
5721 * we fake one here. (We don't use inode number 0,
5722 * since glibc seems to choke on it...)
5723 */
5724 entry->ino = 1;
5725
5726 len = ntohl(*p++); /* bitmap length */
5727 if (len-- > 0) {
5728 bitmap[0] = ntohl(*p++);
5729 if (len-- > 0) {
5730 bitmap[1] = ntohl(*p++);
5731 p += len;
5732 }
5733 }
5734 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5735 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005736 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5737 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5738 /* Ignore the return value of rdattr_error for now */
5739 p++;
5740 len--;
5741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5743 xdr_decode_hyper(p, &entry->ino);
5744 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5745 xdr_decode_hyper(p, &entry->ino);
5746 p += len;
5747 }
5748
5749 entry->eof = !p[0] && p[1];
5750 return p;
5751}
5752
5753/*
5754 * We need to translate between nfs status return values and
5755 * the local errno values which may not be the same.
5756 */
5757static struct {
5758 int stat;
5759 int errno;
5760} nfs_errtbl[] = {
5761 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005762 { NFS4ERR_PERM, -EPERM },
5763 { NFS4ERR_NOENT, -ENOENT },
5764 { NFS4ERR_IO, -errno_NFSERR_IO},
5765 { NFS4ERR_NXIO, -ENXIO },
5766 { NFS4ERR_ACCESS, -EACCES },
5767 { NFS4ERR_EXIST, -EEXIST },
5768 { NFS4ERR_XDEV, -EXDEV },
5769 { NFS4ERR_NOTDIR, -ENOTDIR },
5770 { NFS4ERR_ISDIR, -EISDIR },
5771 { NFS4ERR_INVAL, -EINVAL },
5772 { NFS4ERR_FBIG, -EFBIG },
5773 { NFS4ERR_NOSPC, -ENOSPC },
5774 { NFS4ERR_ROFS, -EROFS },
5775 { NFS4ERR_MLINK, -EMLINK },
5776 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5777 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5778 { NFS4ERR_DQUOT, -EDQUOT },
5779 { NFS4ERR_STALE, -ESTALE },
5780 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5781 { NFS4ERR_BADOWNER, -EINVAL },
5782 { NFS4ERR_BADNAME, -EINVAL },
5783 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5784 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5785 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005786 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03005787 { NFS4ERR_BADTYPE, -EBADTYPE },
5788 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005789 { NFS4ERR_SYMLINK, -ELOOP },
5790 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5791 { NFS4ERR_DEADLOCK, -EDEADLK },
5792 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 * to be handled by a
5794 * middle-layer.
5795 */
Benny Halevy856dff32008-03-31 17:39:06 +03005796 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797};
5798
5799/*
5800 * Convert an NFS error code to a local one.
5801 * This one is used jointly by NFSv2 and NFSv3.
5802 */
5803static int
David Howells0a8ea432006-08-22 20:06:08 -04005804nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805{
5806 int i;
5807 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5808 if (nfs_errtbl[i].stat == stat)
5809 return nfs_errtbl[i].errno;
5810 }
5811 if (stat <= 10000 || stat > 10100) {
5812 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005813 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814 }
5815 /* If we cannot translate the error, the recovery routines should
5816 * handle it.
5817 * Note: remaining NFSv4 error codes have values > 10000, so should
5818 * not conflict with native Linux error codes.
5819 */
Benny Halevy856dff32008-03-31 17:39:06 +03005820 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821}
5822
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823#define PROC(proc, argtype, restype) \
5824[NFSPROC4_CLNT_##proc] = { \
5825 .p_proc = NFSPROC4_COMPOUND, \
5826 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5827 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005828 .p_arglen = NFS4_##argtype##_sz, \
5829 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005830 .p_statidx = NFSPROC4_CLNT_##proc, \
5831 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005832}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833
5834struct rpc_procinfo nfs4_procedures[] = {
5835 PROC(READ, enc_read, dec_read),
5836 PROC(WRITE, enc_write, dec_write),
5837 PROC(COMMIT, enc_commit, dec_commit),
5838 PROC(OPEN, enc_open, dec_open),
5839 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5840 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5841 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5842 PROC(CLOSE, enc_close, dec_close),
5843 PROC(SETATTR, enc_setattr, dec_setattr),
5844 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5845 PROC(RENEW, enc_renew, dec_renew),
5846 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5847 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5848 PROC(LOCK, enc_lock, dec_lock),
5849 PROC(LOCKT, enc_lockt, dec_lockt),
5850 PROC(LOCKU, enc_locku, dec_locku),
5851 PROC(ACCESS, enc_access, dec_access),
5852 PROC(GETATTR, enc_getattr, dec_getattr),
5853 PROC(LOOKUP, enc_lookup, dec_lookup),
5854 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5855 PROC(REMOVE, enc_remove, dec_remove),
5856 PROC(RENAME, enc_rename, dec_rename),
5857 PROC(LINK, enc_link, dec_link),
5858 PROC(SYMLINK, enc_symlink, dec_symlink),
5859 PROC(CREATE, enc_create, dec_create),
5860 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5861 PROC(STATFS, enc_statfs, dec_statfs),
5862 PROC(READLINK, enc_readlink, dec_readlink),
5863 PROC(READDIR, enc_readdir, dec_readdir),
5864 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5865 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005866 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005867 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005868 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005869#if defined(CONFIG_NFS_V4_1)
5870 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005871 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005872 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005873 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005874 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Ricardo Labiaga180197532009-12-05 16:08:40 -05005875 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005876#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877};
5878
5879struct rpc_version nfs_version4 = {
5880 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005881 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882 .procs = nfs4_procedures
5883};
5884
5885/*
5886 * Local variables:
5887 * c-basic-offset: 8
5888 * End:
5889 */