blob: 3feace66b981d818b8ee5d45376d9a23d4696ca9 [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 Myklebustdaccbde2010-06-25 18:11:43 -0400205#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400206#define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400208 1 + encode_stateid_maxsz + 1 + \
209 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400210#define decode_lock_denied_maxsz \
211 (8 + decode_lockowner_maxsz)
212#define decode_lock_maxsz (op_decode_hdr_maxsz + \
213 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400214#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
215 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400216#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
217 decode_lock_denied_maxsz)
218#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
219 encode_stateid_maxsz + \
220 4)
221#define decode_locku_maxsz (op_decode_hdr_maxsz + \
222 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400223#define encode_release_lockowner_maxsz \
224 (op_encode_hdr_maxsz + \
225 encode_lockowner_maxsz)
226#define decode_release_lockowner_maxsz \
227 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400228#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
229#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
231 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400232 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000233 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
235#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400236 1 + 2 + nfs4_name_maxsz + \
237 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400238#define decode_create_maxsz (op_decode_hdr_maxsz + \
239 decode_change_info_maxsz + \
240 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define encode_statfs_maxsz (encode_getattr_maxsz)
242#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
244#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400245#define encode_getacl_maxsz (encode_getattr_maxsz)
246#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
247 nfs4_fattr_bitmap_maxsz + 1)
248#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
249 encode_stateid_maxsz + 3)
250#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400251#define encode_fs_locations_maxsz \
252 (encode_getattr_maxsz)
253#define decode_fs_locations_maxsz \
254 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400255
256#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400257#define NFS4_MAX_MACHINE_NAME_LEN (64)
258
Benny Halevy99fe60d2009-04-01 09:22:29 -0400259#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
260 encode_verifier_maxsz + \
261 1 /* co_ownerid.len */ + \
262 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
263 1 /* flags */ + \
264 1 /* spa_how */ + \
265 0 /* SP4_NONE (for now) */ + \
266 1 /* zero implemetation id array */)
267#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
268 2 /* eir_clientid */ + \
269 1 /* eir_sequenceid */ + \
270 1 /* eir_flags */ + \
271 1 /* spr_how */ + \
272 0 /* SP4_NONE (for now) */ + \
273 2 /* eir_server_owner.so_minor_id */ + \
274 /* eir_server_owner.so_major_id<> */ \
275 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
276 /* eir_server_scope<> */ \
277 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
278 1 /* eir_server_impl_id array length */ + \
279 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400280#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
281#define decode_channel_attrs_maxsz (6 + \
282 1 /* ca_rdma_ird.len */ + \
283 1 /* ca_rdma_ird */)
284#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
285 2 /* csa_clientid */ + \
286 1 /* csa_sequence */ + \
287 1 /* csa_flags */ + \
288 encode_channel_attrs_maxsz + \
289 encode_channel_attrs_maxsz + \
290 1 /* csa_cb_program */ + \
291 1 /* csa_sec_parms.len (1) */ + \
292 1 /* cb_secflavor (AUTH_SYS) */ + \
293 1 /* stamp */ + \
294 1 /* machinename.len */ + \
295 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
296 1 /* uid */ + \
297 1 /* gid */ + \
298 1 /* gids.len (0) */)
299#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
301 1 /* csr_sequence */ + \
302 1 /* csr_flags */ + \
303 decode_channel_attrs_maxsz + \
304 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400305#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
306#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400307#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
308 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
309#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
310 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500311#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
312#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400313#else /* CONFIG_NFS_V4_1 */
314#define encode_sequence_maxsz 0
315#define decode_sequence_maxsz 0
316#endif /* CONFIG_NFS_V4_1 */
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
319#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
320#define NFS4_enc_read_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_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#define NFS4_dec_read_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_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define NFS4_enc_readlink_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_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_dec_readlink_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_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#define NFS4_enc_readdir_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_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400341 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400343 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400345 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400348 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400353 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400358 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400360 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400362 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400363 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400365 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400366 encode_putfh_maxsz + \
367 encode_savefh_maxsz + \
368 encode_open_maxsz + \
369 encode_getfh_maxsz + \
370 encode_getattr_maxsz + \
371 encode_restorefh_maxsz + \
372 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400375 decode_putfh_maxsz + \
376 decode_savefh_maxsz + \
377 decode_open_maxsz + \
378 decode_getfh_maxsz + \
379 decode_getattr_maxsz + \
380 decode_restorefh_maxsz + \
381 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400382#define NFS4_enc_open_confirm_sz \
383 (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_open_confirm_maxsz)
386#define NFS4_dec_open_confirm_sz \
387 (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400393 encode_open_maxsz + \
394 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400398 decode_open_maxsz + \
399 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_enc_open_downgrade_sz \
401 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400402 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 encode_putfh_maxsz + \
404 encode_open_downgrade_maxsz + \
405 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#define NFS4_dec_open_downgrade_sz \
407 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 decode_putfh_maxsz + \
410 decode_open_downgrade_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_putfh_maxsz + \
415 encode_close_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_putfh_maxsz + \
420 decode_close_maxsz + \
421 decode_getattr_maxsz)
422#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_putfh_maxsz + \
425 encode_setattr_maxsz + \
426 encode_getattr_maxsz)
427#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_putfh_maxsz + \
430 decode_setattr_maxsz + \
431 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400433 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 encode_putfh_maxsz + \
435 encode_fsinfo_maxsz)
436#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
439 decode_fsinfo_maxsz)
440#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
441 encode_renew_maxsz)
442#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
443 decode_renew_maxsz)
444#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
445 encode_setclientid_maxsz)
446#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
447 decode_setclientid_maxsz)
448#define NFS4_enc_setclientid_confirm_sz \
449 (compound_encode_hdr_maxsz + \
450 encode_setclientid_confirm_maxsz + \
451 encode_putrootfh_maxsz + \
452 encode_fsinfo_maxsz)
453#define NFS4_dec_setclientid_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_setclientid_confirm_maxsz + \
456 decode_putrootfh_maxsz + \
457 decode_fsinfo_maxsz)
458#define NFS4_enc_lock_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_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400465 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_enc_lockt_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_lockt_maxsz)
470#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400472 decode_putfh_maxsz + \
473 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_enc_locku_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 Myklebust9104a552007-07-17 21:52:42 -0400477 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400482#define NFS4_enc_release_lockowner_sz \
483 (compound_encode_hdr_maxsz + \
484 encode_lockowner_maxsz)
485#define NFS4_dec_release_lockowner_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400491 encode_access_maxsz + \
492 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400496 decode_access_maxsz + \
497 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 encode_putfh_maxsz + \
501 encode_getattr_maxsz)
502#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 decode_putfh_maxsz + \
505 decode_getattr_maxsz)
506#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 encode_putfh_maxsz + \
509 encode_lookup_maxsz + \
510 encode_getattr_maxsz + \
511 encode_getfh_maxsz)
512#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400515 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 decode_getattr_maxsz + \
517 decode_getfh_maxsz)
518#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 encode_putrootfh_maxsz + \
521 encode_getattr_maxsz + \
522 encode_getfh_maxsz)
523#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 decode_putrootfh_maxsz + \
526 decode_getattr_maxsz + \
527 decode_getfh_maxsz)
528#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400531 encode_remove_maxsz + \
532 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_dec_remove_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 + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400536 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400537 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400539 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 encode_putfh_maxsz + \
541 encode_savefh_maxsz + \
542 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400543 encode_rename_maxsz + \
544 encode_getattr_maxsz + \
545 encode_restorefh_maxsz + \
546 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_putfh_maxsz + \
550 decode_savefh_maxsz + \
551 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400552 decode_rename_maxsz + \
553 decode_getattr_maxsz + \
554 decode_restorefh_maxsz + \
555 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 encode_putfh_maxsz + \
559 encode_savefh_maxsz + \
560 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400561 encode_link_maxsz + \
562 decode_getattr_maxsz + \
563 encode_restorefh_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 decode_putfh_maxsz + \
568 decode_savefh_maxsz + \
569 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400570 decode_link_maxsz + \
571 decode_getattr_maxsz + \
572 decode_restorefh_maxsz + \
573 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400575 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_putfh_maxsz + \
577 encode_symlink_maxsz + \
578 encode_getattr_maxsz + \
579 encode_getfh_maxsz)
580#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 decode_putfh_maxsz + \
583 decode_symlink_maxsz + \
584 decode_getattr_maxsz + \
585 decode_getfh_maxsz)
586#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400589 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400591 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400593 encode_restorefh_maxsz + \
594 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400598 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400600 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400602 decode_restorefh_maxsz + \
603 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_putfh_maxsz + \
607 encode_getattr_maxsz)
608#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_putfh_maxsz + \
611 decode_getattr_maxsz)
612#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400615 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400619 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400621 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800622 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_getattr_maxsz)
624#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800626 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_getattr_maxsz)
628#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100631 encode_delegreturn_maxsz + \
632 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100635 decode_delegreturn_maxsz + \
636 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000637#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000639 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400640 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000641#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000643 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400644 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000645#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000647 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400648 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000649#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000651 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400652 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400653#define NFS4_enc_fs_locations_sz \
654 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400656 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400657 encode_lookup_maxsz + \
658 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400659#define NFS4_dec_fs_locations_sz \
660 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400661 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400662 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400663 decode_lookup_maxsz + \
664 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400665#if defined(CONFIG_NFS_V4_1)
666#define NFS4_enc_exchange_id_sz \
667 (compound_encode_hdr_maxsz + \
668 encode_exchange_id_maxsz)
669#define NFS4_dec_exchange_id_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400672#define NFS4_enc_create_session_sz \
673 (compound_encode_hdr_maxsz + \
674 encode_create_session_maxsz)
675#define NFS4_dec_create_session_sz \
676 (compound_decode_hdr_maxsz + \
677 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400678#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
679 encode_destroy_session_maxsz)
680#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
681 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400682#define NFS4_enc_sequence_sz \
683 (compound_decode_hdr_maxsz + \
684 encode_sequence_maxsz)
685#define NFS4_dec_sequence_sz \
686 (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400688#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
689 encode_sequence_maxsz + \
690 encode_putrootfh_maxsz + \
691 encode_fsinfo_maxsz)
692#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
693 decode_sequence_maxsz + \
694 decode_putrootfh_maxsz + \
695 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500696#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
697 encode_sequence_maxsz + \
698 encode_reclaim_complete_maxsz)
699#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_reclaim_complete_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500702
703const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
704 compound_encode_hdr_maxsz +
705 encode_sequence_maxsz +
706 encode_putfh_maxsz +
707 encode_getattr_maxsz) *
708 XDR_UNIT);
709
710const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
711 compound_decode_hdr_maxsz +
712 decode_sequence_maxsz +
713 decode_putfh_maxsz) *
714 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400715#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Trond Myklebustbca79472009-03-11 14:10:26 -0400717static const umode_t nfs_type2fmt[] = {
718 [NF4BAD] = 0,
719 [NF4REG] = S_IFREG,
720 [NF4DIR] = S_IFDIR,
721 [NF4BLK] = S_IFBLK,
722 [NF4CHR] = S_IFCHR,
723 [NF4LNK] = S_IFLNK,
724 [NF4SOCK] = S_IFSOCK,
725 [NF4FIFO] = S_IFIFO,
726 [NF4ATTRDIR] = 0,
727 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728};
729
730struct compound_hdr {
731 int32_t status;
732 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500733 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 uint32_t taglen;
735 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400736 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400737 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738};
739
Benny Halevy13c65ce2009-08-14 17:19:25 +0300740static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
741{
742 __be32 *p = xdr_reserve_space(xdr, nbytes);
743 BUG_ON(!p);
744 return p;
745}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
748{
Al Viro8687b632006-10-19 23:28:48 -0700749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 p = xdr_reserve_space(xdr, 4 + len);
752 BUG_ON(p == NULL);
753 xdr_encode_opaque(p, str, len);
754}
755
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400756static void encode_compound_hdr(struct xdr_stream *xdr,
757 struct rpc_rqst *req,
758 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Al Viro8687b632006-10-19 23:28:48 -0700760 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400761 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400762
763 /* initialize running count of expected bytes in reply.
764 * NOTE: the replied tag SHOULD be the same is the one sent,
765 * but this is not required as a MUST for the server to do so. */
766 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
769 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300770 p = reserve_space(xdr, 4 + hdr->taglen + 8);
771 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300772 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500773 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300774 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500775}
776
777static void encode_nops(struct compound_hdr *hdr)
778{
Andy Adamsonfc931582009-04-01 09:22:31 -0400779 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500780 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
783static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
784{
Al Viro8687b632006-10-19 23:28:48 -0700785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
788 BUG_ON(p == NULL);
789 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
790}
791
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500792static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
794 char owner_name[IDMAP_NAMESZ];
795 char owner_group[IDMAP_NAMESZ];
796 int owner_namelen = 0;
797 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700798 __be32 *p;
799 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 int len;
801 uint32_t bmval0 = 0;
802 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 /*
805 * We reserve enough space to write the entire attribute buffer at once.
806 * In the worst-case, this would be
807 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
808 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000809 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 */
811 len = 16;
812
813 /* Sigh */
814 if (iap->ia_valid & ATTR_SIZE)
815 len += 8;
816 if (iap->ia_valid & ATTR_MODE)
817 len += 4;
818 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400819 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400821 dprintk("nfs: couldn't resolve uid %d to string\n",
822 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 /* XXX */
824 strcpy(owner_name, "nobody");
825 owner_namelen = sizeof("nobody") - 1;
826 /* goto out; */
827 }
828 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
829 }
830 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400831 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400833 dprintk("nfs: couldn't resolve gid %d to string\n",
834 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 strcpy(owner_group, "nobody");
836 owner_grouplen = sizeof("nobody") - 1;
837 /* goto out; */
838 }
839 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
840 }
841 if (iap->ia_valid & ATTR_ATIME_SET)
842 len += 16;
843 else if (iap->ia_valid & ATTR_ATIME)
844 len += 4;
845 if (iap->ia_valid & ATTR_MTIME_SET)
846 len += 16;
847 else if (iap->ia_valid & ATTR_MTIME)
848 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300849 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 /*
852 * We write the bitmap length now, but leave the bitmap and the attribute
853 * buffer length to be backfilled at the end of this routine.
854 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300855 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 q = p;
857 p += 3;
858
859 if (iap->ia_valid & ATTR_SIZE) {
860 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300861 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
863 if (iap->ia_valid & ATTR_MODE) {
864 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300865 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867 if (iap->ia_valid & ATTR_UID) {
868 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300869 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871 if (iap->ia_valid & ATTR_GID) {
872 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300873 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875 if (iap->ia_valid & ATTR_ATIME_SET) {
876 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300877 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
878 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400879 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
880 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882 else if (iap->ia_valid & ATTR_ATIME) {
883 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300884 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886 if (iap->ia_valid & ATTR_MTIME_SET) {
887 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300888 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
889 *p++ = cpu_to_be32(0);
890 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
891 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893 else if (iap->ia_valid & ATTR_MTIME) {
894 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300895 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 /*
899 * Now we backfill the bitmap and the attribute buffer length.
900 */
901 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400902 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 len, ((char *)p - (char *)q) + 4);
904 BUG();
905 }
906 len = (char *)p - (char *)q - 12;
907 *q++ = htonl(bmval0);
908 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300909 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500914static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Al Viro8687b632006-10-19 23:28:48 -0700916 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Benny Halevy13c65ce2009-08-14 17:19:25 +0300918 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300920 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400922 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500925static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Al Viro8687b632006-10-19 23:28:48 -0700927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Benny Halevy13c65ce2009-08-14 17:19:25 +0300929 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300930 *p++ = cpu_to_be32(OP_CLOSE);
931 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300932 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500933 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400934 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500937static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Al Viro8687b632006-10-19 23:28:48 -0700939 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500940
Benny Halevy13c65ce2009-08-14 17:19:25 +0300941 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300942 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300943 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300944 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500945 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400946 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500949static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Al Viro8687b632006-10-19 23:28:48 -0700951 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500952
Benny Halevy13c65ce2009-08-14 17:19:25 +0300953 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300954 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300955 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 switch (create->ftype) {
958 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300959 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300960 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400961 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 break;
963
964 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300965 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300966 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300967 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 break;
969
970 default:
971 break;
972 }
973
Benny Halevy811652b2009-08-14 17:19:34 +0300974 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500975 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400976 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500978 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500981static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982{
Andy Adamson05d564f2008-12-23 16:06:15 -0500983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Benny Halevy13c65ce2009-08-14 17:19:25 +0300985 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300986 *p++ = cpu_to_be32(OP_GETATTR);
987 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300988 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500989 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400990 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500993static 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 -0700994{
Andy Adamson05d564f2008-12-23 16:06:15 -0500995 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Benny Halevy13c65ce2009-08-14 17:19:25 +0300997 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300998 *p++ = cpu_to_be32(OP_GETATTR);
999 *p++ = cpu_to_be32(2);
1000 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001001 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001002 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001003 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001008 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1009 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001012static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001014 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1015 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016}
1017
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001018static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001019{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001020 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1021 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001022}
1023
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001024static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
Al Viro8687b632006-10-19 23:28:48 -07001026 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Benny Halevy13c65ce2009-08-14 17:19:25 +03001028 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001031 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001034static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Al Viro8687b632006-10-19 23:28:48 -07001036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Benny Halevy13c65ce2009-08-14 17:19:25 +03001038 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001040 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001041 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001042 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001045static inline int nfs4_lock_type(struct file_lock *fl, int block)
1046{
1047 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1048 return block ? NFS4_READW_LT : NFS4_READ_LT;
1049 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1050}
1051
1052static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1053{
1054 if (fl->fl_end == OFFSET_MAX)
1055 return ~(uint64_t)0;
1056 return fl->fl_end - fl->fl_start + 1;
1057}
1058
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001059static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1060{
1061 __be32 *p;
1062
1063 p = reserve_space(xdr, 28);
1064 p = xdr_encode_hyper(p, lowner->clientid);
1065 *p++ = cpu_to_be32(16);
1066 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1067 xdr_encode_hyper(p, lowner->id);
1068}
1069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070/*
1071 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1072 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1073 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Al Viro8687b632006-10-19 23:28:48 -07001076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Benny Halevy13c65ce2009-08-14 17:19:25 +03001078 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001079 *p++ = cpu_to_be32(OP_LOCK);
1080 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1081 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001082 p = xdr_encode_hyper(p, args->fl->fl_start);
1083 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001084 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001085 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001086 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001087 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001088 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001089 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001090 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001093 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001094 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001095 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
Andy Adamsond0179312008-12-23 16:06:17 -05001097 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001098 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001101static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Al Viro8687b632006-10-19 23:28:48 -07001103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001105 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001106 *p++ = cpu_to_be32(OP_LOCKT);
1107 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001108 p = xdr_encode_hyper(p, args->fl->fl_start);
1109 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001110 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001111 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001112 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001115static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Al Viro8687b632006-10-19 23:28:48 -07001117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Benny Halevy13c65ce2009-08-14 17:19:25 +03001119 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001120 *p++ = cpu_to_be32(OP_LOCKU);
1121 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1122 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001123 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001124 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001125 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001126 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001127 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001130static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1131{
1132 __be32 *p;
1133
1134 p = reserve_space(xdr, 4);
1135 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1136 encode_lockowner(xdr, lowner);
1137 hdr->nops++;
1138 hdr->replen += decode_release_lockowner_maxsz;
1139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
1143 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Benny Halevy13c65ce2009-08-14 17:19:25 +03001146 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001147 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001148 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001149 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001150 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001153static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
Al Viro8687b632006-10-19 23:28:48 -07001155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Benny Halevy13c65ce2009-08-14 17:19:25 +03001157 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001158 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001159 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001161 break;
1162 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001163 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001164 break;
1165 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001166 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001167 break;
1168 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001169 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
Benny Halevy34558512009-08-14 17:19:30 +03001171 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
1174static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1175{
Al Viro8687b632006-10-19 23:28:48 -07001176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 /*
1178 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1179 * owner 4 = 32
1180 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001181 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001183 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001184 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001185 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001186 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001187 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001188 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001189 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
1192static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1193{
Al Viro8687b632006-10-19 23:28:48 -07001194 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001195 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Benny Halevy13c65ce2009-08-14 17:19:25 +03001197 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001199 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001200 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001201 encode_attrs(xdr, arg->u.attrs, arg->server);
1202 break;
1203 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001204 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001205 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001206 if (nfs4_has_persistent_session(clp)) {
1207 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1208 encode_attrs(xdr, arg->u.attrs, arg->server);
1209 } else {
1210 struct iattr dummy;
1211
1212 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1213 encode_nfs4_verifier(xdr, &arg->u.verifier);
1214 dummy.ia_valid = 0;
1215 encode_attrs(xdr, &dummy, arg->server);
1216 }
1217 } else {
1218 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1219 encode_nfs4_verifier(xdr, &arg->u.verifier);
1220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 }
1222}
1223
1224static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1225{
Al Viro8687b632006-10-19 23:28:48 -07001226 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Benny Halevy13c65ce2009-08-14 17:19:25 +03001228 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001230 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001231 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001232 break;
1233 default:
1234 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001235 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001236 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 }
1238}
1239
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001240static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
Al Viro8687b632006-10-19 23:28:48 -07001242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Benny Halevy13c65ce2009-08-14 17:19:25 +03001244 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001246 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001247 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001248 break;
1249 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001250 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001251 break;
1252 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001253 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001254 break;
1255 default:
1256 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 }
1258}
1259
1260static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1261{
Al Viro8687b632006-10-19 23:28:48 -07001262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Benny Halevy13c65ce2009-08-14 17:19:25 +03001264 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 encode_string(xdr, name->len, name->name);
1267}
1268
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001269static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Al Viro8687b632006-10-19 23:28:48 -07001271 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Benny Halevy13c65ce2009-08-14 17:19:25 +03001273 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001274 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 encode_delegation_type(xdr, type);
1276}
1277
1278static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1279{
Al Viro8687b632006-10-19 23:28:48 -07001280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Benny Halevy13c65ce2009-08-14 17:19:25 +03001282 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001283 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001284 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 encode_string(xdr, name->len, name->name);
1286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 encode_openhdr(xdr, arg);
1291 encode_opentype(xdr, arg);
1292 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001293 case NFS4_OPEN_CLAIM_NULL:
1294 encode_claim_null(xdr, arg->name);
1295 break;
1296 case NFS4_OPEN_CLAIM_PREVIOUS:
1297 encode_claim_previous(xdr, arg->u.delegation_type);
1298 break;
1299 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1300 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1301 break;
1302 default:
1303 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
Andy Adamsond0179312008-12-23 16:06:17 -05001305 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001306 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307}
1308
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001309static 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 -07001310{
Al Viro8687b632006-10-19 23:28:48 -07001311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Benny Halevy13c65ce2009-08-14 17:19:25 +03001313 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001315 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001316 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001317 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001318 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001321static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Al Viro8687b632006-10-19 23:28:48 -07001323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Benny Halevy13c65ce2009-08-14 17:19:25 +03001325 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001326 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001327 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001328 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001329 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001330 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001331 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001334static void
Andy Adamsond0179312008-12-23 16:06:17 -05001335encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Benny Halevy13c65ce2009-08-14 17:19:25 +03001340 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001341 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001342 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001343 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001344 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001347static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
Andy Adamson05d564f2008-12-23 16:06:15 -05001349 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001350
Benny Halevy13c65ce2009-08-14 17:19:25 +03001351 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001352 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001353 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001354 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001357static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Benny Halevy13c65ce2009-08-14 17:19:25 +03001362 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001364 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Benny Halevy34558512009-08-14 17:19:30 +03001365 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 } else
Benny Halevy34558512009-08-14 17:19:30 +03001367 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001370static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Benny Halevy13c65ce2009-08-14 17:19:25 +03001374 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001377 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Benny Halevy13c65ce2009-08-14 17:19:25 +03001379 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001380 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001381 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001382 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001383 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001386static 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 -07001387{
Manoj Naik97d312d2005-06-22 17:16:39 +00001388 uint32_t attrs[2] = {
1389 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1390 FATTR4_WORD1_MOUNTED_ON_FILEID,
1391 };
Al Viro8687b632006-10-19 23:28:48 -07001392 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Benny Halevy13c65ce2009-08-14 17:19:25 +03001394 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001395 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001396 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001397 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001398 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1399 *p++ = cpu_to_be32(readdir->count);
1400 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001401 /* Switch to mounted_on_fileid if the server supports it */
1402 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1403 attrs[0] &= ~FATTR4_WORD0_FILEID;
1404 else
1405 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001406 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001407 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001408 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001409 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001410 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1411 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001412 (unsigned long long)readdir->cookie,
1413 ((u32 *)readdir->verifier.data)[0],
1414 ((u32 *)readdir->verifier.data)[1],
1415 attrs[0] & readdir->bitmask[0],
1416 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417}
1418
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001419static 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 -07001420{
Al Viro8687b632006-10-19 23:28:48 -07001421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Benny Halevy13c65ce2009-08-14 17:19:25 +03001423 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001425 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001426 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427}
1428
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001429static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
Al Viro8687b632006-10-19 23:28:48 -07001431 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Benny Halevy13c65ce2009-08-14 17:19:25 +03001433 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001434 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001435 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001436 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001437 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001440static 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 -07001441{
Al Viro8687b632006-10-19 23:28:48 -07001442 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Benny Halevy811652b2009-08-14 17:19:34 +03001444 p = reserve_space(xdr, 4);
1445 *p = cpu_to_be32(OP_RENAME);
1446 encode_string(xdr, oldname->len, oldname->name);
1447 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001448 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001449 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001452static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001457 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001458 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001459 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001460 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static void
Andy Adamsond0179312008-12-23 16:06:17 -05001464encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001465{
Al Viro8687b632006-10-19 23:28:48 -07001466 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001467
Benny Halevy13c65ce2009-08-14 17:19:25 +03001468 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001469 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001470 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001471 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001472}
1473
1474static int
Andy Adamsond0179312008-12-23 16:06:17 -05001475encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001476{
Al Viro8687b632006-10-19 23:28:48 -07001477 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001478
Benny Halevy13c65ce2009-08-14 17:19:25 +03001479 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001480 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001481 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001482 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001483 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001484 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001485 if (arg->acl_len % 4)
1486 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001487 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001488 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001489 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001490 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001491 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001492 return 0;
1493}
1494
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001495static void
Andy Adamsond0179312008-12-23 16:06:17 -05001496encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001501 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001502 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001503 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001506static 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 -07001507{
Al Viro8687b632006-10-19 23:28:48 -07001508 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001509
Benny Halevy13c65ce2009-08-14 17:19:25 +03001510 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001511 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001512 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001513 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001514 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001515 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
Al Viro8687b632006-10-19 23:28:48 -07001520 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Benny Halevy13c65ce2009-08-14 17:19:25 +03001522 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001523 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001524 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001527 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001528 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1530 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001531 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001532 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001533 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001534 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535}
1536
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001537static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538{
Andy Adamson05d564f2008-12-23 16:06:15 -05001539 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Benny Halevy13c65ce2009-08-14 17:19:25 +03001541 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001542 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001543 p = xdr_encode_hyper(p, arg->clientid);
1544 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001545 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001546 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001549static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Al Viro8687b632006-10-19 23:28:48 -07001551 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001554 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001556 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Benny Halevy13c65ce2009-08-14 17:19:25 +03001558 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001559 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001560 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001561 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001564 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001565 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Al Viro8687b632006-10-19 23:28:48 -07001570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Benny Halevy13c65ce2009-08-14 17:19:25 +03001572 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Benny Halevye75bc1c2009-08-14 17:18:54 +03001574 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001575 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001576 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001577 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001579
Benny Halevy99fe60d2009-04-01 09:22:29 -04001580#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001581/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001582static void encode_exchange_id(struct xdr_stream *xdr,
1583 struct nfs41_exchange_id_args *args,
1584 struct compound_hdr *hdr)
1585{
1586 __be32 *p;
1587
Benny Halevy13c65ce2009-08-14 17:19:25 +03001588 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001589 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001590 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001591
1592 encode_string(xdr, args->id_len, args->id);
1593
Benny Halevy13c65ce2009-08-14 17:19:25 +03001594 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001595 *p++ = cpu_to_be32(args->flags);
1596 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001597 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001598 hdr->nops++;
1599 hdr->replen += decode_exchange_id_maxsz;
1600}
Andy Adamsonfc931582009-04-01 09:22:31 -04001601
1602static void encode_create_session(struct xdr_stream *xdr,
1603 struct nfs41_create_session_args *args,
1604 struct compound_hdr *hdr)
1605{
1606 __be32 *p;
1607 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1608 uint32_t len;
1609 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001610 u32 max_resp_sz_cached;
1611
1612 /*
1613 * Assumes OPEN is the biggest non-idempotent compound.
1614 * 2 is the verifier.
1615 */
1616 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1617 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001618
Andy Adamsonfc931582009-04-01 09:22:31 -04001619 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1620 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001621
Benny Halevy13c65ce2009-08-14 17:19:25 +03001622 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001623 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001624 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001625 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1626 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001627
Andy Adamsonfc931582009-04-01 09:22:31 -04001628 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001629 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1630 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1631 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001632 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001633 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1634 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1635 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001636
1637 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001638 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1639 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1640 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1641 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1642 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1643 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1644 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001645
Benny Halevye75bc1c2009-08-14 17:18:54 +03001646 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001648 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001649
1650 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001651 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001652 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001653 *p++ = cpu_to_be32(0); /* UID */
1654 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001655 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001656 hdr->nops++;
1657 hdr->replen += decode_create_session_maxsz;
1658}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001659
1660static void encode_destroy_session(struct xdr_stream *xdr,
1661 struct nfs4_session *session,
1662 struct compound_hdr *hdr)
1663{
1664 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001665 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001666 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001667 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001668 hdr->nops++;
1669 hdr->replen += decode_destroy_session_maxsz;
1670}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001671
1672static void encode_reclaim_complete(struct xdr_stream *xdr,
1673 struct nfs41_reclaim_complete_args *args,
1674 struct compound_hdr *hdr)
1675{
1676 __be32 *p;
1677
1678 p = reserve_space(xdr, 8);
1679 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1680 *p++ = cpu_to_be32(args->one_fs);
1681 hdr->nops++;
1682 hdr->replen += decode_reclaim_complete_maxsz;
1683}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001684#endif /* CONFIG_NFS_V4_1 */
1685
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001686static void encode_sequence(struct xdr_stream *xdr,
1687 const struct nfs4_sequence_args *args,
1688 struct compound_hdr *hdr)
1689{
1690#if defined(CONFIG_NFS_V4_1)
1691 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001692 struct nfs4_slot_table *tp;
1693 struct nfs4_slot *slot;
1694 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001695
1696 if (!session)
1697 return;
1698
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001699 tp = &session->fc_slot_table;
1700
1701 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1702 slot = tp->slots + args->sa_slotid;
1703
Benny Halevy13c65ce2009-08-14 17:19:25 +03001704 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001705 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001706
1707 /*
1708 * Sessionid + seqid + slotid + max slotid + cache_this
1709 */
1710 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1711 "max_slotid=%d cache_this=%d\n",
1712 __func__,
1713 ((u32 *)session->sess_id.data)[0],
1714 ((u32 *)session->sess_id.data)[1],
1715 ((u32 *)session->sess_id.data)[2],
1716 ((u32 *)session->sess_id.data)[3],
1717 slot->seq_nr, args->sa_slotid,
1718 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001719 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001720 *p++ = cpu_to_be32(slot->seq_nr);
1721 *p++ = cpu_to_be32(args->sa_slotid);
1722 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001723 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001724 hdr->nops++;
1725 hdr->replen += decode_sequence_maxsz;
1726#endif /* CONFIG_NFS_V4_1 */
1727}
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729/*
1730 * END OF "GENERIC" ENCODE ROUTINES.
1731 */
1732
Benny Halevy66cc0422009-04-01 09:22:10 -04001733static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1734{
1735#if defined(CONFIG_NFS_V4_1)
1736 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001737 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001738#endif /* CONFIG_NFS_V4_1 */
1739 return 0;
1740}
1741
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742/*
1743 * Encode an ACCESS request
1744 */
Al Viro8687b632006-10-19 23:28:48 -07001745static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
1747 struct xdr_stream xdr;
1748 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001749 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001753 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001754 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001755 encode_putfh(&xdr, args->fh, &hdr);
1756 encode_access(&xdr, args->access, &hdr);
1757 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001758 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001759 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760}
1761
1762/*
1763 * Encode LOOKUP request
1764 */
Al Viro8687b632006-10-19 23:28:48 -07001765static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
1767 struct xdr_stream xdr;
1768 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001769 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001773 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001774 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001775 encode_putfh(&xdr, args->dir_fh, &hdr);
1776 encode_lookup(&xdr, args->name, &hdr);
1777 encode_getfh(&xdr, &hdr);
1778 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001779 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781}
1782
1783/*
1784 * Encode LOOKUP_ROOT request
1785 */
Al Viro8687b632006-10-19 23:28:48 -07001786static 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 -07001787{
1788 struct xdr_stream xdr;
1789 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001790 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
1793 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001794 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001795 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001796 encode_putrootfh(&xdr, &hdr);
1797 encode_getfh(&xdr, &hdr);
1798 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001799 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001800 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801}
1802
1803/*
1804 * Encode REMOVE request
1805 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001806static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807{
1808 struct xdr_stream xdr;
1809 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001810 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
1813 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001814 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001815 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001816 encode_putfh(&xdr, args->fh, &hdr);
1817 encode_remove(&xdr, &args->name, &hdr);
1818 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001819 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001820 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821}
1822
1823/*
1824 * Encode RENAME request
1825 */
Jeff Layton920769f2010-09-17 17:30:25 -04001826static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
1828 struct xdr_stream xdr;
1829 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001830 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
1833 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001834 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001835 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001836 encode_putfh(&xdr, args->old_dir, &hdr);
1837 encode_savefh(&xdr, &hdr);
1838 encode_putfh(&xdr, args->new_dir, &hdr);
1839 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1840 encode_getfattr(&xdr, args->bitmask, &hdr);
1841 encode_restorefh(&xdr, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001843 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001844 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
1847/*
1848 * Encode LINK request
1849 */
Al Viro8687b632006-10-19 23:28:48 -07001850static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001854 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001858 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001859 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001860 encode_putfh(&xdr, args->fh, &hdr);
1861 encode_savefh(&xdr, &hdr);
1862 encode_putfh(&xdr, args->dir_fh, &hdr);
1863 encode_link(&xdr, args->name, &hdr);
1864 encode_getfattr(&xdr, args->bitmask, &hdr);
1865 encode_restorefh(&xdr, &hdr);
1866 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001867 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001868 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
1870
1871/*
1872 * Encode CREATE request
1873 */
Al Viro8687b632006-10-19 23:28:48 -07001874static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875{
1876 struct xdr_stream xdr;
1877 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001878 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
1881 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001882 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001883 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001884 encode_putfh(&xdr, args->dir_fh, &hdr);
1885 encode_savefh(&xdr, &hdr);
1886 encode_create(&xdr, args, &hdr);
1887 encode_getfh(&xdr, &hdr);
1888 encode_getfattr(&xdr, args->bitmask, &hdr);
1889 encode_restorefh(&xdr, &hdr);
1890 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001891 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001892 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893}
1894
1895/*
1896 * Encode SYMLINK request
1897 */
Al Viro8687b632006-10-19 23:28:48 -07001898static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899{
1900 return nfs4_xdr_enc_create(req, p, args);
1901}
1902
1903/*
1904 * Encode GETATTR request
1905 */
Al Viro8687b632006-10-19 23:28:48 -07001906static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001914 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001915 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001916 encode_putfh(&xdr, args->fh, &hdr);
1917 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001918 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001919 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
1922/*
1923 * Encode a CLOSE request
1924 */
Al Viro8687b632006-10-19 23:28:48 -07001925static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
Andy Adamson05d564f2008-12-23 16:06:15 -05001927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001929 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001930 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
Andy Adamson05d564f2008-12-23 16:06:15 -05001932 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001933 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001934 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001935 encode_putfh(&xdr, args->fh, &hdr);
1936 encode_close(&xdr, args, &hdr);
1937 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001938 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001939 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
1942/*
1943 * Encode an OPEN request
1944 */
Al Viro8687b632006-10-19 23:28:48 -07001945static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946{
1947 struct xdr_stream xdr;
1948 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001949 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
1952 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001953 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001954 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001955 encode_putfh(&xdr, args->fh, &hdr);
1956 encode_savefh(&xdr, &hdr);
1957 encode_open(&xdr, args, &hdr);
1958 encode_getfh(&xdr, &hdr);
1959 encode_getfattr(&xdr, args->bitmask, &hdr);
1960 encode_restorefh(&xdr, &hdr);
1961 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001962 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001963 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
1966/*
1967 * Encode an OPEN_CONFIRM request
1968 */
Al Viro8687b632006-10-19 23:28:48 -07001969static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
1971 struct xdr_stream xdr;
1972 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001973 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
1976 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001977 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001978 encode_putfh(&xdr, args->fh, &hdr);
1979 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001980 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001981 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982}
1983
1984/*
1985 * Encode an OPEN request with no attributes.
1986 */
Al Viro8687b632006-10-19 23:28:48 -07001987static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
1989 struct xdr_stream xdr;
1990 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001995 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001996 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001997 encode_putfh(&xdr, args->fh, &hdr);
1998 encode_open(&xdr, args, &hdr);
1999 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002000 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002001 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002}
2003
2004/*
2005 * Encode an OPEN_DOWNGRADE request
2006 */
Al Viro8687b632006-10-19 23:28:48 -07002007static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
2009 struct xdr_stream xdr;
2010 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002011 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002015 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002016 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002017 encode_putfh(&xdr, args->fh, &hdr);
2018 encode_open_downgrade(&xdr, args, &hdr);
2019 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002020 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002021 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
2023
2024/*
2025 * Encode a LOCK request
2026 */
Al Viro8687b632006-10-19 23:28:48 -07002027static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028{
2029 struct xdr_stream xdr;
2030 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002031 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002035 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002036 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002037 encode_putfh(&xdr, args->fh, &hdr);
2038 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002039 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002040 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041}
2042
2043/*
2044 * Encode a LOCKT request
2045 */
Al Viro8687b632006-10-19 23:28:48 -07002046static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
2048 struct xdr_stream xdr;
2049 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002050 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
2053 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002054 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002055 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002056 encode_putfh(&xdr, args->fh, &hdr);
2057 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002058 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002059 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
2062/*
2063 * Encode a LOCKU request
2064 */
Al Viro8687b632006-10-19 23:28:48 -07002065static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
2067 struct xdr_stream xdr;
2068 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
2072 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002073 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002074 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002075 encode_putfh(&xdr, args->fh, &hdr);
2076 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002077 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002078 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002081static int nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, __be32 *p, struct nfs_release_lockowner_args *args)
2082{
2083 struct xdr_stream xdr;
2084 struct compound_hdr hdr = {
2085 .minorversion = 0,
2086 };
2087
2088 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2089 encode_compound_hdr(&xdr, req, &hdr);
2090 encode_release_lockowner(&xdr, &args->lock_owner, &hdr);
2091 encode_nops(&hdr);
2092 return 0;
2093}
2094
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095/*
2096 * Encode a READLINK request
2097 */
Al Viro8687b632006-10-19 23:28:48 -07002098static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
2100 struct xdr_stream xdr;
2101 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002106 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002107 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002108 encode_putfh(&xdr, args->fh, &hdr);
2109 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002110
Benny Halevy28f56692009-04-01 09:22:09 -04002111 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002112 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002113 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002114 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
2117/*
2118 * Encode a READDIR request
2119 */
Al Viro8687b632006-10-19 23:28:48 -07002120static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
2122 struct xdr_stream xdr;
2123 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
2127 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002128 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002129 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002130 encode_putfh(&xdr, args->fh, &hdr);
2131 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002132
Benny Halevy28f56692009-04-01 09:22:09 -04002133 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002134 args->pgbase, args->count);
2135 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002136 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002137 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002138 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002139 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140}
2141
2142/*
2143 * Encode a READ request
2144 */
Al Viro8687b632006-10-19 23:28:48 -07002145static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct xdr_stream xdr;
2148 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002149 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002153 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002154 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002155 encode_putfh(&xdr, args->fh, &hdr);
2156 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Benny Halevy28f56692009-04-01 09:22:09 -04002158 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002160 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002162 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163}
2164
2165/*
2166 * Encode an SETATTR request
2167 */
Al Viro8687b632006-10-19 23:28:48 -07002168static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Andy Adamson05d564f2008-12-23 16:06:15 -05002170 struct xdr_stream xdr;
2171 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002173 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Andy Adamson05d564f2008-12-23 16:06:15 -05002175 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002176 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002177 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002178 encode_putfh(&xdr, args->fh, &hdr);
2179 encode_setattr(&xdr, args, args->server, &hdr);
2180 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002181 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002182 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002186 * Encode a GETACL request
2187 */
2188static int
Al Viro8687b632006-10-19 23:28:48 -07002189nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002190 struct nfs_getaclargs *args)
2191{
2192 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002193 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002194 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002195 };
Benny Halevy28f56692009-04-01 09:22:09 -04002196 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002197
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);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002202 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002203 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2204
Benny Halevy28f56692009-04-01 09:22:09 -04002205 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002206 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002208 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002209}
2210
2211/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 * Encode a WRITE request
2213 */
Al Viro8687b632006-10-19 23:28:48 -07002214static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
2216 struct xdr_stream xdr;
2217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002222 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002223 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002224 encode_putfh(&xdr, args->fh, &hdr);
2225 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002226 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002227 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002228 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002229 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * a COMMIT request
2234 */
Al Viro8687b632006-10-19 23:28:48 -07002235static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
2237 struct xdr_stream xdr;
2238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002243 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002244 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002245 encode_putfh(&xdr, args->fh, &hdr);
2246 encode_commit(&xdr, args, &hdr);
2247 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002249 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
2252/*
2253 * FSINFO request
2254 */
Al Viro8687b632006-10-19 23:28:48 -07002255static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
2257 struct xdr_stream xdr;
2258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002263 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002264 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002265 encode_putfh(&xdr, args->fh, &hdr);
2266 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002267 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002268 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
2271/*
2272 * a PATHCONF request
2273 */
Al Viro8687b632006-10-19 23:28:48 -07002274static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct xdr_stream xdr;
2277 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002278 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002282 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002283 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002284 encode_putfh(&xdr, args->fh, &hdr);
2285 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2286 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002287 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002288 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
2291/*
2292 * a STATFS request
2293 */
Al Viro8687b632006-10-19 23:28:48 -07002294static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct xdr_stream xdr;
2297 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002298 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002302 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002303 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002304 encode_putfh(&xdr, args->fh, &hdr);
2305 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2306 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002308 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309}
2310
2311/*
2312 * GETATTR_BITMAP request
2313 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002314static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2315 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
2317 struct xdr_stream xdr;
2318 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002319 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002323 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002324 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002325 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002326 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2327 FATTR4_WORD0_LINK_SUPPORT|
2328 FATTR4_WORD0_SYMLINK_SUPPORT|
2329 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002330 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002331 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
2334/*
2335 * a RENEW request
2336 */
Al Viro8687b632006-10-19 23:28:48 -07002337static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
2339 struct xdr_stream xdr;
2340 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002341 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 };
2343
2344 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002345 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002346 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002347 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002348 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
2351/*
2352 * a SETCLIENTID request
2353 */
Al Viro8687b632006-10-19 23:28:48 -07002354static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355{
2356 struct xdr_stream xdr;
2357 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002358 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 };
2360
2361 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002362 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002363 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002364 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002365 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
2368/*
2369 * a SETCLIENTID_CONFIRM request
2370 */
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002371static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
2373 struct xdr_stream xdr;
2374 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002375 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 };
2377 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
2379 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002380 encode_compound_hdr(&xdr, req, &hdr);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002381 encode_setclientid_confirm(&xdr, arg, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002382 encode_putrootfh(&xdr, &hdr);
2383 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002384 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002385 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386}
2387
2388/*
2389 * DELEGRETURN request
2390 */
Al Viro8687b632006-10-19 23:28:48 -07002391static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
2393 struct xdr_stream xdr;
2394 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
2398 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002399 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002400 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002401 encode_putfh(&xdr, args->fhandle, &hdr);
2402 encode_delegreturn(&xdr, args->stateid, &hdr);
2403 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002404 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406}
2407
2408/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002409 * Encode FS_LOCATIONS request
2410 */
Al Viro8687b632006-10-19 23:28:48 -07002411static 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 -04002412{
2413 struct xdr_stream xdr;
2414 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002416 };
Benny Halevy28f56692009-04-01 09:22:09 -04002417 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002418
2419 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002420 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002421 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002422 encode_putfh(&xdr, args->dir_fh, &hdr);
2423 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002424 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002425 encode_fs_locations(&xdr, args->bitmask, &hdr);
2426
Benny Halevy28f56692009-04-01 09:22:09 -04002427 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002428 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002429 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002430 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002431}
2432
Benny Halevy99fe60d2009-04-01 09:22:29 -04002433#if defined(CONFIG_NFS_V4_1)
2434/*
2435 * EXCHANGE_ID request
2436 */
2437static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2438 struct nfs41_exchange_id_args *args)
2439{
2440 struct xdr_stream xdr;
2441 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002442 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002443 };
2444
2445 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2446 encode_compound_hdr(&xdr, req, &hdr);
2447 encode_exchange_id(&xdr, args, &hdr);
2448 encode_nops(&hdr);
2449 return 0;
2450}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002451
2452/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002453 * a CREATE_SESSION request
2454 */
2455static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2456 struct nfs41_create_session_args *args)
2457{
2458 struct xdr_stream xdr;
2459 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002460 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002461 };
2462
2463 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2464 encode_compound_hdr(&xdr, req, &hdr);
2465 encode_create_session(&xdr, args, &hdr);
2466 encode_nops(&hdr);
2467 return 0;
2468}
2469
2470/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002471 * a DESTROY_SESSION request
2472 */
2473static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2474 struct nfs4_session *session)
2475{
2476 struct xdr_stream xdr;
2477 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002478 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002479 };
2480
2481 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2482 encode_compound_hdr(&xdr, req, &hdr);
2483 encode_destroy_session(&xdr, session, &hdr);
2484 encode_nops(&hdr);
2485 return 0;
2486}
2487
2488/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002489 * a SEQUENCE request
2490 */
2491static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2492 struct nfs4_sequence_args *args)
2493{
2494 struct xdr_stream xdr;
2495 struct compound_hdr hdr = {
2496 .minorversion = nfs4_xdr_minorversion(args),
2497 };
2498
2499 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2500 encode_compound_hdr(&xdr, req, &hdr);
2501 encode_sequence(&xdr, args, &hdr);
2502 encode_nops(&hdr);
2503 return 0;
2504}
2505
2506/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002507 * a GET_LEASE_TIME request
2508 */
2509static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2510 struct nfs4_get_lease_time_args *args)
2511{
2512 struct xdr_stream xdr;
2513 struct compound_hdr hdr = {
2514 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2515 };
2516 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2517
2518 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2519 encode_compound_hdr(&xdr, req, &hdr);
2520 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2521 encode_putrootfh(&xdr, &hdr);
2522 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2523 encode_nops(&hdr);
2524 return 0;
2525}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002526
2527/*
2528 * a RECLAIM_COMPLETE request
2529 */
2530static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2531 struct nfs41_reclaim_complete_args *args)
2532{
2533 struct xdr_stream xdr;
2534 struct compound_hdr hdr = {
2535 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2536 };
2537
2538 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2539 encode_compound_hdr(&xdr, req, &hdr);
2540 encode_sequence(&xdr, &args->seq_args, &hdr);
2541 encode_reclaim_complete(&xdr, args, &hdr);
2542 encode_nops(&hdr);
2543 return 0;
2544}
2545
Benny Halevy99fe60d2009-04-01 09:22:29 -04002546#endif /* CONFIG_NFS_V4_1 */
2547
Benny Halevy686841b2009-08-14 17:19:48 +03002548static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2549{
2550 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2551 "Remaining buffer length is %tu words.\n",
2552 func, xdr->end - xdr->p);
2553}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Trond Myklebust683b57b2006-06-09 09:34:22 -04002555static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
Al Viro8687b632006-10-19 23:28:48 -07002557 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Benny Halevyc0eae662009-08-14 17:20:14 +03002559 p = xdr_inline_decode(xdr, 4);
2560 if (unlikely(!p))
2561 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002562 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002563 p = xdr_inline_decode(xdr, *len);
2564 if (unlikely(!p))
2565 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 *string = (char *)p;
2567 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002568out_overflow:
2569 print_overflow_msg(__func__, xdr);
2570 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
2573static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2574{
Al Viro8687b632006-10-19 23:28:48 -07002575 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Benny Halevyc0eae662009-08-14 17:20:14 +03002577 p = xdr_inline_decode(xdr, 8);
2578 if (unlikely(!p))
2579 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002580 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002581 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002582
Benny Halevyc0eae662009-08-14 17:20:14 +03002583 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2584 if (unlikely(!p))
2585 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 hdr->tag = (char *)p;
2587 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002588 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002589 if (unlikely(hdr->nops < 1))
2590 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002592out_overflow:
2593 print_overflow_msg(__func__, xdr);
2594 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
2597static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2598{
Al Viro8687b632006-10-19 23:28:48 -07002599 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 uint32_t opnum;
2601 int32_t nfserr;
2602
Benny Halevyc0eae662009-08-14 17:20:14 +03002603 p = xdr_inline_decode(xdr, 8);
2604 if (unlikely(!p))
2605 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002606 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002608 dprintk("nfs: Server returned operation"
2609 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 opnum, expected);
2611 return -EIO;
2612 }
Benny Halevycccddf42009-08-14 17:20:19 +03002613 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002615 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002617out_overflow:
2618 print_overflow_msg(__func__, xdr);
2619 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620}
2621
2622/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002623static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624{
Al Viro8687b632006-10-19 23:28:48 -07002625 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002626 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 char *str;
2628
Benny Halevyc0eae662009-08-14 17:20:14 +03002629 p = xdr_inline_decode(xdr, 12);
2630 if (likely(p))
2631 return decode_opaque_inline(xdr, &strlen, &str);
2632 print_overflow_msg(__func__, xdr);
2633 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634}
2635
2636static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2637{
Al Viro8687b632006-10-19 23:28:48 -07002638 uint32_t bmlen;
2639 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
Benny Halevyc0eae662009-08-14 17:20:14 +03002641 p = xdr_inline_decode(xdr, 4);
2642 if (unlikely(!p))
2643 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002644 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002647 p = xdr_inline_decode(xdr, (bmlen << 2));
2648 if (unlikely(!p))
2649 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002651 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002653 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 }
2655 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002656out_overflow:
2657 print_overflow_msg(__func__, xdr);
2658 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
2660
Al Viro8687b632006-10-19 23:28:48 -07002661static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
Al Viro8687b632006-10-19 23:28:48 -07002663 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Benny Halevyc0eae662009-08-14 17:20:14 +03002665 p = xdr_inline_decode(xdr, 4);
2666 if (unlikely(!p))
2667 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002668 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 *savep = xdr->p;
2670 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002671out_overflow:
2672 print_overflow_msg(__func__, xdr);
2673 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674}
2675
2676static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2677{
2678 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2679 decode_attr_bitmap(xdr, bitmask);
2680 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2681 } else
2682 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002683 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 return 0;
2685}
2686
2687static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2688{
Al Viro8687b632006-10-19 23:28:48 -07002689 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002690 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
2692 *type = 0;
2693 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2694 return -EIO;
2695 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002696 p = xdr_inline_decode(xdr, 4);
2697 if (unlikely(!p))
2698 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002699 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002701 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 return -EIO;
2703 }
2704 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002705 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002707 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002708 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002709out_overflow:
2710 print_overflow_msg(__func__, xdr);
2711 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712}
2713
2714static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2715{
Al Viro8687b632006-10-19 23:28:48 -07002716 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002717 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
2719 *change = 0;
2720 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2721 return -EIO;
2722 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002723 p = xdr_inline_decode(xdr, 8);
2724 if (unlikely(!p))
2725 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002726 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002728 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002730 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002732 return ret;
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_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2739{
Al Viro8687b632006-10-19 23:28:48 -07002740 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002741 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
2743 *size = 0;
2744 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2745 return -EIO;
2746 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002747 p = xdr_inline_decode(xdr, 8);
2748 if (unlikely(!p))
2749 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002750 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002752 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002754 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002755 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002756out_overflow:
2757 print_overflow_msg(__func__, xdr);
2758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759}
2760
2761static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2762{
Al Viro8687b632006-10-19 23:28:48 -07002763 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
2765 *res = 0;
2766 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2767 return -EIO;
2768 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002769 p = xdr_inline_decode(xdr, 4);
2770 if (unlikely(!p))
2771 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002772 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2774 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002775 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002777out_overflow:
2778 print_overflow_msg(__func__, xdr);
2779 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780}
2781
2782static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2783{
Al Viro8687b632006-10-19 23:28:48 -07002784 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
2786 *res = 0;
2787 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2788 return -EIO;
2789 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002790 p = xdr_inline_decode(xdr, 4);
2791 if (unlikely(!p))
2792 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002793 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002796 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002798out_overflow:
2799 print_overflow_msg(__func__, xdr);
2800 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801}
2802
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002803static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804{
Al Viro8687b632006-10-19 23:28:48 -07002805 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002806 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 fsid->major = 0;
2809 fsid->minor = 0;
2810 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2811 return -EIO;
2812 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002813 p = xdr_inline_decode(xdr, 16);
2814 if (unlikely(!p))
2815 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002816 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002817 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002819 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002821 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 (unsigned long long)fsid->major,
2823 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002824 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002825out_overflow:
2826 print_overflow_msg(__func__, xdr);
2827 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828}
2829
2830static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2831{
Al Viro8687b632006-10-19 23:28:48 -07002832 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
2834 *res = 60;
2835 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2836 return -EIO;
2837 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002838 p = xdr_inline_decode(xdr, 4);
2839 if (unlikely(!p))
2840 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002841 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2843 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002844 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 return 0;
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
2851static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2852{
Al Viro8687b632006-10-19 23:28:48 -07002853 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
2855 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2856 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2857 return -EIO;
2858 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002859 p = xdr_inline_decode(xdr, 4);
2860 if (unlikely(!p))
2861 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002862 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2864 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002865 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002867out_overflow:
2868 print_overflow_msg(__func__, xdr);
2869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870}
2871
2872static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2873{
Al Viro8687b632006-10-19 23:28:48 -07002874 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002875 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
2877 *fileid = 0;
2878 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2879 return -EIO;
2880 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002881 p = xdr_inline_decode(xdr, 8);
2882 if (unlikely(!p))
2883 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002884 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002886 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002888 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002889 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002890out_overflow:
2891 print_overflow_msg(__func__, xdr);
2892 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893}
2894
Manoj Naik99baf622006-06-09 09:34:24 -04002895static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2896{
Al Viro8687b632006-10-19 23:28:48 -07002897 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002898 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002899
2900 *fileid = 0;
2901 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2902 return -EIO;
2903 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002904 p = xdr_inline_decode(xdr, 8);
2905 if (unlikely(!p))
2906 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002907 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002908 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002909 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002910 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002911 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002912 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002913out_overflow:
2914 print_overflow_msg(__func__, xdr);
2915 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002916}
2917
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918static int decode_attr_files_avail(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_AVAIL - 1U)))
2925 return -EIO;
2926 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
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_AVAIL;
2932 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002933 dprintk("%s: files avail=%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
2940static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2941{
Al Viro8687b632006-10-19 23:28:48 -07002942 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 int status = 0;
2944
2945 *res = 0;
2946 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2947 return -EIO;
2948 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002949 p = xdr_inline_decode(xdr, 8);
2950 if (unlikely(!p))
2951 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002952 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2954 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002955 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002957out_overflow:
2958 print_overflow_msg(__func__, xdr);
2959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960}
2961
2962static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2963{
Al Viro8687b632006-10-19 23:28:48 -07002964 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 int status = 0;
2966
2967 *res = 0;
2968 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2969 return -EIO;
2970 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002971 p = xdr_inline_decode(xdr, 8);
2972 if (unlikely(!p))
2973 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002974 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2976 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002977 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002979out_overflow:
2980 print_overflow_msg(__func__, xdr);
2981 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982}
2983
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002984static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2985{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002986 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002987 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002988 int status = 0;
2989
Benny Halevyc0eae662009-08-14 17:20:14 +03002990 p = xdr_inline_decode(xdr, 4);
2991 if (unlikely(!p))
2992 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002993 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04002994 if (n == 0)
2995 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002996 dprintk("path ");
2997 path->ncomponents = 0;
2998 while (path->ncomponents < n) {
2999 struct nfs4_string *component = &path->components[path->ncomponents];
3000 status = decode_opaque_inline(xdr, &component->len, &component->data);
3001 if (unlikely(status != 0))
3002 goto out_eio;
3003 if (path->ncomponents != n)
3004 dprintk("/");
3005 dprintk("%s", component->data);
3006 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3007 path->ncomponents++;
3008 else {
3009 dprintk("cannot parse %d components in path\n", n);
3010 goto out_eio;
3011 }
3012 }
3013out:
3014 dprintk("\n");
3015 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003016root_path:
3017/* a root pathname is sent as a zero component4 */
3018 path->ncomponents = 1;
3019 path->components[0].len=0;
3020 path->components[0].data=NULL;
3021 dprintk("path /\n");
3022 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003023out_eio:
3024 dprintk(" status %d", status);
3025 status = -EIO;
3026 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003027out_overflow:
3028 print_overflow_msg(__func__, xdr);
3029 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003030}
3031
3032static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003033{
3034 int n;
Al Viro8687b632006-10-19 23:28:48 -07003035 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003036 int status = -EIO;
3037
3038 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3039 goto out;
3040 status = 0;
3041 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3042 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003043 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003044 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003045 if (unlikely(status != 0))
3046 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003047 p = xdr_inline_decode(xdr, 4);
3048 if (unlikely(!p))
3049 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003050 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003051 if (n <= 0)
3052 goto out_eio;
3053 res->nlocations = 0;
3054 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003055 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003056 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003057
Benny Halevyc0eae662009-08-14 17:20:14 +03003058 p = xdr_inline_decode(xdr, 4);
3059 if (unlikely(!p))
3060 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003061 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003062
3063 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003064 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003065 while (loc->nservers < m) {
3066 struct nfs4_string *server = &loc->servers[loc->nservers];
3067 status = decode_opaque_inline(xdr, &server->len, &server->data);
3068 if (unlikely(status != 0))
3069 goto out_eio;
3070 dprintk("%s ", server->data);
3071 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3072 loc->nservers++;
3073 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003074 unsigned int i;
3075 dprintk("%s: using first %u of %u servers "
3076 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003077 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003078 NFS4_FS_LOCATION_MAXSERVERS,
3079 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003080 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003081 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003082 char *data;
3083 status = decode_opaque_inline(xdr, &len, &data);
3084 if (unlikely(status != 0))
3085 goto out_eio;
3086 }
3087 }
3088 }
3089 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003090 if (unlikely(status != 0))
3091 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003092 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003093 res->nlocations++;
3094 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003095 if (res->nlocations != 0)
3096 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003097out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003098 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003099 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003100out_overflow:
3101 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003102out_eio:
3103 status = -EIO;
3104 goto out;
3105}
3106
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3108{
Al Viro8687b632006-10-19 23:28:48 -07003109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 int status = 0;
3111
3112 *res = 0;
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003116 p = xdr_inline_decode(xdr, 8);
3117 if (unlikely(!p))
3118 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003119 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3121 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003122 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
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_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3130{
Al Viro8687b632006-10-19 23:28:48 -07003131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 int status = 0;
3133
3134 *maxlink = 1;
3135 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3136 return -EIO;
3137 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003138 p = xdr_inline_decode(xdr, 4);
3139 if (unlikely(!p))
3140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003141 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3143 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003144 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003146out_overflow:
3147 print_overflow_msg(__func__, xdr);
3148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149}
3150
3151static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3152{
Al Viro8687b632006-10-19 23:28:48 -07003153 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 int status = 0;
3155
3156 *maxname = 1024;
3157 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3158 return -EIO;
3159 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003160 p = xdr_inline_decode(xdr, 4);
3161 if (unlikely(!p))
3162 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003163 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3165 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003166 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003168out_overflow:
3169 print_overflow_msg(__func__, xdr);
3170 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171}
3172
3173static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3174{
Al Viro8687b632006-10-19 23:28:48 -07003175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 int status = 0;
3177
3178 *res = 1024;
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3180 return -EIO;
3181 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3182 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003183 p = xdr_inline_decode(xdr, 8);
3184 if (unlikely(!p))
3185 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003186 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 if (maxread > 0x7FFFFFFF)
3188 maxread = 0x7FFFFFFF;
3189 *res = (uint32_t)maxread;
3190 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3191 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003192 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003194out_overflow:
3195 print_overflow_msg(__func__, xdr);
3196 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197}
3198
3199static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 int status = 0;
3203
3204 *res = 1024;
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3208 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003209 p = xdr_inline_decode(xdr, 8);
3210 if (unlikely(!p))
3211 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003212 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 if (maxwrite > 0x7FFFFFFF)
3214 maxwrite = 0x7FFFFFFF;
3215 *res = (uint32_t)maxwrite;
3216 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3217 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003218 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003220out_overflow:
3221 print_overflow_msg(__func__, xdr);
3222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223}
3224
Trond Myklebustbca79472009-03-11 14:10:26 -04003225static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226{
Trond Myklebustbca79472009-03-11 14:10:26 -04003227 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003228 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003229 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
3231 *mode = 0;
3232 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003235 p = xdr_inline_decode(xdr, 4);
3236 if (unlikely(!p))
3237 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003238 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003239 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003241 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003243 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003244 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003245out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248}
3249
3250static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3251{
Al Viro8687b632006-10-19 23:28:48 -07003252 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003253 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255 *nlink = 1;
3256 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3257 return -EIO;
3258 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003259 p = xdr_inline_decode(xdr, 4);
3260 if (unlikely(!p))
3261 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003262 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003264 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003266 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271}
3272
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003273static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3274 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275{
Al Viro8687b632006-10-19 23:28:48 -07003276 uint32_t len;
3277 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003278 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 *uid = -2;
3281 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3282 return -EIO;
3283 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003284 p = xdr_inline_decode(xdr, 4);
3285 if (unlikely(!p))
3286 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003287 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003288 p = xdr_inline_decode(xdr, len);
3289 if (unlikely(!p))
3290 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003291 if (!may_sleep) {
3292 /* do nothing */
3293 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003294 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3295 ret = NFS_ATTR_FATTR_OWNER;
3296 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003298 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003300 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003301 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3303 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003304 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003305 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003306out_overflow:
3307 print_overflow_msg(__func__, xdr);
3308 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309}
3310
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003311static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3312 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313{
Al Viro8687b632006-10-19 23:28:48 -07003314 uint32_t len;
3315 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003316 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
3318 *gid = -2;
3319 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3320 return -EIO;
3321 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003322 p = xdr_inline_decode(xdr, 4);
3323 if (unlikely(!p))
3324 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003325 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003326 p = xdr_inline_decode(xdr, len);
3327 if (unlikely(!p))
3328 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003329 if (!may_sleep) {
3330 /* do nothing */
3331 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3333 ret = NFS_ATTR_FATTR_GROUP;
3334 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003336 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003338 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003339 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3341 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003342 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003343 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003344out_overflow:
3345 print_overflow_msg(__func__, xdr);
3346 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347}
3348
3349static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3350{
Al Viro8687b632006-10-19 23:28:48 -07003351 uint32_t major = 0, minor = 0;
3352 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354
3355 *rdev = MKDEV(0,0);
3356 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3359 dev_t tmp;
3360
Benny Halevyc0eae662009-08-14 17:20:14 +03003361 p = xdr_inline_decode(xdr, 8);
3362 if (unlikely(!p))
3363 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003364 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003365 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 tmp = MKDEV(major, minor);
3367 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3368 *rdev = tmp;
3369 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003370 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003372 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003373 return ret;
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_avail(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_AVAIL - 1U)))
3386 return -EIO;
3387 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
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_AVAIL;
3393 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003394 dprintk("%s: space avail=%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_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3402{
Al Viro8687b632006-10-19 23:28:48 -07003403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 int status = 0;
3405
3406 *res = 0;
3407 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3408 return -EIO;
3409 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
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, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3415 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003416 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003418out_overflow:
3419 print_overflow_msg(__func__, xdr);
3420 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421}
3422
3423static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3424{
Al Viro8687b632006-10-19 23:28:48 -07003425 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 int status = 0;
3427
3428 *res = 0;
3429 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3430 return -EIO;
3431 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003432 p = xdr_inline_decode(xdr, 8);
3433 if (unlikely(!p))
3434 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003435 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3437 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003438 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003440out_overflow:
3441 print_overflow_msg(__func__, xdr);
3442 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443}
3444
3445static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3446{
Al Viro8687b632006-10-19 23:28:48 -07003447 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
3450 *used = 0;
3451 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3452 return -EIO;
3453 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003454 p = xdr_inline_decode(xdr, 8);
3455 if (unlikely(!p))
3456 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003457 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003459 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003461 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003463 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
3469static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3470{
Al Viro8687b632006-10-19 23:28:48 -07003471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 uint64_t sec;
3473 uint32_t nsec;
3474
Benny Halevyc0eae662009-08-14 17:20:14 +03003475 p = xdr_inline_decode(xdr, 12);
3476 if (unlikely(!p))
3477 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003478 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003479 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 time->tv_sec = (time_t)sec;
3481 time->tv_nsec = (long)nsec;
3482 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003483out_overflow:
3484 print_overflow_msg(__func__, xdr);
3485 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486}
3487
3488static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3489{
3490 int status = 0;
3491
3492 time->tv_sec = 0;
3493 time->tv_nsec = 0;
3494 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3495 return -EIO;
3496 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3497 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003498 if (status == 0)
3499 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3501 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003502 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 return status;
3504}
3505
3506static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3507{
3508 int status = 0;
3509
3510 time->tv_sec = 0;
3511 time->tv_nsec = 0;
3512 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3513 return -EIO;
3514 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3515 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003516 if (status == 0)
3517 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3519 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003520 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 return status;
3522}
3523
3524static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3525{
3526 int status = 0;
3527
3528 time->tv_sec = 0;
3529 time->tv_nsec = 0;
3530 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3531 return -EIO;
3532 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3533 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003534 if (status == 0)
3535 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3537 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003538 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 return status;
3540}
3541
Al Viro8687b632006-10-19 23:28:48 -07003542static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543{
3544 unsigned int attrwords = XDR_QUADLEN(attrlen);
3545 unsigned int nwords = xdr->p - savep;
3546
3547 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003548 dprintk("%s: server returned incorrect attribute length: "
3549 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003550 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 attrwords << 2,
3552 (attrwords < nwords) ? '<' : '>',
3553 nwords << 2);
3554 return -EIO;
3555 }
3556 return 0;
3557}
3558
3559static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3560{
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562
Benny Halevyc0eae662009-08-14 17:20:14 +03003563 p = xdr_inline_decode(xdr, 20);
3564 if (unlikely(!p))
3565 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003566 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003567 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003568 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003570out_overflow:
3571 print_overflow_msg(__func__, xdr);
3572 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573}
3574
3575static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3576{
Al Viro8687b632006-10-19 23:28:48 -07003577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 uint32_t supp, acc;
3579 int status;
3580
3581 status = decode_op_hdr(xdr, OP_ACCESS);
3582 if (status)
3583 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 8);
3585 if (unlikely(!p))
3586 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003587 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003588 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 access->supported = supp;
3590 access->access = acc;
3591 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003592out_overflow:
3593 print_overflow_msg(__func__, xdr);
3594 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595}
3596
Benny Halevy07d30432009-08-14 17:19:52 +03003597static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598{
Al Viro8687b632006-10-19 23:28:48 -07003599 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003600
3601 p = xdr_inline_decode(xdr, len);
3602 if (likely(p)) {
3603 memcpy(buf, p, len);
3604 return 0;
3605 }
3606 print_overflow_msg(__func__, xdr);
3607 return -EIO;
3608}
3609
3610static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3611{
3612 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613}
3614
3615static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 int status;
3618
3619 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003620 if (status != -EIO)
3621 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003622 if (!status)
3623 status = decode_stateid(xdr, &res->stateid);
3624 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625}
3626
Benny Halevydb942bb2009-08-14 17:19:56 +03003627static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3628{
3629 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630}
3631
3632static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 int status;
3635
3636 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003637 if (!status)
3638 status = decode_verifier(xdr, res->verf->verifier);
3639 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640}
3641
3642static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3643{
Al Viro8687b632006-10-19 23:28:48 -07003644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 uint32_t bmlen;
3646 int status;
3647
3648 status = decode_op_hdr(xdr, OP_CREATE);
3649 if (status)
3650 return status;
3651 if ((status = decode_change_info(xdr, cinfo)))
3652 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003653 p = xdr_inline_decode(xdr, 4);
3654 if (unlikely(!p))
3655 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003656 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003657 p = xdr_inline_decode(xdr, bmlen << 2);
3658 if (likely(p))
3659 return 0;
3660out_overflow:
3661 print_overflow_msg(__func__, xdr);
3662 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663}
3664
3665static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3666{
Al Viro8687b632006-10-19 23:28:48 -07003667 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003668 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 int status;
3670
3671 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3672 goto xdr_error;
3673 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3674 goto xdr_error;
3675 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3676 goto xdr_error;
3677 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3678 goto xdr_error;
3679 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3680 goto xdr_error;
3681 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3682 goto xdr_error;
3683 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3684 goto xdr_error;
3685 status = verify_attr_len(xdr, savep, attrlen);
3686xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003687 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 return status;
3689}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003690
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3692{
Al Viro8687b632006-10-19 23:28:48 -07003693 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003694 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003696
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3698 goto xdr_error;
3699 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3700 goto xdr_error;
3701 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3702 goto xdr_error;
3703
3704 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3705 goto xdr_error;
3706 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3707 goto xdr_error;
3708 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3709 goto xdr_error;
3710 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3711 goto xdr_error;
3712 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3713 goto xdr_error;
3714 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3715 goto xdr_error;
3716
3717 status = verify_attr_len(xdr, savep, attrlen);
3718xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003719 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 return status;
3721}
3722
3723static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3724{
Al Viro8687b632006-10-19 23:28:48 -07003725 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003726 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003728
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3730 goto xdr_error;
3731 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3732 goto xdr_error;
3733 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3734 goto xdr_error;
3735
3736 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3737 goto xdr_error;
3738 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3739 goto xdr_error;
3740
3741 status = verify_attr_len(xdr, savep, attrlen);
3742xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003743 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 return status;
3745}
3746
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003747static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3748 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749{
Al Viro8687b632006-10-19 23:28:48 -07003750 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 uint32_t attrlen,
3752 bitmap[2] = {0},
3753 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003754 int status;
3755 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003756 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003758 status = decode_op_hdr(xdr, OP_GETATTR);
3759 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 goto xdr_error;
3761
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003762 status = decode_attr_bitmap(xdr, bitmap);
3763 if (status < 0)
3764 goto xdr_error;
3765
3766 status = decode_attr_length(xdr, &attrlen, &savep);
3767 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 goto xdr_error;
3769
3770
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003771 status = decode_attr_type(xdr, bitmap, &type);
3772 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 fattr->mode = 0;
3775 if (status != 0) {
3776 fattr->mode |= nfs_type2fmt[type];
3777 fattr->valid |= status;
3778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003780 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3781 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003783 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003784
3785 status = decode_attr_size(xdr, bitmap, &fattr->size);
3786 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003788 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003789
3790 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3791 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003793 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003794
3795 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3796 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003798 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003799
3800 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003801 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003802 fattr));
3803 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003804 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003805 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003806
3807 status = decode_attr_mode(xdr, bitmap, &fmode);
3808 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003810 if (status != 0) {
3811 fattr->mode |= fmode;
3812 fattr->valid |= status;
3813 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003814
3815 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3816 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003819
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003820 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3821 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003822 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003824 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003825
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003826 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3827 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003828 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003831
3832 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3833 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003835 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003836
3837 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3838 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003841
3842 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3843 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003845 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003846
3847 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3848 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003850 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003851
3852 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3853 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003855 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003856
3857 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3858 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003859 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003861 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003862 fattr->valid |= status;
3863 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003864
3865 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003867 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 return status;
3869}
3870
3871
3872static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3873{
Al Viro8687b632006-10-19 23:28:48 -07003874 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 uint32_t attrlen, bitmap[2];
3876 int status;
3877
3878 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3879 goto xdr_error;
3880 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3881 goto xdr_error;
3882 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3883 goto xdr_error;
3884
3885 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3886
3887 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3888 goto xdr_error;
3889 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3890 goto xdr_error;
3891 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3892 goto xdr_error;
3893 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3894 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3895 goto xdr_error;
3896 fsinfo->wtpref = fsinfo->wtmax;
3897
3898 status = verify_attr_len(xdr, savep, attrlen);
3899xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 return status;
3902}
3903
3904static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3905{
Al Viro8687b632006-10-19 23:28:48 -07003906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 uint32_t len;
3908 int status;
3909
Trond Myklebust99367812007-07-17 21:52:41 -04003910 /* Zero handle first to allow comparisons */
3911 memset(fh, 0, sizeof(*fh));
3912
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 status = decode_op_hdr(xdr, OP_GETFH);
3914 if (status)
3915 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
Benny Halevyc0eae662009-08-14 17:20:14 +03003917 p = xdr_inline_decode(xdr, 4);
3918 if (unlikely(!p))
3919 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003920 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 if (len > NFS4_FHSIZE)
3922 return -EIO;
3923 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03003924 p = xdr_inline_decode(xdr, len);
3925 if (unlikely(!p))
3926 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03003927 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003929out_overflow:
3930 print_overflow_msg(__func__, xdr);
3931 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932}
3933
3934static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3935{
3936 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003937
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 status = decode_op_hdr(xdr, OP_LINK);
3939 if (status)
3940 return status;
3941 return decode_change_info(xdr, cinfo);
3942}
3943
3944/*
3945 * We create the owner, so we know a proper owner.id length is 4.
3946 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003947static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003949 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003950 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003951 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952
Benny Halevyc0eae662009-08-14 17:20:14 +03003953 p = xdr_inline_decode(xdr, 32);
3954 if (unlikely(!p))
3955 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003956 p = xdr_decode_hyper(p, &offset);
3957 p = xdr_decode_hyper(p, &length);
Benny Halevy6f723f72009-08-14 17:19:37 +03003958 type = be32_to_cpup(p++);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003959 if (fl != NULL) {
3960 fl->fl_start = (loff_t)offset;
3961 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3962 if (length == ~(uint64_t)0)
3963 fl->fl_end = OFFSET_MAX;
3964 fl->fl_type = F_WRLCK;
3965 if (type & 1)
3966 fl->fl_type = F_RDLCK;
3967 fl->fl_pid = 0;
3968 }
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003969 p = xdr_decode_hyper(p, &clientid);
Benny Halevycccddf42009-08-14 17:20:19 +03003970 namelen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003971 p = xdr_inline_decode(xdr, namelen);
3972 if (likely(p))
3973 return -NFS4ERR_DENIED;
3974out_overflow:
3975 print_overflow_msg(__func__, xdr);
3976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003979static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 int status;
3982
3983 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003984 if (status == -EIO)
3985 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03003987 status = decode_stateid(xdr, &res->stateid);
3988 if (unlikely(status))
3989 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003991 status = decode_lock_denied(xdr, NULL);
3992 if (res->open_seqid != NULL)
3993 nfs_increment_open_seqid(status, res->open_seqid);
3994 nfs_increment_lock_seqid(status, res->lock_seqid);
3995out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 return status;
3997}
3998
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003999static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000{
4001 int status;
4002 status = decode_op_hdr(xdr, OP_LOCKT);
4003 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004004 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 return status;
4006}
4007
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004008static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 int status;
4011
4012 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004013 if (status != -EIO)
4014 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004015 if (status == 0)
4016 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 return status;
4018}
4019
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004020static int decode_release_lockowner(struct xdr_stream *xdr)
4021{
4022 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4023}
4024
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025static int decode_lookup(struct xdr_stream *xdr)
4026{
4027 return decode_op_hdr(xdr, OP_LOOKUP);
4028}
4029
4030/* This is too sick! */
4031static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4032{
Andy Adamson05d564f2008-12-23 16:06:15 -05004033 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 uint32_t limit_type, nblocks, blocksize;
4035
Benny Halevyc0eae662009-08-14 17:20:14 +03004036 p = xdr_inline_decode(xdr, 12);
4037 if (unlikely(!p))
4038 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004039 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004041 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004042 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004043 break;
4044 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004045 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004046 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004047 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 }
4049 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004050out_overflow:
4051 print_overflow_msg(__func__, xdr);
4052 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053}
4054
4055static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4056{
Andy Adamson05d564f2008-12-23 16:06:15 -05004057 __be32 *p;
4058 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004059 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060
Benny Halevyc0eae662009-08-14 17:20:14 +03004061 p = xdr_inline_decode(xdr, 4);
4062 if (unlikely(!p))
4063 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004064 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4066 res->delegation_type = 0;
4067 return 0;
4068 }
Benny Halevy07d30432009-08-14 17:19:52 +03004069 status = decode_stateid(xdr, &res->delegation);
4070 if (unlikely(status))
4071 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004072 p = xdr_inline_decode(xdr, 4);
4073 if (unlikely(!p))
4074 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004075 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004076
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004078 case NFS4_OPEN_DELEGATE_READ:
4079 res->delegation_type = FMODE_READ;
4080 break;
4081 case NFS4_OPEN_DELEGATE_WRITE:
4082 res->delegation_type = FMODE_WRITE|FMODE_READ;
4083 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 return -EIO;
4085 }
David Howells7539bba2006-08-22 20:06:09 -04004086 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004087out_overflow:
4088 print_overflow_msg(__func__, xdr);
4089 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090}
4091
4092static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4093{
Andy Adamson05d564f2008-12-23 16:06:15 -05004094 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004095 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004096 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097
Andy Adamson05d564f2008-12-23 16:06:15 -05004098 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004099 if (status != -EIO)
4100 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004101 if (!status)
4102 status = decode_stateid(xdr, &res->stateid);
4103 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004104 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105
Andy Adamson05d564f2008-12-23 16:06:15 -05004106 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107
Benny Halevyc0eae662009-08-14 17:20:14 +03004108 p = xdr_inline_decode(xdr, 8);
4109 if (unlikely(!p))
4110 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004111 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004112 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004113 if (bmlen > 10)
4114 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
Benny Halevyc0eae662009-08-14 17:20:14 +03004116 p = xdr_inline_decode(xdr, bmlen << 2);
4117 if (unlikely(!p))
4118 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004119 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4120 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004121 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004122 for (; i < NFS4_BITMAP_SIZE; i++)
4123 res->attrset[i] = 0;
4124
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 return decode_delegation(xdr, res);
4126xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004127 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004129out_overflow:
4130 print_overflow_msg(__func__, xdr);
4131 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132}
4133
4134static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4135{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 int status;
4137
Andy Adamson05d564f2008-12-23 16:06:15 -05004138 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004139 if (status != -EIO)
4140 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004141 if (!status)
4142 status = decode_stateid(xdr, &res->stateid);
4143 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144}
4145
4146static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4147{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 int status;
4149
4150 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004151 if (status != -EIO)
4152 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004153 if (!status)
4154 status = decode_stateid(xdr, &res->stateid);
4155 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156}
4157
4158static int decode_putfh(struct xdr_stream *xdr)
4159{
4160 return decode_op_hdr(xdr, OP_PUTFH);
4161}
4162
4163static int decode_putrootfh(struct xdr_stream *xdr)
4164{
4165 return decode_op_hdr(xdr, OP_PUTROOTFH);
4166}
4167
4168static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4169{
4170 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 uint32_t count, eof, recvd, hdrlen;
4173 int status;
4174
4175 status = decode_op_hdr(xdr, OP_READ);
4176 if (status)
4177 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004178 p = xdr_inline_decode(xdr, 8);
4179 if (unlikely(!p))
4180 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004181 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004182 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4184 recvd = req->rq_rcv_buf.len - hdrlen;
4185 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004186 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 "count %u > recvd %u\n", count, recvd);
4188 count = recvd;
4189 eof = 0;
4190 }
4191 xdr_read_pages(xdr, count);
4192 res->eof = eof;
4193 res->count = count;
4194 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004195out_overflow:
4196 print_overflow_msg(__func__, xdr);
4197 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198}
4199
4200static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4201{
4202 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4203 struct page *page = *rcvbuf->pages;
4204 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004205 size_t hdrlen;
4206 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07004207 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004208 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04004209 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210
4211 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004212 if (!status)
4213 status = decode_verifier(xdr, readdir->verifier.data);
4214 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004216 dprintk("%s: verifier = %08x:%08x\n",
4217 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004218 ((u32 *)readdir->verifier.data)[0],
4219 ((u32 *)readdir->verifier.data)[1]);
4220
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221
Benny Halevydb942bb2009-08-14 17:19:56 +03004222 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 recvd = rcvbuf->len - hdrlen;
4224 if (pglen > recvd)
4225 pglen = recvd;
4226 xdr_read_pages(xdr, pglen);
4227
4228 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07004229 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04004230 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004232
4233 /* Make sure the packet actually has a value_follows and EOF entry */
4234 if ((entry + 1) > end)
4235 goto short_pkt;
4236
4237 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004238 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04004239 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004241 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 p += 2; /* cookie */
4243 len = ntohl(*p++); /* filename length */
4244 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004245 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4246 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 goto err_unmap;
4248 }
David Howellse8896492006-08-24 15:44:19 -04004249 xlen = XDR_QUADLEN(len);
4250 if (end - p < xlen + 1)
4251 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004252 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04004253 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04004255 if (end - p < len + 1)
4256 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04004259 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04004261 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 entry = p;
4263 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004264 /*
4265 * Apparently some server sends responses that are a valid size, but
4266 * contain no entries, and have value_follows==0 and EOF==0. For
4267 * those, just set the EOF marker.
4268 */
4269 if (!nr && entry[1] == 0) {
4270 dprintk("NFS: readdir reply truncated!\n");
4271 entry[1] = 1;
4272 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05004273out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 kunmap_atomic(kaddr, KM_USER0);
4275 return 0;
4276short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004277 /*
4278 * When we get a short packet there are 2 possibilities. We can
4279 * return an error, or fix up the response to look like a valid
4280 * response and return what we have so far. If there are no
4281 * entries and the packet was short, then return -EIO. If there
4282 * are valid entries in the response, return them and pretend that
4283 * the call was successful, but incomplete. The caller can retry the
4284 * readdir starting at the last cookie.
4285 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07004286 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004288 if (nr)
4289 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290err_unmap:
4291 kunmap_atomic(kaddr, KM_USER0);
4292 return -errno_NFSERR_IO;
4293}
4294
4295static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4296{
4297 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4298 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004299 size_t hdrlen;
4300 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 int status;
4303
4304 status = decode_op_hdr(xdr, OP_READLINK);
4305 if (status)
4306 return status;
4307
4308 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004309 p = xdr_inline_decode(xdr, 4);
4310 if (unlikely(!p))
4311 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004312 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004314 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 return -ENAMETOOLONG;
4316 }
4317 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4318 recvd = req->rq_rcv_buf.len - hdrlen;
4319 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004320 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 "count %u > recvd %u\n", len, recvd);
4322 return -EIO;
4323 }
4324 xdr_read_pages(xdr, len);
4325 /*
4326 * The XDR encode routine has set things up so that
4327 * the link text will be copied directly into the
4328 * buffer. We just have to do overflow-checking,
4329 * and and null-terminate the text (the VFS expects
4330 * null-termination).
4331 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004332 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004334out_overflow:
4335 print_overflow_msg(__func__, xdr);
4336 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337}
4338
4339static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4340{
4341 int status;
4342
4343 status = decode_op_hdr(xdr, OP_REMOVE);
4344 if (status)
4345 goto out;
4346 status = decode_change_info(xdr, cinfo);
4347out:
4348 return status;
4349}
4350
4351static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4352 struct nfs4_change_info *new_cinfo)
4353{
4354 int status;
4355
4356 status = decode_op_hdr(xdr, OP_RENAME);
4357 if (status)
4358 goto out;
4359 if ((status = decode_change_info(xdr, old_cinfo)))
4360 goto out;
4361 status = decode_change_info(xdr, new_cinfo);
4362out:
4363 return status;
4364}
4365
4366static int decode_renew(struct xdr_stream *xdr)
4367{
4368 return decode_op_hdr(xdr, OP_RENEW);
4369}
4370
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004371static int
4372decode_restorefh(struct xdr_stream *xdr)
4373{
4374 return decode_op_hdr(xdr, OP_RESTOREFH);
4375}
4376
J. Bruce Fields029d1052005-06-22 17:16:22 +00004377static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4378 size_t *acl_len)
4379{
Al Viro8687b632006-10-19 23:28:48 -07004380 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004381 uint32_t attrlen,
4382 bitmap[2] = {0};
4383 struct kvec *iov = req->rq_rcv_buf.head;
4384 int status;
4385
4386 *acl_len = 0;
4387 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4388 goto out;
4389 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4390 goto out;
4391 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4392 goto out;
4393
4394 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4395 return -EIO;
4396 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004397 size_t hdrlen;
4398 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004399
4400 /* We ignore &savep and don't do consistency checks on
4401 * the attr length. Let userspace figure it out.... */
4402 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4403 recvd = req->rq_rcv_buf.len - hdrlen;
4404 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004405 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004406 " acl reply: attrlen %u > recvd %u\n",
4407 attrlen, recvd);
4408 return -EINVAL;
4409 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004410 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004411 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004412 } else
4413 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004414
4415out:
4416 return status;
4417}
4418
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419static int
4420decode_savefh(struct xdr_stream *xdr)
4421{
4422 return decode_op_hdr(xdr, OP_SAVEFH);
4423}
4424
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004425static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426{
Al Viro8687b632006-10-19 23:28:48 -07004427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 uint32_t bmlen;
4429 int status;
4430
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 status = decode_op_hdr(xdr, OP_SETATTR);
4432 if (status)
4433 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004434 p = xdr_inline_decode(xdr, 4);
4435 if (unlikely(!p))
4436 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004437 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004438 p = xdr_inline_decode(xdr, bmlen << 2);
4439 if (likely(p))
4440 return 0;
4441out_overflow:
4442 print_overflow_msg(__func__, xdr);
4443 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444}
4445
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004446static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447{
Al Viro8687b632006-10-19 23:28:48 -07004448 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 uint32_t opnum;
4450 int32_t nfserr;
4451
Benny Halevyc0eae662009-08-14 17:20:14 +03004452 p = xdr_inline_decode(xdr, 8);
4453 if (unlikely(!p))
4454 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004455 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004457 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004458 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 return -EIO;
4460 }
Benny Halevycccddf42009-08-14 17:20:19 +03004461 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004463 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4464 if (unlikely(!p))
4465 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004466 p = xdr_decode_hyper(p, &res->clientid);
4467 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 } else if (nfserr == NFSERR_CLID_INUSE) {
4469 uint32_t len;
4470
4471 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004472 p = xdr_inline_decode(xdr, 4);
4473 if (unlikely(!p))
4474 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004475 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004476 p = xdr_inline_decode(xdr, len);
4477 if (unlikely(!p))
4478 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479
4480 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004481 p = xdr_inline_decode(xdr, 4);
4482 if (unlikely(!p))
4483 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004484 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004485 p = xdr_inline_decode(xdr, len);
4486 if (unlikely(!p))
4487 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 return -NFSERR_CLID_INUSE;
4489 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004490 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491
4492 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004493out_overflow:
4494 print_overflow_msg(__func__, xdr);
4495 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496}
4497
4498static int decode_setclientid_confirm(struct xdr_stream *xdr)
4499{
4500 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4501}
4502
4503static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4504{
Al Viro8687b632006-10-19 23:28:48 -07004505 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 int status;
4507
4508 status = decode_op_hdr(xdr, OP_WRITE);
4509 if (status)
4510 return status;
4511
Benny Halevyc0eae662009-08-14 17:20:14 +03004512 p = xdr_inline_decode(xdr, 16);
4513 if (unlikely(!p))
4514 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004515 res->count = be32_to_cpup(p++);
4516 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004517 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004519out_overflow:
4520 print_overflow_msg(__func__, xdr);
4521 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522}
4523
4524static int decode_delegreturn(struct xdr_stream *xdr)
4525{
4526 return decode_op_hdr(xdr, OP_DELEGRETURN);
4527}
4528
Benny Halevy99fe60d2009-04-01 09:22:29 -04004529#if defined(CONFIG_NFS_V4_1)
4530static int decode_exchange_id(struct xdr_stream *xdr,
4531 struct nfs41_exchange_id_res *res)
4532{
4533 __be32 *p;
4534 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004535 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004536 int status;
4537 struct nfs_client *clp = res->client;
4538
4539 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4540 if (status)
4541 return status;
4542
Benny Halevyc0eae662009-08-14 17:20:14 +03004543 p = xdr_inline_decode(xdr, 8);
4544 if (unlikely(!p))
4545 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004546 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004547 p = xdr_inline_decode(xdr, 12);
4548 if (unlikely(!p))
4549 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004550 clp->cl_seqid = be32_to_cpup(p++);
4551 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004552
4553 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004554 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004555 if (dummy != SP4_NONE)
4556 return -EIO;
4557
4558 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004559 p = xdr_inline_decode(xdr, 8);
4560 if (unlikely(!p))
4561 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004562
4563 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004564 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4565 if (unlikely(status))
4566 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004567
4568 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004569 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4570 if (unlikely(status))
4571 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004572
4573 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004574 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4575 if (unlikely(status))
4576 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004577
4578 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004579out_overflow:
4580 print_overflow_msg(__func__, xdr);
4581 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004582}
Andy Adamsonfc931582009-04-01 09:22:31 -04004583
4584static int decode_chan_attrs(struct xdr_stream *xdr,
4585 struct nfs4_channel_attrs *attrs)
4586{
4587 __be32 *p;
4588 u32 nr_attrs;
4589
Benny Halevyc0eae662009-08-14 17:20:14 +03004590 p = xdr_inline_decode(xdr, 28);
4591 if (unlikely(!p))
4592 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004593 attrs->headerpadsz = be32_to_cpup(p++);
4594 attrs->max_rqst_sz = be32_to_cpup(p++);
4595 attrs->max_resp_sz = be32_to_cpup(p++);
4596 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4597 attrs->max_ops = be32_to_cpup(p++);
4598 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004599 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004600 if (unlikely(nr_attrs > 1)) {
4601 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4602 __func__, nr_attrs);
4603 return -EINVAL;
4604 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004605 if (nr_attrs == 1) {
4606 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4607 if (unlikely(!p))
4608 goto out_overflow;
4609 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004610 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004611out_overflow:
4612 print_overflow_msg(__func__, xdr);
4613 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004614}
4615
Benny Halevye78291e2009-08-14 17:20:00 +03004616static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4617{
4618 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004619}
4620
4621static int decode_create_session(struct xdr_stream *xdr,
4622 struct nfs41_create_session_res *res)
4623{
4624 __be32 *p;
4625 int status;
4626 struct nfs_client *clp = res->client;
4627 struct nfs4_session *session = clp->cl_session;
4628
4629 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004630 if (!status)
4631 status = decode_sessionid(xdr, &session->sess_id);
4632 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004633 return status;
4634
Andy Adamsonfc931582009-04-01 09:22:31 -04004635 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004636 p = xdr_inline_decode(xdr, 8);
4637 if (unlikely(!p))
4638 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004639 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004640 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004641
4642 /* Channel attributes */
4643 status = decode_chan_attrs(xdr, &session->fc_attrs);
4644 if (!status)
4645 status = decode_chan_attrs(xdr, &session->bc_attrs);
4646 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004647out_overflow:
4648 print_overflow_msg(__func__, xdr);
4649 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004650}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004651
4652static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4653{
4654 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4655}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004656
4657static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4658{
4659 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4660}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004661#endif /* CONFIG_NFS_V4_1 */
4662
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004663static int decode_sequence(struct xdr_stream *xdr,
4664 struct nfs4_sequence_res *res,
4665 struct rpc_rqst *rqstp)
4666{
4667#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004668 struct nfs4_sessionid id;
4669 u32 dummy;
4670 int status;
4671 __be32 *p;
4672
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004673 if (!res->sr_session)
4674 return 0;
4675
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004676 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004677 if (!status)
4678 status = decode_sessionid(xdr, &id);
4679 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004680 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004681
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004682 /*
4683 * If the server returns different values for sessionID, slotID or
4684 * sequence number, the server is looney tunes.
4685 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004686 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004687
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004688 if (memcmp(id.data, res->sr_session->sess_id.data,
4689 NFS4_MAX_SESSIONID_LEN)) {
4690 dprintk("%s Invalid session id\n", __func__);
4691 goto out_err;
4692 }
Benny Halevye78291e2009-08-14 17:20:00 +03004693
Benny Halevyc0eae662009-08-14 17:20:14 +03004694 p = xdr_inline_decode(xdr, 20);
4695 if (unlikely(!p))
4696 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004697
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004698 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004699 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004700 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004701 dprintk("%s Invalid sequence number\n", __func__);
4702 goto out_err;
4703 }
4704 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004705 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004706 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004707 dprintk("%s Invalid slot id\n", __func__);
4708 goto out_err;
4709 }
4710 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004711 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004712 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004713 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004714 /* result flags */
4715 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004716 status = 0;
4717out_err:
4718 res->sr_status = status;
4719 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004720out_overflow:
4721 print_overflow_msg(__func__, xdr);
4722 status = -EIO;
4723 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004724#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004725 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004726#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004727}
4728
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729/*
Benny Halevy49c25592008-12-23 16:06:16 -05004730 * END OF "GENERIC" DECODE ROUTINES.
4731 */
4732
4733/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 * Decode OPEN_DOWNGRADE response
4735 */
Al Viro8687b632006-10-19 23:28:48 -07004736static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737{
Andy Adamson05d564f2008-12-23 16:06:15 -05004738 struct xdr_stream xdr;
4739 struct compound_hdr hdr;
4740 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741
Andy Adamson05d564f2008-12-23 16:06:15 -05004742 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4743 status = decode_compound_hdr(&xdr, &hdr);
4744 if (status)
4745 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004746 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4747 if (status)
4748 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004749 status = decode_putfh(&xdr);
4750 if (status)
4751 goto out;
4752 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004753 if (status != 0)
4754 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004755 decode_getfattr(&xdr, res->fattr, res->server,
4756 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004758 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759}
4760
4761/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 * Decode ACCESS response
4763 */
Al Viro8687b632006-10-19 23:28:48 -07004764static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765{
4766 struct xdr_stream xdr;
4767 struct compound_hdr hdr;
4768 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004769
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004771 status = decode_compound_hdr(&xdr, &hdr);
4772 if (status)
4773 goto out;
4774 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4775 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004777 status = decode_putfh(&xdr);
4778 if (status != 0)
4779 goto out;
4780 status = decode_access(&xdr, res);
4781 if (status != 0)
4782 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004783 decode_getfattr(&xdr, res->fattr, res->server,
4784 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785out:
4786 return status;
4787}
4788
4789/*
4790 * Decode LOOKUP response
4791 */
Al Viro8687b632006-10-19 23:28:48 -07004792static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793{
4794 struct xdr_stream xdr;
4795 struct compound_hdr hdr;
4796 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004797
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004799 status = decode_compound_hdr(&xdr, &hdr);
4800 if (status)
4801 goto out;
4802 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4803 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 goto out;
4805 if ((status = decode_putfh(&xdr)) != 0)
4806 goto out;
4807 if ((status = decode_lookup(&xdr)) != 0)
4808 goto out;
4809 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4810 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004811 status = decode_getfattr(&xdr, res->fattr, res->server
4812 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813out:
4814 return status;
4815}
4816
4817/*
4818 * Decode LOOKUP_ROOT response
4819 */
Al Viro8687b632006-10-19 23:28:48 -07004820static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821{
4822 struct xdr_stream xdr;
4823 struct compound_hdr hdr;
4824 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004825
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004827 status = decode_compound_hdr(&xdr, &hdr);
4828 if (status)
4829 goto out;
4830 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4831 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832 goto out;
4833 if ((status = decode_putrootfh(&xdr)) != 0)
4834 goto out;
4835 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004836 status = decode_getfattr(&xdr, res->fattr, res->server,
4837 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838out:
4839 return status;
4840}
4841
4842/*
4843 * Decode REMOVE response
4844 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004845static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846{
4847 struct xdr_stream xdr;
4848 struct compound_hdr hdr;
4849 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004850
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004852 status = decode_compound_hdr(&xdr, &hdr);
4853 if (status)
4854 goto out;
4855 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4856 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004858 if ((status = decode_putfh(&xdr)) != 0)
4859 goto out;
4860 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4861 goto out;
Trond Myklebustd3468902010-04-16 16:22:50 -04004862 decode_getfattr(&xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004863 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864out:
4865 return status;
4866}
4867
4868/*
4869 * Decode RENAME response
4870 */
Jeff Laytone8582a82010-09-17 17:31:06 -04004871static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872{
4873 struct xdr_stream xdr;
4874 struct compound_hdr hdr;
4875 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004876
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004878 status = decode_compound_hdr(&xdr, &hdr);
4879 if (status)
4880 goto out;
4881 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4882 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 goto out;
4884 if ((status = decode_putfh(&xdr)) != 0)
4885 goto out;
4886 if ((status = decode_savefh(&xdr)) != 0)
4887 goto out;
4888 if ((status = decode_putfh(&xdr)) != 0)
4889 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004890 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4891 goto out;
4892 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004893 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4894 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004895 goto out;
4896 if ((status = decode_restorefh(&xdr)) != 0)
4897 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004898 decode_getfattr(&xdr, res->old_fattr, res->server,
4899 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900out:
4901 return status;
4902}
4903
4904/*
4905 * Decode LINK response
4906 */
Al Viro8687b632006-10-19 23:28:48 -07004907static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908{
4909 struct xdr_stream xdr;
4910 struct compound_hdr hdr;
4911 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004912
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004914 status = decode_compound_hdr(&xdr, &hdr);
4915 if (status)
4916 goto out;
4917 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4918 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 goto out;
4920 if ((status = decode_putfh(&xdr)) != 0)
4921 goto out;
4922 if ((status = decode_savefh(&xdr)) != 0)
4923 goto out;
4924 if ((status = decode_putfh(&xdr)) != 0)
4925 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004926 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4927 goto out;
4928 /*
4929 * Note order: OP_LINK leaves the directory as the current
4930 * filehandle.
4931 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004932 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4933 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004934 goto out;
4935 if ((status = decode_restorefh(&xdr)) != 0)
4936 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004937 decode_getfattr(&xdr, res->fattr, res->server,
4938 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939out:
4940 return status;
4941}
4942
4943/*
4944 * Decode CREATE response
4945 */
Al Viro8687b632006-10-19 23:28:48 -07004946static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947{
4948 struct xdr_stream xdr;
4949 struct compound_hdr hdr;
4950 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004951
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004953 status = decode_compound_hdr(&xdr, &hdr);
4954 if (status)
4955 goto out;
4956 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4957 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 goto out;
4959 if ((status = decode_putfh(&xdr)) != 0)
4960 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004961 if ((status = decode_savefh(&xdr)) != 0)
4962 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4964 goto out;
4965 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4966 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004967 if (decode_getfattr(&xdr, res->fattr, res->server,
4968 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004969 goto out;
4970 if ((status = decode_restorefh(&xdr)) != 0)
4971 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004972 decode_getfattr(&xdr, res->dir_fattr, res->server,
4973 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974out:
4975 return status;
4976}
4977
4978/*
4979 * Decode SYMLINK response
4980 */
Al Viro8687b632006-10-19 23:28:48 -07004981static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982{
4983 return nfs4_xdr_dec_create(rqstp, p, res);
4984}
4985
4986/*
4987 * Decode GETATTR response
4988 */
Al Viro8687b632006-10-19 23:28:48 -07004989static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990{
4991 struct xdr_stream xdr;
4992 struct compound_hdr hdr;
4993 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004994
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4996 status = decode_compound_hdr(&xdr, &hdr);
4997 if (status)
4998 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004999 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5000 if (status)
5001 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 status = decode_putfh(&xdr);
5003 if (status)
5004 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005005 status = decode_getfattr(&xdr, res->fattr, res->server,
5006 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007out:
5008 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009}
5010
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005011/*
5012 * Encode an SETACL request
5013 */
5014static int
Al Viro8687b632006-10-19 23:28:48 -07005015nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005016{
Andy Adamson05d564f2008-12-23 16:06:15 -05005017 struct xdr_stream xdr;
5018 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005019 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005020 };
5021 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005022
Andy Adamson05d564f2008-12-23 16:06:15 -05005023 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04005024 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005025 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05005026 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005027 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005028 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005029 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005030}
Andy Adamson05d564f2008-12-23 16:06:15 -05005031
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005032/*
5033 * Decode SETACL response
5034 */
5035static int
Benny Halevy73c403a2009-04-01 09:22:01 -04005036nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
5037 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005038{
5039 struct xdr_stream xdr;
5040 struct compound_hdr hdr;
5041 int status;
5042
5043 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5044 status = decode_compound_hdr(&xdr, &hdr);
5045 if (status)
5046 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005047 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5048 if (status)
5049 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005050 status = decode_putfh(&xdr);
5051 if (status)
5052 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005053 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005054out:
5055 return status;
5056}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057
5058/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005059 * Decode GETACL response
5060 */
5061static int
Benny Halevy663c79b2009-04-01 09:21:59 -04005062nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
5063 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005064{
5065 struct xdr_stream xdr;
5066 struct compound_hdr hdr;
5067 int status;
5068
5069 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5070 status = decode_compound_hdr(&xdr, &hdr);
5071 if (status)
5072 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005073 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5074 if (status)
5075 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005076 status = decode_putfh(&xdr);
5077 if (status)
5078 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04005079 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005080
5081out:
5082 return status;
5083}
5084
5085/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 * Decode CLOSE response
5087 */
Al Viro8687b632006-10-19 23:28:48 -07005088static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089{
Andy Adamson05d564f2008-12-23 16:06:15 -05005090 struct xdr_stream xdr;
5091 struct compound_hdr hdr;
5092 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Andy Adamson05d564f2008-12-23 16:06:15 -05005094 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5095 status = decode_compound_hdr(&xdr, &hdr);
5096 if (status)
5097 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005098 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5099 if (status)
5100 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005101 status = decode_putfh(&xdr);
5102 if (status)
5103 goto out;
5104 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005105 if (status != 0)
5106 goto out;
5107 /*
5108 * Note: Server may do delete on close for this file
5109 * in which case the getattr call will fail with
5110 * an ESTALE error. Shouldn't be a problem,
5111 * though, since fattr->valid will remain unset.
5112 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005113 decode_getfattr(&xdr, res->fattr, res->server,
5114 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005116 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117}
5118
5119/*
5120 * Decode OPEN response
5121 */
Al Viro8687b632006-10-19 23:28:48 -07005122static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123{
Andy Adamson05d564f2008-12-23 16:06:15 -05005124 struct xdr_stream xdr;
5125 struct compound_hdr hdr;
5126 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127
Andy Adamson05d564f2008-12-23 16:06:15 -05005128 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5129 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005130 if (status)
5131 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005132 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5133 if (status)
5134 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005135 status = decode_putfh(&xdr);
5136 if (status)
5137 goto out;
5138 status = decode_savefh(&xdr);
5139 if (status)
5140 goto out;
5141 status = decode_open(&xdr, res);
5142 if (status)
5143 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005144 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005146 if (decode_getfattr(&xdr, res->f_attr, res->server,
5147 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005148 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005149 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005150 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005151 decode_getfattr(&xdr, res->dir_attr, res->server,
5152 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005154 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155}
5156
5157/*
5158 * Decode OPEN_CONFIRM response
5159 */
Al Viro8687b632006-10-19 23:28:48 -07005160static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161{
Andy Adamson05d564f2008-12-23 16:06:15 -05005162 struct xdr_stream xdr;
5163 struct compound_hdr hdr;
5164 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165
Andy Adamson05d564f2008-12-23 16:06:15 -05005166 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5167 status = decode_compound_hdr(&xdr, &hdr);
5168 if (status)
5169 goto out;
5170 status = decode_putfh(&xdr);
5171 if (status)
5172 goto out;
5173 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005175 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176}
5177
5178/*
5179 * Decode OPEN response
5180 */
Al Viro8687b632006-10-19 23:28:48 -07005181static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182{
Andy Adamson05d564f2008-12-23 16:06:15 -05005183 struct xdr_stream xdr;
5184 struct compound_hdr hdr;
5185 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186
Andy Adamson05d564f2008-12-23 16:06:15 -05005187 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5188 status = decode_compound_hdr(&xdr, &hdr);
5189 if (status)
5190 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005191 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5192 if (status)
5193 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005194 status = decode_putfh(&xdr);
5195 if (status)
5196 goto out;
5197 status = decode_open(&xdr, res);
5198 if (status)
5199 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005200 decode_getfattr(&xdr, res->f_attr, res->server,
5201 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005203 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204}
5205
5206/*
5207 * Decode SETATTR response
5208 */
Al Viro8687b632006-10-19 23:28:48 -07005209static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210{
Andy Adamson05d564f2008-12-23 16:06:15 -05005211 struct xdr_stream xdr;
5212 struct compound_hdr hdr;
5213 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214
Andy Adamson05d564f2008-12-23 16:06:15 -05005215 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5216 status = decode_compound_hdr(&xdr, &hdr);
5217 if (status)
5218 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005219 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5220 if (status)
5221 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005222 status = decode_putfh(&xdr);
5223 if (status)
5224 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005225 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005226 if (status)
5227 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005228 decode_getfattr(&xdr, res->fattr, res->server,
5229 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005231 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232}
5233
5234/*
5235 * Decode LOCK response
5236 */
Al Viro8687b632006-10-19 23:28:48 -07005237static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238{
5239 struct xdr_stream xdr;
5240 struct compound_hdr hdr;
5241 int status;
5242
5243 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5244 status = decode_compound_hdr(&xdr, &hdr);
5245 if (status)
5246 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005247 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5248 if (status)
5249 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 status = decode_putfh(&xdr);
5251 if (status)
5252 goto out;
5253 status = decode_lock(&xdr, res);
5254out:
5255 return status;
5256}
5257
5258/*
5259 * Decode LOCKT response
5260 */
Al Viro8687b632006-10-19 23:28:48 -07005261static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262{
5263 struct xdr_stream xdr;
5264 struct compound_hdr hdr;
5265 int status;
5266
5267 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5268 status = decode_compound_hdr(&xdr, &hdr);
5269 if (status)
5270 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005271 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5272 if (status)
5273 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 status = decode_putfh(&xdr);
5275 if (status)
5276 goto out;
5277 status = decode_lockt(&xdr, res);
5278out:
5279 return status;
5280}
5281
5282/*
5283 * Decode LOCKU response
5284 */
Al Viro8687b632006-10-19 23:28:48 -07005285static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286{
5287 struct xdr_stream xdr;
5288 struct compound_hdr hdr;
5289 int status;
5290
5291 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5292 status = decode_compound_hdr(&xdr, &hdr);
5293 if (status)
5294 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005295 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5296 if (status)
5297 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 status = decode_putfh(&xdr);
5299 if (status)
5300 goto out;
5301 status = decode_locku(&xdr, res);
5302out:
5303 return status;
5304}
5305
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005306static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
5307{
5308 struct xdr_stream xdr;
5309 struct compound_hdr hdr;
5310 int status;
5311
5312 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5313 status = decode_compound_hdr(&xdr, &hdr);
5314 if (!status)
5315 status = decode_release_lockowner(&xdr);
5316 return status;
5317}
5318
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319/*
5320 * Decode READLINK response
5321 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005322static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5323 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324{
5325 struct xdr_stream xdr;
5326 struct compound_hdr hdr;
5327 int status;
5328
5329 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5330 status = decode_compound_hdr(&xdr, &hdr);
5331 if (status)
5332 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005333 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5334 if (status)
5335 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 status = decode_putfh(&xdr);
5337 if (status)
5338 goto out;
5339 status = decode_readlink(&xdr, rqstp);
5340out:
5341 return status;
5342}
5343
5344/*
5345 * Decode READDIR response
5346 */
Al Viro8687b632006-10-19 23:28:48 -07005347static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348{
5349 struct xdr_stream xdr;
5350 struct compound_hdr hdr;
5351 int status;
5352
5353 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5354 status = decode_compound_hdr(&xdr, &hdr);
5355 if (status)
5356 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005357 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5358 if (status)
5359 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 status = decode_putfh(&xdr);
5361 if (status)
5362 goto out;
5363 status = decode_readdir(&xdr, rqstp, res);
5364out:
5365 return status;
5366}
5367
5368/*
5369 * Decode Read response
5370 */
Al Viro8687b632006-10-19 23:28:48 -07005371static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372{
5373 struct xdr_stream xdr;
5374 struct compound_hdr hdr;
5375 int status;
5376
5377 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5378 status = decode_compound_hdr(&xdr, &hdr);
5379 if (status)
5380 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005381 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5382 if (status)
5383 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 status = decode_putfh(&xdr);
5385 if (status)
5386 goto out;
5387 status = decode_read(&xdr, rqstp, res);
5388 if (!status)
5389 status = res->count;
5390out:
5391 return status;
5392}
5393
5394/*
5395 * Decode WRITE response
5396 */
Al Viro8687b632006-10-19 23:28:48 -07005397static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398{
5399 struct xdr_stream xdr;
5400 struct compound_hdr hdr;
5401 int status;
5402
5403 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5404 status = decode_compound_hdr(&xdr, &hdr);
5405 if (status)
5406 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005407 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5408 if (status)
5409 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410 status = decode_putfh(&xdr);
5411 if (status)
5412 goto out;
5413 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005414 if (status)
5415 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005416 decode_getfattr(&xdr, res->fattr, res->server,
5417 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418 if (!status)
5419 status = res->count;
5420out:
5421 return status;
5422}
5423
5424/*
5425 * Decode COMMIT response
5426 */
Al Viro8687b632006-10-19 23:28:48 -07005427static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428{
5429 struct xdr_stream xdr;
5430 struct compound_hdr hdr;
5431 int status;
5432
5433 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5434 status = decode_compound_hdr(&xdr, &hdr);
5435 if (status)
5436 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005437 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5438 if (status)
5439 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 status = decode_putfh(&xdr);
5441 if (status)
5442 goto out;
5443 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005444 if (status)
5445 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005446 decode_getfattr(&xdr, res->fattr, res->server,
5447 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448out:
5449 return status;
5450}
5451
5452/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005453 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005455static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5456 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005457{
5458 struct xdr_stream xdr;
5459 struct compound_hdr hdr;
5460 int status;
5461
5462 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5463 status = decode_compound_hdr(&xdr, &hdr);
5464 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005465 status = decode_sequence(&xdr, &res->seq_res, req);
5466 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467 status = decode_putfh(&xdr);
5468 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005469 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470 return status;
5471}
5472
5473/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005474 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005476static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5477 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478{
5479 struct xdr_stream xdr;
5480 struct compound_hdr hdr;
5481 int status;
5482
5483 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5484 status = decode_compound_hdr(&xdr, &hdr);
5485 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005486 status = decode_sequence(&xdr, &res->seq_res, req);
5487 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488 status = decode_putfh(&xdr);
5489 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005490 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491 return status;
5492}
5493
5494/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005495 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005496 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005497static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5498 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499{
5500 struct xdr_stream xdr;
5501 struct compound_hdr hdr;
5502 int status;
5503
5504 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5505 status = decode_compound_hdr(&xdr, &hdr);
5506 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005507 status = decode_sequence(&xdr, &res->seq_res, req);
5508 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509 status = decode_putfh(&xdr);
5510 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005511 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512 return status;
5513}
5514
5515/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005516 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517 */
Al Viro8687b632006-10-19 23:28:48 -07005518static 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 -07005519{
5520 struct xdr_stream xdr;
5521 struct compound_hdr hdr;
5522 int status;
5523
5524 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005525 status = decode_compound_hdr(&xdr, &hdr);
5526 if (status)
5527 goto out;
5528 status = decode_sequence(&xdr, &res->seq_res, req);
5529 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530 goto out;
5531 if ((status = decode_putfh(&xdr)) != 0)
5532 goto out;
5533 status = decode_server_caps(&xdr, res);
5534out:
5535 return status;
5536}
5537
5538/*
5539 * Decode RENEW response
5540 */
Al Viro8687b632006-10-19 23:28:48 -07005541static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542{
5543 struct xdr_stream xdr;
5544 struct compound_hdr hdr;
5545 int status;
5546
5547 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5548 status = decode_compound_hdr(&xdr, &hdr);
5549 if (!status)
5550 status = decode_renew(&xdr);
5551 return status;
5552}
5553
5554/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005555 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556 */
Al Viro8687b632006-10-19 23:28:48 -07005557static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005558 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559{
5560 struct xdr_stream xdr;
5561 struct compound_hdr hdr;
5562 int status;
5563
5564 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5565 status = decode_compound_hdr(&xdr, &hdr);
5566 if (!status)
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005567 status = decode_setclientid(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568 return status;
5569}
5570
5571/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005572 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573 */
Al Viro8687b632006-10-19 23:28:48 -07005574static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575{
5576 struct xdr_stream xdr;
5577 struct compound_hdr hdr;
5578 int status;
5579
5580 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5581 status = decode_compound_hdr(&xdr, &hdr);
5582 if (!status)
5583 status = decode_setclientid_confirm(&xdr);
5584 if (!status)
5585 status = decode_putrootfh(&xdr);
5586 if (!status)
5587 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588 return status;
5589}
5590
5591/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005592 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005593 */
Al Viro8687b632006-10-19 23:28:48 -07005594static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005595{
5596 struct xdr_stream xdr;
5597 struct compound_hdr hdr;
5598 int status;
5599
5600 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5601 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005602 if (status)
5603 goto out;
5604 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5605 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005606 goto out;
5607 status = decode_putfh(&xdr);
5608 if (status != 0)
5609 goto out;
5610 status = decode_delegreturn(&xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005611 if (status != 0)
5612 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005613 decode_getfattr(&xdr, res->fattr, res->server,
5614 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005615out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 return status;
5617}
5618
Trond Myklebust683b57b2006-06-09 09:34:22 -04005619/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005620 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005621 */
Benny Halevy22958462009-04-01 09:22:02 -04005622static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5623 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005624{
5625 struct xdr_stream xdr;
5626 struct compound_hdr hdr;
5627 int status;
5628
5629 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5630 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005631 if (status)
5632 goto out;
5633 status = decode_sequence(&xdr, &res->seq_res, req);
5634 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005635 goto out;
5636 if ((status = decode_putfh(&xdr)) != 0)
5637 goto out;
5638 if ((status = decode_lookup(&xdr)) != 0)
5639 goto out;
5640 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005641 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005642 res->fs_locations->server,
5643 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005644out:
5645 return status;
5646}
5647
Benny Halevy99fe60d2009-04-01 09:22:29 -04005648#if defined(CONFIG_NFS_V4_1)
5649/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005650 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005651 */
5652static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5653 void *res)
5654{
5655 struct xdr_stream xdr;
5656 struct compound_hdr hdr;
5657 int status;
5658
5659 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5660 status = decode_compound_hdr(&xdr, &hdr);
5661 if (!status)
5662 status = decode_exchange_id(&xdr, res);
5663 return status;
5664}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005665
5666/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005667 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005668 */
5669static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5670 struct nfs41_create_session_res *res)
5671{
5672 struct xdr_stream xdr;
5673 struct compound_hdr hdr;
5674 int status;
5675
5676 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5677 status = decode_compound_hdr(&xdr, &hdr);
5678 if (!status)
5679 status = decode_create_session(&xdr, res);
5680 return status;
5681}
5682
5683/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005684 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005685 */
5686static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5687 void *dummy)
5688{
5689 struct xdr_stream xdr;
5690 struct compound_hdr hdr;
5691 int status;
5692
5693 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5694 status = decode_compound_hdr(&xdr, &hdr);
5695 if (!status)
5696 status = decode_destroy_session(&xdr, dummy);
5697 return status;
5698}
5699
5700/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005701 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005702 */
5703static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5704 struct nfs4_sequence_res *res)
5705{
5706 struct xdr_stream xdr;
5707 struct compound_hdr hdr;
5708 int status;
5709
5710 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5711 status = decode_compound_hdr(&xdr, &hdr);
5712 if (!status)
5713 status = decode_sequence(&xdr, res, rqstp);
5714 return status;
5715}
5716
5717/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005718 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005719 */
5720static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5721 struct nfs4_get_lease_time_res *res)
5722{
5723 struct xdr_stream xdr;
5724 struct compound_hdr hdr;
5725 int status;
5726
5727 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5728 status = decode_compound_hdr(&xdr, &hdr);
5729 if (!status)
5730 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5731 if (!status)
5732 status = decode_putrootfh(&xdr);
5733 if (!status)
5734 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5735 return status;
5736}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005737
5738/*
5739 * Decode RECLAIM_COMPLETE response
5740 */
5741static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p,
5742 struct nfs41_reclaim_complete_res *res)
5743{
5744 struct xdr_stream xdr;
5745 struct compound_hdr hdr;
5746 int status;
5747
5748 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5749 status = decode_compound_hdr(&xdr, &hdr);
5750 if (!status)
5751 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5752 if (!status)
5753 status = decode_reclaim_complete(&xdr, (void *)NULL);
5754 return status;
5755}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005756#endif /* CONFIG_NFS_V4_1 */
5757
Al Viro0dbb4c62006-10-19 23:28:49 -07005758__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759{
5760 uint32_t bitmap[2] = {0};
5761 uint32_t len;
5762
5763 if (!*p++) {
5764 if (!*p)
5765 return ERR_PTR(-EAGAIN);
5766 entry->eof = 1;
5767 return ERR_PTR(-EBADCOOKIE);
5768 }
5769
5770 entry->prev_cookie = entry->cookie;
5771 p = xdr_decode_hyper(p, &entry->cookie);
5772 entry->len = ntohl(*p++);
5773 entry->name = (const char *) p;
5774 p += XDR_QUADLEN(entry->len);
5775
5776 /*
5777 * In case the server doesn't return an inode number,
5778 * we fake one here. (We don't use inode number 0,
5779 * since glibc seems to choke on it...)
5780 */
5781 entry->ino = 1;
5782
5783 len = ntohl(*p++); /* bitmap length */
5784 if (len-- > 0) {
5785 bitmap[0] = ntohl(*p++);
5786 if (len-- > 0) {
5787 bitmap[1] = ntohl(*p++);
5788 p += len;
5789 }
5790 }
5791 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5792 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005793 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5794 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5795 /* Ignore the return value of rdattr_error for now */
5796 p++;
5797 len--;
5798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5800 xdr_decode_hyper(p, &entry->ino);
5801 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5802 xdr_decode_hyper(p, &entry->ino);
5803 p += len;
5804 }
5805
5806 entry->eof = !p[0] && p[1];
5807 return p;
5808}
5809
5810/*
5811 * We need to translate between nfs status return values and
5812 * the local errno values which may not be the same.
5813 */
5814static struct {
5815 int stat;
5816 int errno;
5817} nfs_errtbl[] = {
5818 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005819 { NFS4ERR_PERM, -EPERM },
5820 { NFS4ERR_NOENT, -ENOENT },
5821 { NFS4ERR_IO, -errno_NFSERR_IO},
5822 { NFS4ERR_NXIO, -ENXIO },
5823 { NFS4ERR_ACCESS, -EACCES },
5824 { NFS4ERR_EXIST, -EEXIST },
5825 { NFS4ERR_XDEV, -EXDEV },
5826 { NFS4ERR_NOTDIR, -ENOTDIR },
5827 { NFS4ERR_ISDIR, -EISDIR },
5828 { NFS4ERR_INVAL, -EINVAL },
5829 { NFS4ERR_FBIG, -EFBIG },
5830 { NFS4ERR_NOSPC, -ENOSPC },
5831 { NFS4ERR_ROFS, -EROFS },
5832 { NFS4ERR_MLINK, -EMLINK },
5833 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5834 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5835 { NFS4ERR_DQUOT, -EDQUOT },
5836 { NFS4ERR_STALE, -ESTALE },
5837 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5838 { NFS4ERR_BADOWNER, -EINVAL },
5839 { NFS4ERR_BADNAME, -EINVAL },
5840 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5841 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5842 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005843 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03005844 { NFS4ERR_BADTYPE, -EBADTYPE },
5845 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005846 { NFS4ERR_SYMLINK, -ELOOP },
5847 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5848 { NFS4ERR_DEADLOCK, -EDEADLK },
5849 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 * to be handled by a
5851 * middle-layer.
5852 */
Benny Halevy856dff32008-03-31 17:39:06 +03005853 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854};
5855
5856/*
5857 * Convert an NFS error code to a local one.
5858 * This one is used jointly by NFSv2 and NFSv3.
5859 */
5860static int
David Howells0a8ea432006-08-22 20:06:08 -04005861nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862{
5863 int i;
5864 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5865 if (nfs_errtbl[i].stat == stat)
5866 return nfs_errtbl[i].errno;
5867 }
5868 if (stat <= 10000 || stat > 10100) {
5869 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005870 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871 }
5872 /* If we cannot translate the error, the recovery routines should
5873 * handle it.
5874 * Note: remaining NFSv4 error codes have values > 10000, so should
5875 * not conflict with native Linux error codes.
5876 */
Benny Halevy856dff32008-03-31 17:39:06 +03005877 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878}
5879
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880#define PROC(proc, argtype, restype) \
5881[NFSPROC4_CLNT_##proc] = { \
5882 .p_proc = NFSPROC4_COMPOUND, \
5883 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5884 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005885 .p_arglen = NFS4_##argtype##_sz, \
5886 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005887 .p_statidx = NFSPROC4_CLNT_##proc, \
5888 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005889}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890
5891struct rpc_procinfo nfs4_procedures[] = {
5892 PROC(READ, enc_read, dec_read),
5893 PROC(WRITE, enc_write, dec_write),
5894 PROC(COMMIT, enc_commit, dec_commit),
5895 PROC(OPEN, enc_open, dec_open),
5896 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5897 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5898 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5899 PROC(CLOSE, enc_close, dec_close),
5900 PROC(SETATTR, enc_setattr, dec_setattr),
5901 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5902 PROC(RENEW, enc_renew, dec_renew),
5903 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5904 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5905 PROC(LOCK, enc_lock, dec_lock),
5906 PROC(LOCKT, enc_lockt, dec_lockt),
5907 PROC(LOCKU, enc_locku, dec_locku),
5908 PROC(ACCESS, enc_access, dec_access),
5909 PROC(GETATTR, enc_getattr, dec_getattr),
5910 PROC(LOOKUP, enc_lookup, dec_lookup),
5911 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5912 PROC(REMOVE, enc_remove, dec_remove),
5913 PROC(RENAME, enc_rename, dec_rename),
5914 PROC(LINK, enc_link, dec_link),
5915 PROC(SYMLINK, enc_symlink, dec_symlink),
5916 PROC(CREATE, enc_create, dec_create),
5917 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5918 PROC(STATFS, enc_statfs, dec_statfs),
5919 PROC(READLINK, enc_readlink, dec_readlink),
5920 PROC(READDIR, enc_readdir, dec_readdir),
5921 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5922 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005923 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005924 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005925 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005926 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005927#if defined(CONFIG_NFS_V4_1)
5928 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005929 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005930 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005931 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005932 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Ricardo Labiaga180197532009-12-05 16:08:40 -05005933 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005934#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935};
5936
5937struct rpc_version nfs_version4 = {
5938 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005939 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 .procs = nfs4_procedures
5941};
5942
5943/*
5944 * Local variables:
5945 * c-basic-offset: 8
5946 * End:
5947 */