blob: 8b4dfa393f0f0cd27e3a39b59ceb58e885600549 [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) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400819 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
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) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400831 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
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{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001388 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001389 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001390 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001392 if (readdir->plus) {
1393 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1394 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1395 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1396 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1397 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1398 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001399 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001400 }
1401 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1402 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001403 /* Switch to mounted_on_fileid if the server supports it */
1404 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1405 attrs[0] &= ~FATTR4_WORD0_FILEID;
1406 else
1407 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001408
Benny Halevy13c65ce2009-08-14 17:19:25 +03001409 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001410 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001411 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001412 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001413 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001414 *p++ = cpu_to_be32(readdir->count);
1415 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001416
Benny Halevye75bc1c2009-08-14 17:18:54 +03001417 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001419 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001420 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001421 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1422 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001423 (unsigned long long)readdir->cookie,
1424 ((u32 *)readdir->verifier.data)[0],
1425 ((u32 *)readdir->verifier.data)[1],
1426 attrs[0] & readdir->bitmask[0],
1427 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001430static 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 -07001431{
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Benny Halevy13c65ce2009-08-14 17:19:25 +03001434 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001435 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001436 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001437 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001440static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, 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 Halevy13c65ce2009-08-14 17:19:25 +03001444 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001445 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001446 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001447 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001448 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001451static 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 -07001452{
Al Viro8687b632006-10-19 23:28:48 -07001453 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Benny Halevy811652b2009-08-14 17:19:34 +03001455 p = reserve_space(xdr, 4);
1456 *p = cpu_to_be32(OP_RENAME);
1457 encode_string(xdr, oldname->len, oldname->name);
1458 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001459 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001460 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Al Viro8687b632006-10-19 23:28:48 -07001465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Benny Halevy13c65ce2009-08-14 17:19:25 +03001467 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001468 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001469 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001470 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001471 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static void
Andy Adamsond0179312008-12-23 16:06:17 -05001475encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001476{
Al Viro8687b632006-10-19 23:28:48 -07001477 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001478
Benny Halevy13c65ce2009-08-14 17:19:25 +03001479 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001480 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001481 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001482 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001483}
1484
1485static int
Andy Adamsond0179312008-12-23 16:06:17 -05001486encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001487{
Al Viro8687b632006-10-19 23:28:48 -07001488 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001489
Benny Halevy13c65ce2009-08-14 17:19:25 +03001490 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001491 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001492 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001493 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001494 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001495 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001496 if (arg->acl_len % 4)
1497 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001498 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001499 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001500 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001501 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001502 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001503 return 0;
1504}
1505
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001506static void
Andy Adamsond0179312008-12-23 16:06:17 -05001507encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001512 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001513 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001514 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static 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 -07001518{
Al Viro8687b632006-10-19 23:28:48 -07001519 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001520
Benny Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001522 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001523 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001524 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001525 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
1528
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001529static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
Al Viro8687b632006-10-19 23:28:48 -07001531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Benny Halevy13c65ce2009-08-14 17:19:25 +03001533 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001534 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001535 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001538 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001539 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1541 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001542 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001543 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001544 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001545 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001548static 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 -07001549{
Andy Adamson05d564f2008-12-23 16:06:15 -05001550 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Benny Halevy13c65ce2009-08-14 17:19:25 +03001552 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001553 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001554 p = xdr_encode_hyper(p, arg->clientid);
1555 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001556 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001557 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Al Viro8687b632006-10-19 23:28:48 -07001562 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Benny Halevy13c65ce2009-08-14 17:19:25 +03001564 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001565 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001567 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Benny Halevy13c65ce2009-08-14 17:19:25 +03001569 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001570 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001571 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001572 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001575 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001576 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001579static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Al Viro8687b632006-10-19 23:28:48 -07001581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Benny Halevy13c65ce2009-08-14 17:19:25 +03001583 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Benny Halevye75bc1c2009-08-14 17:18:54 +03001585 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001586 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001587 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001588 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001590
Benny Halevy99fe60d2009-04-01 09:22:29 -04001591#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001592/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001593static void encode_exchange_id(struct xdr_stream *xdr,
1594 struct nfs41_exchange_id_args *args,
1595 struct compound_hdr *hdr)
1596{
1597 __be32 *p;
1598
Benny Halevy13c65ce2009-08-14 17:19:25 +03001599 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001600 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001601 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001602
1603 encode_string(xdr, args->id_len, args->id);
1604
Benny Halevy13c65ce2009-08-14 17:19:25 +03001605 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001606 *p++ = cpu_to_be32(args->flags);
1607 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001608 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001609 hdr->nops++;
1610 hdr->replen += decode_exchange_id_maxsz;
1611}
Andy Adamsonfc931582009-04-01 09:22:31 -04001612
1613static void encode_create_session(struct xdr_stream *xdr,
1614 struct nfs41_create_session_args *args,
1615 struct compound_hdr *hdr)
1616{
1617 __be32 *p;
1618 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1619 uint32_t len;
1620 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001621 u32 max_resp_sz_cached;
1622
1623 /*
1624 * Assumes OPEN is the biggest non-idempotent compound.
1625 * 2 is the verifier.
1626 */
1627 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1628 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001629
Andy Adamsonfc931582009-04-01 09:22:31 -04001630 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1631 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001632
Benny Halevy13c65ce2009-08-14 17:19:25 +03001633 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001634 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001635 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001636 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1637 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001638
Andy Adamsonfc931582009-04-01 09:22:31 -04001639 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001640 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1641 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1642 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001643 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001644 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1645 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1646 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001647
1648 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001649 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1650 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1651 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1652 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1653 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1654 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1655 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001656
Benny Halevye75bc1c2009-08-14 17:18:54 +03001657 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001658 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001659 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001660
1661 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001662 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001663 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001664 *p++ = cpu_to_be32(0); /* UID */
1665 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001666 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001667 hdr->nops++;
1668 hdr->replen += decode_create_session_maxsz;
1669}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001670
1671static void encode_destroy_session(struct xdr_stream *xdr,
1672 struct nfs4_session *session,
1673 struct compound_hdr *hdr)
1674{
1675 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001677 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001678 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001679 hdr->nops++;
1680 hdr->replen += decode_destroy_session_maxsz;
1681}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001682
1683static void encode_reclaim_complete(struct xdr_stream *xdr,
1684 struct nfs41_reclaim_complete_args *args,
1685 struct compound_hdr *hdr)
1686{
1687 __be32 *p;
1688
1689 p = reserve_space(xdr, 8);
1690 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1691 *p++ = cpu_to_be32(args->one_fs);
1692 hdr->nops++;
1693 hdr->replen += decode_reclaim_complete_maxsz;
1694}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001695#endif /* CONFIG_NFS_V4_1 */
1696
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001697static void encode_sequence(struct xdr_stream *xdr,
1698 const struct nfs4_sequence_args *args,
1699 struct compound_hdr *hdr)
1700{
1701#if defined(CONFIG_NFS_V4_1)
1702 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001703 struct nfs4_slot_table *tp;
1704 struct nfs4_slot *slot;
1705 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001706
1707 if (!session)
1708 return;
1709
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001710 tp = &session->fc_slot_table;
1711
1712 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1713 slot = tp->slots + args->sa_slotid;
1714
Benny Halevy13c65ce2009-08-14 17:19:25 +03001715 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001716 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001717
1718 /*
1719 * Sessionid + seqid + slotid + max slotid + cache_this
1720 */
1721 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1722 "max_slotid=%d cache_this=%d\n",
1723 __func__,
1724 ((u32 *)session->sess_id.data)[0],
1725 ((u32 *)session->sess_id.data)[1],
1726 ((u32 *)session->sess_id.data)[2],
1727 ((u32 *)session->sess_id.data)[3],
1728 slot->seq_nr, args->sa_slotid,
1729 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001730 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001731 *p++ = cpu_to_be32(slot->seq_nr);
1732 *p++ = cpu_to_be32(args->sa_slotid);
1733 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001734 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001735 hdr->nops++;
1736 hdr->replen += decode_sequence_maxsz;
1737#endif /* CONFIG_NFS_V4_1 */
1738}
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740/*
1741 * END OF "GENERIC" ENCODE ROUTINES.
1742 */
1743
Benny Halevy66cc0422009-04-01 09:22:10 -04001744static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1745{
1746#if defined(CONFIG_NFS_V4_1)
1747 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001748 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001749#endif /* CONFIG_NFS_V4_1 */
1750 return 0;
1751}
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753/*
1754 * Encode an ACCESS request
1755 */
Al Viro8687b632006-10-19 23:28:48 -07001756static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757{
1758 struct xdr_stream xdr;
1759 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001760 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001764 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001765 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001766 encode_putfh(&xdr, args->fh, &hdr);
1767 encode_access(&xdr, args->access, &hdr);
1768 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001769 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001770 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
1773/*
1774 * Encode LOOKUP request
1775 */
Al Viro8687b632006-10-19 23:28:48 -07001776static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777{
1778 struct xdr_stream xdr;
1779 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001780 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001784 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001785 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001786 encode_putfh(&xdr, args->dir_fh, &hdr);
1787 encode_lookup(&xdr, args->name, &hdr);
1788 encode_getfh(&xdr, &hdr);
1789 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001790 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001791 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
1793
1794/*
1795 * Encode LOOKUP_ROOT request
1796 */
Al Viro8687b632006-10-19 23:28:48 -07001797static 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 -07001798{
1799 struct xdr_stream xdr;
1800 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001801 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001805 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001806 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001807 encode_putrootfh(&xdr, &hdr);
1808 encode_getfh(&xdr, &hdr);
1809 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001810 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001811 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812}
1813
1814/*
1815 * Encode REMOVE request
1816 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001817static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818{
1819 struct xdr_stream xdr;
1820 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001821 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
1824 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001825 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001826 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001827 encode_putfh(&xdr, args->fh, &hdr);
1828 encode_remove(&xdr, &args->name, &hdr);
1829 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001830 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001831 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832}
1833
1834/*
1835 * Encode RENAME request
1836 */
Jeff Layton920769f2010-09-17 17:30:25 -04001837static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
1839 struct xdr_stream xdr;
1840 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001841 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001845 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001846 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001847 encode_putfh(&xdr, args->old_dir, &hdr);
1848 encode_savefh(&xdr, &hdr);
1849 encode_putfh(&xdr, args->new_dir, &hdr);
1850 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1851 encode_getfattr(&xdr, args->bitmask, &hdr);
1852 encode_restorefh(&xdr, &hdr);
1853 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001854 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001855 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856}
1857
1858/*
1859 * Encode LINK request
1860 */
Al Viro8687b632006-10-19 23:28:48 -07001861static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
1863 struct xdr_stream xdr;
1864 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001865 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
1868 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001869 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001870 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001871 encode_putfh(&xdr, args->fh, &hdr);
1872 encode_savefh(&xdr, &hdr);
1873 encode_putfh(&xdr, args->dir_fh, &hdr);
1874 encode_link(&xdr, args->name, &hdr);
1875 encode_getfattr(&xdr, args->bitmask, &hdr);
1876 encode_restorefh(&xdr, &hdr);
1877 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001878 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001879 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880}
1881
1882/*
1883 * Encode CREATE request
1884 */
Al Viro8687b632006-10-19 23:28:48 -07001885static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
1887 struct xdr_stream xdr;
1888 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001889 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
1892 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001893 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001894 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001895 encode_putfh(&xdr, args->dir_fh, &hdr);
1896 encode_savefh(&xdr, &hdr);
1897 encode_create(&xdr, args, &hdr);
1898 encode_getfh(&xdr, &hdr);
1899 encode_getfattr(&xdr, args->bitmask, &hdr);
1900 encode_restorefh(&xdr, &hdr);
1901 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001902 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001903 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
1906/*
1907 * Encode SYMLINK request
1908 */
Al Viro8687b632006-10-19 23:28:48 -07001909static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
1911 return nfs4_xdr_enc_create(req, p, args);
1912}
1913
1914/*
1915 * Encode GETATTR request
1916 */
Al Viro8687b632006-10-19 23:28:48 -07001917static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
1919 struct xdr_stream xdr;
1920 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001921 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
1924 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001925 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001926 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001927 encode_putfh(&xdr, args->fh, &hdr);
1928 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001929 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001930 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931}
1932
1933/*
1934 * Encode a CLOSE request
1935 */
Al Viro8687b632006-10-19 23:28:48 -07001936static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937{
Andy Adamson05d564f2008-12-23 16:06:15 -05001938 struct xdr_stream xdr;
1939 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001940 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001941 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
Andy Adamson05d564f2008-12-23 16:06:15 -05001943 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001944 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001945 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001946 encode_putfh(&xdr, args->fh, &hdr);
1947 encode_close(&xdr, args, &hdr);
1948 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001949 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001950 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
1953/*
1954 * Encode an OPEN request
1955 */
Al Viro8687b632006-10-19 23:28:48 -07001956static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
1958 struct xdr_stream xdr;
1959 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001960 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001964 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001965 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001966 encode_putfh(&xdr, args->fh, &hdr);
1967 encode_savefh(&xdr, &hdr);
1968 encode_open(&xdr, args, &hdr);
1969 encode_getfh(&xdr, &hdr);
1970 encode_getfattr(&xdr, args->bitmask, &hdr);
1971 encode_restorefh(&xdr, &hdr);
1972 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001973 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001974 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975}
1976
1977/*
1978 * Encode an OPEN_CONFIRM request
1979 */
Al Viro8687b632006-10-19 23:28:48 -07001980static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981{
1982 struct xdr_stream xdr;
1983 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001984 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001988 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001989 encode_putfh(&xdr, args->fh, &hdr);
1990 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001991 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001992 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993}
1994
1995/*
1996 * Encode an OPEN request with no attributes.
1997 */
Al Viro8687b632006-10-19 23:28:48 -07001998static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
2000 struct xdr_stream xdr;
2001 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002002 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
2005 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002006 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002007 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002008 encode_putfh(&xdr, args->fh, &hdr);
2009 encode_open(&xdr, args, &hdr);
2010 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002011 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002012 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013}
2014
2015/*
2016 * Encode an OPEN_DOWNGRADE request
2017 */
Al Viro8687b632006-10-19 23:28:48 -07002018static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
2020 struct xdr_stream xdr;
2021 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002022 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
2025 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002026 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002027 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002028 encode_putfh(&xdr, args->fh, &hdr);
2029 encode_open_downgrade(&xdr, args, &hdr);
2030 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002031 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002032 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033}
2034
2035/*
2036 * Encode a LOCK request
2037 */
Al Viro8687b632006-10-19 23:28:48 -07002038static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
2040 struct xdr_stream xdr;
2041 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
2045 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002046 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002047 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002048 encode_putfh(&xdr, args->fh, &hdr);
2049 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002050 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002051 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052}
2053
2054/*
2055 * Encode a LOCKT request
2056 */
Al Viro8687b632006-10-19 23:28:48 -07002057static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
2059 struct xdr_stream xdr;
2060 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
2064 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002065 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002066 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002067 encode_putfh(&xdr, args->fh, &hdr);
2068 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002069 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
2073/*
2074 * Encode a LOCKU request
2075 */
Al Viro8687b632006-10-19 23:28:48 -07002076static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 struct xdr_stream xdr;
2079 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002084 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002085 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002086 encode_putfh(&xdr, args->fh, &hdr);
2087 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002089 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002092static int nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, __be32 *p, struct nfs_release_lockowner_args *args)
2093{
2094 struct xdr_stream xdr;
2095 struct compound_hdr hdr = {
2096 .minorversion = 0,
2097 };
2098
2099 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2100 encode_compound_hdr(&xdr, req, &hdr);
2101 encode_release_lockowner(&xdr, &args->lock_owner, &hdr);
2102 encode_nops(&hdr);
2103 return 0;
2104}
2105
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106/*
2107 * Encode a READLINK request
2108 */
Al Viro8687b632006-10-19 23:28:48 -07002109static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
2111 struct xdr_stream xdr;
2112 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002113 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002117 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002118 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002119 encode_putfh(&xdr, args->fh, &hdr);
2120 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002121
Benny Halevy28f56692009-04-01 09:22:09 -04002122 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002123 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/*
2129 * Encode a READDIR request
2130 */
Al Viro8687b632006-10-19 23:28:48 -07002131static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
2133 struct xdr_stream xdr;
2134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002139 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002140 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002141 encode_putfh(&xdr, args->fh, &hdr);
2142 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002143
Benny Halevy28f56692009-04-01 09:22:09 -04002144 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002145 args->pgbase, args->count);
2146 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002147 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002148 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002149 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002150 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153/*
2154 * Encode a READ request
2155 */
Al Viro8687b632006-10-19 23:28:48 -07002156static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct xdr_stream xdr;
2159 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
2163 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002164 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002165 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002166 encode_putfh(&xdr, args->fh, &hdr);
2167 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Benny Halevy28f56692009-04-01 09:22:09 -04002169 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002171 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002172 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002173 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174}
2175
2176/*
2177 * Encode an SETATTR request
2178 */
Al Viro8687b632006-10-19 23:28:48 -07002179static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Andy Adamson05d564f2008-12-23 16:06:15 -05002181 struct xdr_stream xdr;
2182 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002184 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Andy Adamson05d564f2008-12-23 16:06:15 -05002186 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002187 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002188 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002189 encode_putfh(&xdr, args->fh, &hdr);
2190 encode_setattr(&xdr, args, args->server, &hdr);
2191 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002192 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002197 * Encode a GETACL request
2198 */
2199static int
Al Viro8687b632006-10-19 23:28:48 -07002200nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002201 struct nfs_getaclargs *args)
2202{
2203 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002204 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002205 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002206 };
Benny Halevy28f56692009-04-01 09:22:09 -04002207 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002208
2209 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002210 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002211 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002212 encode_putfh(&xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002213 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002214 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2215
Benny Halevy28f56692009-04-01 09:22:09 -04002216 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002217 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002218 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002219 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002220}
2221
2222/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 * Encode a WRITE request
2224 */
Al Viro8687b632006-10-19 23:28:48 -07002225static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
2227 struct xdr_stream xdr;
2228 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002229 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
2232 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002233 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002234 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002235 encode_putfh(&xdr, args->fh, &hdr);
2236 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002237 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002238 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002239 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002240 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241}
2242
2243/*
2244 * a COMMIT request
2245 */
Al Viro8687b632006-10-19 23:28:48 -07002246static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247{
2248 struct xdr_stream xdr;
2249 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002250 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002254 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002255 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002256 encode_putfh(&xdr, args->fh, &hdr);
2257 encode_commit(&xdr, args, &hdr);
2258 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002259 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002260 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
2263/*
2264 * FSINFO request
2265 */
Al Viro8687b632006-10-19 23:28:48 -07002266static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267{
2268 struct xdr_stream xdr;
2269 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002270 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
2273 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002274 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002275 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002276 encode_putfh(&xdr, args->fh, &hdr);
2277 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002278 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
2282/*
2283 * a PATHCONF request
2284 */
Al Viro8687b632006-10-19 23:28:48 -07002285static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 struct xdr_stream xdr;
2288 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002289 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002293 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002294 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002295 encode_putfh(&xdr, args->fh, &hdr);
2296 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2297 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002298 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002299 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
2302/*
2303 * a STATFS request
2304 */
Al Viro8687b632006-10-19 23:28:48 -07002305static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct xdr_stream xdr;
2308 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002309 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002313 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002314 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002315 encode_putfh(&xdr, args->fh, &hdr);
2316 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2317 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002318 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002319 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320}
2321
2322/*
2323 * GETATTR_BITMAP request
2324 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002325static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2326 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327{
2328 struct xdr_stream xdr;
2329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
2333 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002334 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002335 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002336 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002337 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2338 FATTR4_WORD0_LINK_SUPPORT|
2339 FATTR4_WORD0_SYMLINK_SUPPORT|
2340 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002341 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002342 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343}
2344
2345/*
2346 * a RENEW request
2347 */
Al Viro8687b632006-10-19 23:28:48 -07002348static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349{
2350 struct xdr_stream xdr;
2351 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002352 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 };
2354
2355 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002356 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002357 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002358 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002359 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360}
2361
2362/*
2363 * a SETCLIENTID request
2364 */
Al Viro8687b632006-10-19 23:28:48 -07002365static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366{
2367 struct xdr_stream xdr;
2368 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002369 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 };
2371
2372 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002373 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002374 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002375 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002376 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377}
2378
2379/*
2380 * a SETCLIENTID_CONFIRM request
2381 */
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002382static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
2384 struct xdr_stream xdr;
2385 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002386 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 };
2388 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
2390 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002391 encode_compound_hdr(&xdr, req, &hdr);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002392 encode_setclientid_confirm(&xdr, arg, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002393 encode_putrootfh(&xdr, &hdr);
2394 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002395 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002396 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397}
2398
2399/*
2400 * DELEGRETURN request
2401 */
Al Viro8687b632006-10-19 23:28:48 -07002402static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403{
2404 struct xdr_stream xdr;
2405 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002406 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
2409 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002410 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002411 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002412 encode_putfh(&xdr, args->fhandle, &hdr);
2413 encode_delegreturn(&xdr, args->stateid, &hdr);
2414 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002416 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
2419/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002420 * Encode FS_LOCATIONS request
2421 */
Al Viro8687b632006-10-19 23:28:48 -07002422static 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 -04002423{
2424 struct xdr_stream xdr;
2425 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002426 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002427 };
Benny Halevy28f56692009-04-01 09:22:09 -04002428 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002429
2430 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002431 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002432 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002433 encode_putfh(&xdr, args->dir_fh, &hdr);
2434 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002435 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002436 encode_fs_locations(&xdr, args->bitmask, &hdr);
2437
Benny Halevy28f56692009-04-01 09:22:09 -04002438 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002439 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002440 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002441 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002442}
2443
Benny Halevy99fe60d2009-04-01 09:22:29 -04002444#if defined(CONFIG_NFS_V4_1)
2445/*
2446 * EXCHANGE_ID request
2447 */
2448static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2449 struct nfs41_exchange_id_args *args)
2450{
2451 struct xdr_stream xdr;
2452 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002453 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002454 };
2455
2456 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2457 encode_compound_hdr(&xdr, req, &hdr);
2458 encode_exchange_id(&xdr, args, &hdr);
2459 encode_nops(&hdr);
2460 return 0;
2461}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002462
2463/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002464 * a CREATE_SESSION request
2465 */
2466static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2467 struct nfs41_create_session_args *args)
2468{
2469 struct xdr_stream xdr;
2470 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002471 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002472 };
2473
2474 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2475 encode_compound_hdr(&xdr, req, &hdr);
2476 encode_create_session(&xdr, args, &hdr);
2477 encode_nops(&hdr);
2478 return 0;
2479}
2480
2481/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002482 * a DESTROY_SESSION request
2483 */
2484static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2485 struct nfs4_session *session)
2486{
2487 struct xdr_stream xdr;
2488 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002489 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002490 };
2491
2492 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2493 encode_compound_hdr(&xdr, req, &hdr);
2494 encode_destroy_session(&xdr, session, &hdr);
2495 encode_nops(&hdr);
2496 return 0;
2497}
2498
2499/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002500 * a SEQUENCE request
2501 */
2502static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2503 struct nfs4_sequence_args *args)
2504{
2505 struct xdr_stream xdr;
2506 struct compound_hdr hdr = {
2507 .minorversion = nfs4_xdr_minorversion(args),
2508 };
2509
2510 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2511 encode_compound_hdr(&xdr, req, &hdr);
2512 encode_sequence(&xdr, args, &hdr);
2513 encode_nops(&hdr);
2514 return 0;
2515}
2516
2517/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002518 * a GET_LEASE_TIME request
2519 */
2520static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2521 struct nfs4_get_lease_time_args *args)
2522{
2523 struct xdr_stream xdr;
2524 struct compound_hdr hdr = {
2525 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2526 };
2527 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2528
2529 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2530 encode_compound_hdr(&xdr, req, &hdr);
2531 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2532 encode_putrootfh(&xdr, &hdr);
2533 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2534 encode_nops(&hdr);
2535 return 0;
2536}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002537
2538/*
2539 * a RECLAIM_COMPLETE request
2540 */
2541static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2542 struct nfs41_reclaim_complete_args *args)
2543{
2544 struct xdr_stream xdr;
2545 struct compound_hdr hdr = {
2546 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2547 };
2548
2549 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2550 encode_compound_hdr(&xdr, req, &hdr);
2551 encode_sequence(&xdr, &args->seq_args, &hdr);
2552 encode_reclaim_complete(&xdr, args, &hdr);
2553 encode_nops(&hdr);
2554 return 0;
2555}
2556
Benny Halevy99fe60d2009-04-01 09:22:29 -04002557#endif /* CONFIG_NFS_V4_1 */
2558
Benny Halevy686841b2009-08-14 17:19:48 +03002559static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2560{
2561 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2562 "Remaining buffer length is %tu words.\n",
2563 func, xdr->end - xdr->p);
2564}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
Trond Myklebust683b57b2006-06-09 09:34:22 -04002566static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567{
Al Viro8687b632006-10-19 23:28:48 -07002568 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Benny Halevyc0eae662009-08-14 17:20:14 +03002570 p = xdr_inline_decode(xdr, 4);
2571 if (unlikely(!p))
2572 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002573 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002574 p = xdr_inline_decode(xdr, *len);
2575 if (unlikely(!p))
2576 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 *string = (char *)p;
2578 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002579out_overflow:
2580 print_overflow_msg(__func__, xdr);
2581 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
2584static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2585{
Al Viro8687b632006-10-19 23:28:48 -07002586 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Benny Halevyc0eae662009-08-14 17:20:14 +03002588 p = xdr_inline_decode(xdr, 8);
2589 if (unlikely(!p))
2590 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002591 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002592 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002593
Benny Halevyc0eae662009-08-14 17:20:14 +03002594 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2595 if (unlikely(!p))
2596 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 hdr->tag = (char *)p;
2598 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002599 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002600 if (unlikely(hdr->nops < 1))
2601 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002603out_overflow:
2604 print_overflow_msg(__func__, xdr);
2605 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606}
2607
2608static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2609{
Al Viro8687b632006-10-19 23:28:48 -07002610 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 uint32_t opnum;
2612 int32_t nfserr;
2613
Benny Halevyc0eae662009-08-14 17:20:14 +03002614 p = xdr_inline_decode(xdr, 8);
2615 if (unlikely(!p))
2616 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002617 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002619 dprintk("nfs: Server returned operation"
2620 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 opnum, expected);
2622 return -EIO;
2623 }
Benny Halevycccddf42009-08-14 17:20:19 +03002624 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002626 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002628out_overflow:
2629 print_overflow_msg(__func__, xdr);
2630 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631}
2632
2633/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002634static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635{
Al Viro8687b632006-10-19 23:28:48 -07002636 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002637 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 char *str;
2639
Benny Halevyc0eae662009-08-14 17:20:14 +03002640 p = xdr_inline_decode(xdr, 12);
2641 if (likely(p))
2642 return decode_opaque_inline(xdr, &strlen, &str);
2643 print_overflow_msg(__func__, xdr);
2644 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645}
2646
2647static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2648{
Al Viro8687b632006-10-19 23:28:48 -07002649 uint32_t bmlen;
2650 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Benny Halevyc0eae662009-08-14 17:20:14 +03002652 p = xdr_inline_decode(xdr, 4);
2653 if (unlikely(!p))
2654 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002655 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
2657 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002658 p = xdr_inline_decode(xdr, (bmlen << 2));
2659 if (unlikely(!p))
2660 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002662 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002664 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
2666 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002667out_overflow:
2668 print_overflow_msg(__func__, xdr);
2669 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670}
2671
Al Viro8687b632006-10-19 23:28:48 -07002672static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673{
Al Viro8687b632006-10-19 23:28:48 -07002674 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Benny Halevyc0eae662009-08-14 17:20:14 +03002676 p = xdr_inline_decode(xdr, 4);
2677 if (unlikely(!p))
2678 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002679 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 *savep = xdr->p;
2681 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002682out_overflow:
2683 print_overflow_msg(__func__, xdr);
2684 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685}
2686
2687static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2688{
2689 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002690 int ret;
2691 ret = decode_attr_bitmap(xdr, bitmask);
2692 if (unlikely(ret < 0))
2693 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2695 } else
2696 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002697 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 return 0;
2699}
2700
2701static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2702{
Al Viro8687b632006-10-19 23:28:48 -07002703 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002704 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
2706 *type = 0;
2707 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2708 return -EIO;
2709 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002710 p = xdr_inline_decode(xdr, 4);
2711 if (unlikely(!p))
2712 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002713 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002715 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 return -EIO;
2717 }
2718 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002719 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002721 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002722 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002723out_overflow:
2724 print_overflow_msg(__func__, xdr);
2725 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726}
2727
2728static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2729{
Al Viro8687b632006-10-19 23:28:48 -07002730 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002731 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
2733 *change = 0;
2734 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2735 return -EIO;
2736 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002737 p = xdr_inline_decode(xdr, 8);
2738 if (unlikely(!p))
2739 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002740 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002742 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002744 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002746 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002747out_overflow:
2748 print_overflow_msg(__func__, xdr);
2749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750}
2751
2752static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2753{
Al Viro8687b632006-10-19 23:28:48 -07002754 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002755 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
2757 *size = 0;
2758 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2759 return -EIO;
2760 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002761 p = xdr_inline_decode(xdr, 8);
2762 if (unlikely(!p))
2763 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002764 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002766 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002768 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002769 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002770out_overflow:
2771 print_overflow_msg(__func__, xdr);
2772 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773}
2774
2775static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2776{
Al Viro8687b632006-10-19 23:28:48 -07002777 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
2779 *res = 0;
2780 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2781 return -EIO;
2782 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002783 p = xdr_inline_decode(xdr, 4);
2784 if (unlikely(!p))
2785 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002786 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2788 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002789 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002791out_overflow:
2792 print_overflow_msg(__func__, xdr);
2793 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794}
2795
2796static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2797{
Al Viro8687b632006-10-19 23:28:48 -07002798 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799
2800 *res = 0;
2801 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2802 return -EIO;
2803 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002804 p = xdr_inline_decode(xdr, 4);
2805 if (unlikely(!p))
2806 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002807 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2809 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002810 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002812out_overflow:
2813 print_overflow_msg(__func__, xdr);
2814 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815}
2816
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002817static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818{
Al Viro8687b632006-10-19 23:28:48 -07002819 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002820 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 fsid->major = 0;
2823 fsid->minor = 0;
2824 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2825 return -EIO;
2826 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002827 p = xdr_inline_decode(xdr, 16);
2828 if (unlikely(!p))
2829 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002830 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002831 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002833 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002835 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 (unsigned long long)fsid->major,
2837 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002838 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002839out_overflow:
2840 print_overflow_msg(__func__, xdr);
2841 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842}
2843
2844static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2845{
Al Viro8687b632006-10-19 23:28:48 -07002846 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
2848 *res = 60;
2849 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2850 return -EIO;
2851 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002852 p = xdr_inline_decode(xdr, 4);
2853 if (unlikely(!p))
2854 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002855 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2857 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002858 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002860out_overflow:
2861 print_overflow_msg(__func__, xdr);
2862 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863}
2864
Bryan Schumakerae42c702010-10-21 16:33:17 -04002865static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2866{
2867 __be32 *p;
2868
2869 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2870 return -EIO;
2871 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2872 p = xdr_inline_decode(xdr, 4);
2873 if (unlikely(!p))
2874 goto out_overflow;
2875 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2876 }
2877 return 0;
2878out_overflow:
2879 print_overflow_msg(__func__, xdr);
2880 return -EIO;
2881}
2882
2883static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2884{
2885 __be32 *p;
2886 int len;
2887
Trond Myklebust7ad07352010-10-23 15:34:20 -04002888 if (fh != NULL)
2889 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002890
2891 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2892 return -EIO;
2893 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2894 p = xdr_inline_decode(xdr, 4);
2895 if (unlikely(!p))
2896 goto out_overflow;
2897 len = be32_to_cpup(p);
2898 if (len > NFS4_FHSIZE)
2899 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002900 p = xdr_inline_decode(xdr, len);
2901 if (unlikely(!p))
2902 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002903 if (fh != NULL) {
2904 memcpy(fh->data, p, len);
2905 fh->size = len;
2906 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04002907 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2908 }
2909 return 0;
2910out_overflow:
2911 print_overflow_msg(__func__, xdr);
2912 return -EIO;
2913}
2914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2916{
Al Viro8687b632006-10-19 23:28:48 -07002917 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
2919 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2920 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2921 return -EIO;
2922 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002923 p = xdr_inline_decode(xdr, 4);
2924 if (unlikely(!p))
2925 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002926 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2928 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002929 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002931out_overflow:
2932 print_overflow_msg(__func__, xdr);
2933 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934}
2935
2936static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2937{
Al Viro8687b632006-10-19 23:28:48 -07002938 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002939 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
2941 *fileid = 0;
2942 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2943 return -EIO;
2944 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002945 p = xdr_inline_decode(xdr, 8);
2946 if (unlikely(!p))
2947 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002948 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002950 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002952 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002953 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002954out_overflow:
2955 print_overflow_msg(__func__, xdr);
2956 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957}
2958
Manoj Naik99baf622006-06-09 09:34:24 -04002959static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2960{
Al Viro8687b632006-10-19 23:28:48 -07002961 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002962 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002963
2964 *fileid = 0;
2965 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2966 return -EIO;
2967 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002968 p = xdr_inline_decode(xdr, 8);
2969 if (unlikely(!p))
2970 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002971 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002972 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002973 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002974 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002975 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002976 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002977out_overflow:
2978 print_overflow_msg(__func__, xdr);
2979 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002980}
2981
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2983{
Al Viro8687b632006-10-19 23:28:48 -07002984 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 int status = 0;
2986
2987 *res = 0;
2988 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2989 return -EIO;
2990 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002991 p = xdr_inline_decode(xdr, 8);
2992 if (unlikely(!p))
2993 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002994 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2996 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002997 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002999out_overflow:
3000 print_overflow_msg(__func__, xdr);
3001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
3004static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3005{
Al Viro8687b632006-10-19 23:28:48 -07003006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 int status = 0;
3008
3009 *res = 0;
3010 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3011 return -EIO;
3012 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003013 p = xdr_inline_decode(xdr, 8);
3014 if (unlikely(!p))
3015 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003016 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3018 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003019 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003021out_overflow:
3022 print_overflow_msg(__func__, xdr);
3023 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024}
3025
3026static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3027{
Al Viro8687b632006-10-19 23:28:48 -07003028 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 int status = 0;
3030
3031 *res = 0;
3032 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3033 return -EIO;
3034 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003035 p = xdr_inline_decode(xdr, 8);
3036 if (unlikely(!p))
3037 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003038 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3040 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003041 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003043out_overflow:
3044 print_overflow_msg(__func__, xdr);
3045 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046}
3047
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003048static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3049{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003050 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003051 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003052 int status = 0;
3053
Benny Halevyc0eae662009-08-14 17:20:14 +03003054 p = xdr_inline_decode(xdr, 4);
3055 if (unlikely(!p))
3056 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003057 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003058 if (n == 0)
3059 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003060 dprintk("path ");
3061 path->ncomponents = 0;
3062 while (path->ncomponents < n) {
3063 struct nfs4_string *component = &path->components[path->ncomponents];
3064 status = decode_opaque_inline(xdr, &component->len, &component->data);
3065 if (unlikely(status != 0))
3066 goto out_eio;
3067 if (path->ncomponents != n)
3068 dprintk("/");
3069 dprintk("%s", component->data);
3070 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3071 path->ncomponents++;
3072 else {
3073 dprintk("cannot parse %d components in path\n", n);
3074 goto out_eio;
3075 }
3076 }
3077out:
3078 dprintk("\n");
3079 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003080root_path:
3081/* a root pathname is sent as a zero component4 */
3082 path->ncomponents = 1;
3083 path->components[0].len=0;
3084 path->components[0].data=NULL;
3085 dprintk("path /\n");
3086 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003087out_eio:
3088 dprintk(" status %d", status);
3089 status = -EIO;
3090 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003091out_overflow:
3092 print_overflow_msg(__func__, xdr);
3093 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003094}
3095
3096static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003097{
3098 int n;
Al Viro8687b632006-10-19 23:28:48 -07003099 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003100 int status = -EIO;
3101
3102 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3103 goto out;
3104 status = 0;
3105 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3106 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003107 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003108 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003109 if (unlikely(status != 0))
3110 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003111 p = xdr_inline_decode(xdr, 4);
3112 if (unlikely(!p))
3113 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003114 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003115 if (n <= 0)
3116 goto out_eio;
3117 res->nlocations = 0;
3118 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003119 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003120 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003121
Benny Halevyc0eae662009-08-14 17:20:14 +03003122 p = xdr_inline_decode(xdr, 4);
3123 if (unlikely(!p))
3124 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003125 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003126
3127 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003128 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003129 while (loc->nservers < m) {
3130 struct nfs4_string *server = &loc->servers[loc->nservers];
3131 status = decode_opaque_inline(xdr, &server->len, &server->data);
3132 if (unlikely(status != 0))
3133 goto out_eio;
3134 dprintk("%s ", server->data);
3135 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3136 loc->nservers++;
3137 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003138 unsigned int i;
3139 dprintk("%s: using first %u of %u servers "
3140 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003141 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003142 NFS4_FS_LOCATION_MAXSERVERS,
3143 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003144 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003145 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003146 char *data;
3147 status = decode_opaque_inline(xdr, &len, &data);
3148 if (unlikely(status != 0))
3149 goto out_eio;
3150 }
3151 }
3152 }
3153 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003154 if (unlikely(status != 0))
3155 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003156 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003157 res->nlocations++;
3158 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003159 if (res->nlocations != 0)
3160 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003161out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003162 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003163 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003164out_overflow:
3165 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003166out_eio:
3167 status = -EIO;
3168 goto out;
3169}
3170
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3172{
Al Viro8687b632006-10-19 23:28:48 -07003173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 int status = 0;
3175
3176 *res = 0;
3177 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3178 return -EIO;
3179 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003180 p = xdr_inline_decode(xdr, 8);
3181 if (unlikely(!p))
3182 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003183 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3185 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003186 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003188out_overflow:
3189 print_overflow_msg(__func__, xdr);
3190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191}
3192
3193static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3194{
Al Viro8687b632006-10-19 23:28:48 -07003195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 int status = 0;
3197
3198 *maxlink = 1;
3199 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3200 return -EIO;
3201 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003202 p = xdr_inline_decode(xdr, 4);
3203 if (unlikely(!p))
3204 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003205 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3207 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003208 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003210out_overflow:
3211 print_overflow_msg(__func__, xdr);
3212 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213}
3214
3215static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3216{
Al Viro8687b632006-10-19 23:28:48 -07003217 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 int status = 0;
3219
3220 *maxname = 1024;
3221 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3222 return -EIO;
3223 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003224 p = xdr_inline_decode(xdr, 4);
3225 if (unlikely(!p))
3226 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003227 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3229 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003230 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003232out_overflow:
3233 print_overflow_msg(__func__, xdr);
3234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235}
3236
3237static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3238{
Al Viro8687b632006-10-19 23:28:48 -07003239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 int status = 0;
3241
3242 *res = 1024;
3243 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3244 return -EIO;
3245 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3246 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003247 p = xdr_inline_decode(xdr, 8);
3248 if (unlikely(!p))
3249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003250 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 if (maxread > 0x7FFFFFFF)
3252 maxread = 0x7FFFFFFF;
3253 *res = (uint32_t)maxread;
3254 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3255 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003256 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003258out_overflow:
3259 print_overflow_msg(__func__, xdr);
3260 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261}
3262
3263static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3264{
Al Viro8687b632006-10-19 23:28:48 -07003265 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 int status = 0;
3267
3268 *res = 1024;
3269 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3270 return -EIO;
3271 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3272 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003273 p = xdr_inline_decode(xdr, 8);
3274 if (unlikely(!p))
3275 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003276 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 if (maxwrite > 0x7FFFFFFF)
3278 maxwrite = 0x7FFFFFFF;
3279 *res = (uint32_t)maxwrite;
3280 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3281 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003282 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003284out_overflow:
3285 print_overflow_msg(__func__, xdr);
3286 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287}
3288
Trond Myklebustbca79472009-03-11 14:10:26 -04003289static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290{
Trond Myklebustbca79472009-03-11 14:10:26 -04003291 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003292 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003293 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294
3295 *mode = 0;
3296 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3297 return -EIO;
3298 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003299 p = xdr_inline_decode(xdr, 4);
3300 if (unlikely(!p))
3301 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003302 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003303 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003305 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003307 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003308 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003309out_overflow:
3310 print_overflow_msg(__func__, xdr);
3311 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312}
3313
3314static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3315{
Al Viro8687b632006-10-19 23:28:48 -07003316 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003317 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 *nlink = 1;
3320 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003323 p = xdr_inline_decode(xdr, 4);
3324 if (unlikely(!p))
3325 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003326 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003328 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003330 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003331 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003332out_overflow:
3333 print_overflow_msg(__func__, xdr);
3334 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003337static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3338 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339{
Al Viro8687b632006-10-19 23:28:48 -07003340 uint32_t len;
3341 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 *uid = -2;
3345 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3346 return -EIO;
3347 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 4);
3349 if (unlikely(!p))
3350 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003351 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003352 p = xdr_inline_decode(xdr, len);
3353 if (unlikely(!p))
3354 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003355 if (!may_sleep) {
3356 /* do nothing */
3357 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003358 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3359 ret = NFS_ATTR_FATTR_OWNER;
3360 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003362 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003364 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003365 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3367 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003368 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003369 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003370out_overflow:
3371 print_overflow_msg(__func__, xdr);
3372 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373}
3374
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003375static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3376 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377{
Al Viro8687b632006-10-19 23:28:48 -07003378 uint32_t len;
3379 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003380 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
3382 *gid = -2;
3383 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3384 return -EIO;
3385 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003386 p = xdr_inline_decode(xdr, 4);
3387 if (unlikely(!p))
3388 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003389 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003390 p = xdr_inline_decode(xdr, len);
3391 if (unlikely(!p))
3392 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003393 if (!may_sleep) {
3394 /* do nothing */
3395 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003396 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3397 ret = NFS_ATTR_FATTR_GROUP;
3398 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003400 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003402 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003403 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3405 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003406 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003407 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003408out_overflow:
3409 print_overflow_msg(__func__, xdr);
3410 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411}
3412
3413static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3414{
Al Viro8687b632006-10-19 23:28:48 -07003415 uint32_t major = 0, minor = 0;
3416 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003417 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
3419 *rdev = MKDEV(0,0);
3420 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3421 return -EIO;
3422 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3423 dev_t tmp;
3424
Benny Halevyc0eae662009-08-14 17:20:14 +03003425 p = xdr_inline_decode(xdr, 8);
3426 if (unlikely(!p))
3427 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003428 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003429 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 tmp = MKDEV(major, minor);
3431 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3432 *rdev = tmp;
3433 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003434 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003436 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003437 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003438out_overflow:
3439 print_overflow_msg(__func__, xdr);
3440 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441}
3442
3443static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3444{
Al Viro8687b632006-10-19 23:28:48 -07003445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 int status = 0;
3447
3448 *res = 0;
3449 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3450 return -EIO;
3451 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003452 p = xdr_inline_decode(xdr, 8);
3453 if (unlikely(!p))
3454 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003455 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3457 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003460out_overflow:
3461 print_overflow_msg(__func__, xdr);
3462 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463}
3464
3465static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3466{
Al Viro8687b632006-10-19 23:28:48 -07003467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 int status = 0;
3469
3470 *res = 0;
3471 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3472 return -EIO;
3473 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003474 p = xdr_inline_decode(xdr, 8);
3475 if (unlikely(!p))
3476 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003477 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3479 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003480 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003482out_overflow:
3483 print_overflow_msg(__func__, xdr);
3484 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485}
3486
3487static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3488{
Al Viro8687b632006-10-19 23:28:48 -07003489 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 int status = 0;
3491
3492 *res = 0;
3493 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3494 return -EIO;
3495 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003496 p = xdr_inline_decode(xdr, 8);
3497 if (unlikely(!p))
3498 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003499 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3501 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003502 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003504out_overflow:
3505 print_overflow_msg(__func__, xdr);
3506 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507}
3508
3509static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3510{
Al Viro8687b632006-10-19 23:28:48 -07003511 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003512 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
3514 *used = 0;
3515 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3516 return -EIO;
3517 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003518 p = xdr_inline_decode(xdr, 8);
3519 if (unlikely(!p))
3520 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003521 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003523 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003525 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003527 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003528out_overflow:
3529 print_overflow_msg(__func__, xdr);
3530 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531}
3532
3533static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3534{
Al Viro8687b632006-10-19 23:28:48 -07003535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 uint64_t sec;
3537 uint32_t nsec;
3538
Benny Halevyc0eae662009-08-14 17:20:14 +03003539 p = xdr_inline_decode(xdr, 12);
3540 if (unlikely(!p))
3541 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003542 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003543 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 time->tv_sec = (time_t)sec;
3545 time->tv_nsec = (long)nsec;
3546 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003547out_overflow:
3548 print_overflow_msg(__func__, xdr);
3549 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550}
3551
3552static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3553{
3554 int status = 0;
3555
3556 time->tv_sec = 0;
3557 time->tv_nsec = 0;
3558 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3559 return -EIO;
3560 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3561 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003562 if (status == 0)
3563 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3565 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003566 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 return status;
3568}
3569
3570static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3571{
3572 int status = 0;
3573
3574 time->tv_sec = 0;
3575 time->tv_nsec = 0;
3576 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3577 return -EIO;
3578 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3579 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003580 if (status == 0)
3581 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3583 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003584 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 return status;
3586}
3587
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003588static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3589 struct timespec *time)
3590{
3591 int status = 0;
3592
3593 time->tv_sec = 0;
3594 time->tv_nsec = 0;
3595 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3596 return -EIO;
3597 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3598 status = decode_attr_time(xdr, time);
3599 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3600 }
3601 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3602 (long)time->tv_nsec);
3603 return status;
3604}
3605
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3607{
3608 int status = 0;
3609
3610 time->tv_sec = 0;
3611 time->tv_nsec = 0;
3612 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3613 return -EIO;
3614 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3615 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003616 if (status == 0)
3617 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3619 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003620 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 return status;
3622}
3623
Al Viro8687b632006-10-19 23:28:48 -07003624static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625{
3626 unsigned int attrwords = XDR_QUADLEN(attrlen);
3627 unsigned int nwords = xdr->p - savep;
3628
3629 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003630 dprintk("%s: server returned incorrect attribute length: "
3631 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003632 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 attrwords << 2,
3634 (attrwords < nwords) ? '<' : '>',
3635 nwords << 2);
3636 return -EIO;
3637 }
3638 return 0;
3639}
3640
3641static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3642{
Al Viro8687b632006-10-19 23:28:48 -07003643 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644
Benny Halevyc0eae662009-08-14 17:20:14 +03003645 p = xdr_inline_decode(xdr, 20);
3646 if (unlikely(!p))
3647 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003648 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003649 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003650 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003652out_overflow:
3653 print_overflow_msg(__func__, xdr);
3654 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655}
3656
3657static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3658{
Al Viro8687b632006-10-19 23:28:48 -07003659 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 uint32_t supp, acc;
3661 int status;
3662
3663 status = decode_op_hdr(xdr, OP_ACCESS);
3664 if (status)
3665 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003666 p = xdr_inline_decode(xdr, 8);
3667 if (unlikely(!p))
3668 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003669 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003670 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 access->supported = supp;
3672 access->access = acc;
3673 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003674out_overflow:
3675 print_overflow_msg(__func__, xdr);
3676 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677}
3678
Benny Halevy07d30432009-08-14 17:19:52 +03003679static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680{
Al Viro8687b632006-10-19 23:28:48 -07003681 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003682
3683 p = xdr_inline_decode(xdr, len);
3684 if (likely(p)) {
3685 memcpy(buf, p, len);
3686 return 0;
3687 }
3688 print_overflow_msg(__func__, xdr);
3689 return -EIO;
3690}
3691
3692static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3693{
3694 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695}
3696
3697static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3698{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 int status;
3700
3701 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003702 if (status != -EIO)
3703 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003704 if (!status)
3705 status = decode_stateid(xdr, &res->stateid);
3706 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707}
3708
Benny Halevydb942bb2009-08-14 17:19:56 +03003709static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3710{
3711 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712}
3713
3714static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3715{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 int status;
3717
3718 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003719 if (!status)
3720 status = decode_verifier(xdr, res->verf->verifier);
3721 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722}
3723
3724static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3725{
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 uint32_t bmlen;
3728 int status;
3729
3730 status = decode_op_hdr(xdr, OP_CREATE);
3731 if (status)
3732 return status;
3733 if ((status = decode_change_info(xdr, cinfo)))
3734 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003735 p = xdr_inline_decode(xdr, 4);
3736 if (unlikely(!p))
3737 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003738 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003739 p = xdr_inline_decode(xdr, bmlen << 2);
3740 if (likely(p))
3741 return 0;
3742out_overflow:
3743 print_overflow_msg(__func__, xdr);
3744 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745}
3746
3747static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3748{
Al Viro8687b632006-10-19 23:28:48 -07003749 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003750 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 int status;
3752
3753 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3754 goto xdr_error;
3755 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3756 goto xdr_error;
3757 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3758 goto xdr_error;
3759 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3760 goto xdr_error;
3761 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3762 goto xdr_error;
3763 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3764 goto xdr_error;
3765 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3766 goto xdr_error;
3767 status = verify_attr_len(xdr, savep, attrlen);
3768xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 return status;
3771}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003772
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3774{
Al Viro8687b632006-10-19 23:28:48 -07003775 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003776 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003778
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3780 goto xdr_error;
3781 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3782 goto xdr_error;
3783 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3784 goto xdr_error;
3785
3786 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3787 goto xdr_error;
3788 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3789 goto xdr_error;
3790 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3791 goto xdr_error;
3792 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3793 goto xdr_error;
3794 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3795 goto xdr_error;
3796 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3797 goto xdr_error;
3798
3799 status = verify_attr_len(xdr, savep, attrlen);
3800xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003801 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 return status;
3803}
3804
3805static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3806{
Al Viro8687b632006-10-19 23:28:48 -07003807 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003808 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003810
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3812 goto xdr_error;
3813 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3814 goto xdr_error;
3815 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3816 goto xdr_error;
3817
3818 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3819 goto xdr_error;
3820 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3821 goto xdr_error;
3822
3823 status = verify_attr_len(xdr, savep, attrlen);
3824xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003825 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 return status;
3827}
3828
Bryan Schumakerae42c702010-10-21 16:33:17 -04003829static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3830 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003831 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832{
Trond Myklebustbca79472009-03-11 14:10:26 -04003833 int status;
3834 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003835 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003836 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003838 status = decode_attr_type(xdr, bitmap, &type);
3839 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 fattr->mode = 0;
3842 if (status != 0) {
3843 fattr->mode |= nfs_type2fmt[type];
3844 fattr->valid |= status;
3845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003847 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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_size(xdr, bitmap, &fattr->size);
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_fsid(xdr, bitmap, &fattr->fsid);
3858 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003861
Bryan Schumakerae42c702010-10-21 16:33:17 -04003862 status = decode_attr_error(xdr, bitmap);
3863 if (status < 0)
3864 goto xdr_error;
3865
3866 status = decode_attr_filehandle(xdr, bitmap, fh);
3867 if (status < 0)
3868 goto xdr_error;
3869
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003870 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3871 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003873 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003874
3875 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003876 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003877 fattr));
3878 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003879 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003880 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003881
3882 status = decode_attr_mode(xdr, bitmap, &fmode);
3883 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003885 if (status != 0) {
3886 fattr->mode |= fmode;
3887 fattr->valid |= status;
3888 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003889
3890 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3891 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003893 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003894
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003895 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3896 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003897 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003899 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003900
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003901 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3902 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003903 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003906
3907 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3908 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003911
3912 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3913 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003915 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003916
3917 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3918 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003921
3922 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3923 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003926
3927 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3928 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003930 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003931
3932 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3933 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003934 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04003935 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003936 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003937 fattr->valid |= status;
3938 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003939
Bryan Schumakerae42c702010-10-21 16:33:17 -04003940xdr_error:
3941 dprintk("%s: xdr returned %d\n", __func__, -status);
3942 return status;
3943}
3944
3945static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3946 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3947{
3948 __be32 *savep;
3949 uint32_t attrlen,
3950 bitmap[2] = {0};
3951 int status;
3952
3953 status = decode_op_hdr(xdr, OP_GETATTR);
3954 if (status < 0)
3955 goto xdr_error;
3956
3957 status = decode_attr_bitmap(xdr, bitmap);
3958 if (status < 0)
3959 goto xdr_error;
3960
3961 status = decode_attr_length(xdr, &attrlen, &savep);
3962 if (status < 0)
3963 goto xdr_error;
3964
3965 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
3966 if (status < 0)
3967 goto xdr_error;
3968
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003969 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003971 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 return status;
3973}
3974
Bryan Schumakerae42c702010-10-21 16:33:17 -04003975static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3976 const struct nfs_server *server, int may_sleep)
3977{
3978 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
3979}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980
Andy Adamson504913f2010-10-20 00:17:57 -04003981/*
3982 * Decode potentially multiple layout types. Currently we only support
3983 * one layout driver per file system.
3984 */
3985static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
3986 uint32_t *layouttype)
3987{
3988 uint32_t *p;
3989 int num;
3990
3991 p = xdr_inline_decode(xdr, 4);
3992 if (unlikely(!p))
3993 goto out_overflow;
3994 num = be32_to_cpup(p);
3995
3996 /* pNFS is not supported by the underlying file system */
3997 if (num == 0) {
3998 *layouttype = 0;
3999 return 0;
4000 }
4001 if (num > 1)
4002 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4003 "per filesystem not supported\n", __func__);
4004
4005 /* Decode and set first layout type, move xdr->p past unused types */
4006 p = xdr_inline_decode(xdr, num * 4);
4007 if (unlikely(!p))
4008 goto out_overflow;
4009 *layouttype = be32_to_cpup(p);
4010 return 0;
4011out_overflow:
4012 print_overflow_msg(__func__, xdr);
4013 return -EIO;
4014}
4015
4016/*
4017 * The type of file system exported.
4018 * Note we must ensure that layouttype is set in any non-error case.
4019 */
4020static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4021 uint32_t *layouttype)
4022{
4023 int status = 0;
4024
4025 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4026 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4027 return -EIO;
4028 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4029 status = decode_first_pnfs_layout_type(xdr, layouttype);
4030 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4031 } else
4032 *layouttype = 0;
4033 return status;
4034}
4035
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4037{
Al Viro8687b632006-10-19 23:28:48 -07004038 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 uint32_t attrlen, bitmap[2];
4040 int status;
4041
4042 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4043 goto xdr_error;
4044 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4045 goto xdr_error;
4046 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4047 goto xdr_error;
4048
4049 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4050
4051 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4052 goto xdr_error;
4053 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4054 goto xdr_error;
4055 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4056 goto xdr_error;
4057 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4058 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4059 goto xdr_error;
4060 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004061 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4062 if (status != 0)
4063 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004064 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4065 if (status != 0)
4066 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
4068 status = verify_attr_len(xdr, savep, attrlen);
4069xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004070 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 return status;
4072}
4073
4074static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4075{
Al Viro8687b632006-10-19 23:28:48 -07004076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 uint32_t len;
4078 int status;
4079
Trond Myklebust99367812007-07-17 21:52:41 -04004080 /* Zero handle first to allow comparisons */
4081 memset(fh, 0, sizeof(*fh));
4082
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 status = decode_op_hdr(xdr, OP_GETFH);
4084 if (status)
4085 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086
Benny Halevyc0eae662009-08-14 17:20:14 +03004087 p = xdr_inline_decode(xdr, 4);
4088 if (unlikely(!p))
4089 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004090 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 if (len > NFS4_FHSIZE)
4092 return -EIO;
4093 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004094 p = xdr_inline_decode(xdr, len);
4095 if (unlikely(!p))
4096 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004097 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004099out_overflow:
4100 print_overflow_msg(__func__, xdr);
4101 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102}
4103
4104static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4105{
4106 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004107
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 status = decode_op_hdr(xdr, OP_LINK);
4109 if (status)
4110 return status;
4111 return decode_change_info(xdr, cinfo);
4112}
4113
4114/*
4115 * We create the owner, so we know a proper owner.id length is 4.
4116 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004117static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004119 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004120 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004121 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004123 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004124 if (unlikely(!p))
4125 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004126 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004127 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004128 type = be32_to_cpup(p++); /* 4 byte read */
4129 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004130 fl->fl_start = (loff_t)offset;
4131 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4132 if (length == ~(uint64_t)0)
4133 fl->fl_end = OFFSET_MAX;
4134 fl->fl_type = F_WRLCK;
4135 if (type & 1)
4136 fl->fl_type = F_RDLCK;
4137 fl->fl_pid = 0;
4138 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004139 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4140 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4141 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004142 if (likely(p))
4143 return -NFS4ERR_DENIED;
4144out_overflow:
4145 print_overflow_msg(__func__, xdr);
4146 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147}
4148
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004149static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 int status;
4152
4153 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004154 if (status == -EIO)
4155 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004157 status = decode_stateid(xdr, &res->stateid);
4158 if (unlikely(status))
4159 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004161 status = decode_lock_denied(xdr, NULL);
4162 if (res->open_seqid != NULL)
4163 nfs_increment_open_seqid(status, res->open_seqid);
4164 nfs_increment_lock_seqid(status, res->lock_seqid);
4165out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 return status;
4167}
4168
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004169static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170{
4171 int status;
4172 status = decode_op_hdr(xdr, OP_LOCKT);
4173 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004174 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 return status;
4176}
4177
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004178static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 int status;
4181
4182 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004183 if (status != -EIO)
4184 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004185 if (status == 0)
4186 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return status;
4188}
4189
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004190static int decode_release_lockowner(struct xdr_stream *xdr)
4191{
4192 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4193}
4194
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195static int decode_lookup(struct xdr_stream *xdr)
4196{
4197 return decode_op_hdr(xdr, OP_LOOKUP);
4198}
4199
4200/* This is too sick! */
4201static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4202{
Andy Adamson05d564f2008-12-23 16:06:15 -05004203 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 uint32_t limit_type, nblocks, blocksize;
4205
Benny Halevyc0eae662009-08-14 17:20:14 +03004206 p = xdr_inline_decode(xdr, 12);
4207 if (unlikely(!p))
4208 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004209 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004211 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004212 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004213 break;
4214 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004215 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004216 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004217 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 }
4219 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004220out_overflow:
4221 print_overflow_msg(__func__, xdr);
4222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223}
4224
4225static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4226{
Andy Adamson05d564f2008-12-23 16:06:15 -05004227 __be32 *p;
4228 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004229 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230
Benny Halevyc0eae662009-08-14 17:20:14 +03004231 p = xdr_inline_decode(xdr, 4);
4232 if (unlikely(!p))
4233 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004234 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4236 res->delegation_type = 0;
4237 return 0;
4238 }
Benny Halevy07d30432009-08-14 17:19:52 +03004239 status = decode_stateid(xdr, &res->delegation);
4240 if (unlikely(status))
4241 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004242 p = xdr_inline_decode(xdr, 4);
4243 if (unlikely(!p))
4244 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004245 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004246
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004248 case NFS4_OPEN_DELEGATE_READ:
4249 res->delegation_type = FMODE_READ;
4250 break;
4251 case NFS4_OPEN_DELEGATE_WRITE:
4252 res->delegation_type = FMODE_WRITE|FMODE_READ;
4253 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 return -EIO;
4255 }
David Howells7539bba2006-08-22 20:06:09 -04004256 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004257out_overflow:
4258 print_overflow_msg(__func__, xdr);
4259 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260}
4261
4262static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4263{
Andy Adamson05d564f2008-12-23 16:06:15 -05004264 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004265 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004266 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267
Andy Adamson05d564f2008-12-23 16:06:15 -05004268 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004269 if (status != -EIO)
4270 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004271 if (!status)
4272 status = decode_stateid(xdr, &res->stateid);
4273 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004274 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275
Andy Adamson05d564f2008-12-23 16:06:15 -05004276 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
Benny Halevyc0eae662009-08-14 17:20:14 +03004278 p = xdr_inline_decode(xdr, 8);
4279 if (unlikely(!p))
4280 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004281 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004282 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004283 if (bmlen > 10)
4284 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285
Benny Halevyc0eae662009-08-14 17:20:14 +03004286 p = xdr_inline_decode(xdr, bmlen << 2);
4287 if (unlikely(!p))
4288 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004289 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4290 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004291 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004292 for (; i < NFS4_BITMAP_SIZE; i++)
4293 res->attrset[i] = 0;
4294
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 return decode_delegation(xdr, res);
4296xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004297 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004299out_overflow:
4300 print_overflow_msg(__func__, xdr);
4301 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302}
4303
4304static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4305{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 int status;
4307
Andy Adamson05d564f2008-12-23 16:06:15 -05004308 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004309 if (status != -EIO)
4310 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004311 if (!status)
4312 status = decode_stateid(xdr, &res->stateid);
4313 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314}
4315
4316static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4317{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 int status;
4319
4320 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004321 if (status != -EIO)
4322 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004323 if (!status)
4324 status = decode_stateid(xdr, &res->stateid);
4325 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326}
4327
4328static int decode_putfh(struct xdr_stream *xdr)
4329{
4330 return decode_op_hdr(xdr, OP_PUTFH);
4331}
4332
4333static int decode_putrootfh(struct xdr_stream *xdr)
4334{
4335 return decode_op_hdr(xdr, OP_PUTROOTFH);
4336}
4337
4338static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4339{
4340 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 uint32_t count, eof, recvd, hdrlen;
4343 int status;
4344
4345 status = decode_op_hdr(xdr, OP_READ);
4346 if (status)
4347 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004348 p = xdr_inline_decode(xdr, 8);
4349 if (unlikely(!p))
4350 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004351 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004352 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4354 recvd = req->rq_rcv_buf.len - hdrlen;
4355 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004356 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 "count %u > recvd %u\n", count, recvd);
4358 count = recvd;
4359 eof = 0;
4360 }
4361 xdr_read_pages(xdr, count);
4362 res->eof = eof;
4363 res->count = count;
4364 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004365out_overflow:
4366 print_overflow_msg(__func__, xdr);
4367 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368}
4369
4370static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4371{
4372 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004374 size_t hdrlen;
4375 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004376 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377
4378 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004379 if (!status)
4380 status = decode_verifier(xdr, readdir->verifier.data);
4381 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004383 dprintk("%s: verifier = %08x:%08x\n",
4384 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004385 ((u32 *)readdir->verifier.data)[0],
4386 ((u32 *)readdir->verifier.data)[1]);
4387
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388
Benny Halevydb942bb2009-08-14 17:19:56 +03004389 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 recvd = rcvbuf->len - hdrlen;
4391 if (pglen > recvd)
4392 pglen = recvd;
4393 xdr_read_pages(xdr, pglen);
4394
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004395
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397}
4398
4399static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4400{
4401 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4402 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004403 size_t hdrlen;
4404 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004405 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 int status;
4407
4408 status = decode_op_hdr(xdr, OP_READLINK);
4409 if (status)
4410 return status;
4411
4412 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004413 p = xdr_inline_decode(xdr, 4);
4414 if (unlikely(!p))
4415 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004416 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004418 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 return -ENAMETOOLONG;
4420 }
4421 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4422 recvd = req->rq_rcv_buf.len - hdrlen;
4423 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004424 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 "count %u > recvd %u\n", len, recvd);
4426 return -EIO;
4427 }
4428 xdr_read_pages(xdr, len);
4429 /*
4430 * The XDR encode routine has set things up so that
4431 * the link text will be copied directly into the
4432 * buffer. We just have to do overflow-checking,
4433 * and and null-terminate the text (the VFS expects
4434 * null-termination).
4435 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004436 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004438out_overflow:
4439 print_overflow_msg(__func__, xdr);
4440 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441}
4442
4443static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4444{
4445 int status;
4446
4447 status = decode_op_hdr(xdr, OP_REMOVE);
4448 if (status)
4449 goto out;
4450 status = decode_change_info(xdr, cinfo);
4451out:
4452 return status;
4453}
4454
4455static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4456 struct nfs4_change_info *new_cinfo)
4457{
4458 int status;
4459
4460 status = decode_op_hdr(xdr, OP_RENAME);
4461 if (status)
4462 goto out;
4463 if ((status = decode_change_info(xdr, old_cinfo)))
4464 goto out;
4465 status = decode_change_info(xdr, new_cinfo);
4466out:
4467 return status;
4468}
4469
4470static int decode_renew(struct xdr_stream *xdr)
4471{
4472 return decode_op_hdr(xdr, OP_RENEW);
4473}
4474
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004475static int
4476decode_restorefh(struct xdr_stream *xdr)
4477{
4478 return decode_op_hdr(xdr, OP_RESTOREFH);
4479}
4480
J. Bruce Fields029d1052005-06-22 17:16:22 +00004481static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4482 size_t *acl_len)
4483{
Al Viro8687b632006-10-19 23:28:48 -07004484 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004485 uint32_t attrlen,
4486 bitmap[2] = {0};
4487 struct kvec *iov = req->rq_rcv_buf.head;
4488 int status;
4489
4490 *acl_len = 0;
4491 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4492 goto out;
4493 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4494 goto out;
4495 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4496 goto out;
4497
4498 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4499 return -EIO;
4500 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004501 size_t hdrlen;
4502 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004503
4504 /* We ignore &savep and don't do consistency checks on
4505 * the attr length. Let userspace figure it out.... */
4506 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4507 recvd = req->rq_rcv_buf.len - hdrlen;
4508 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004509 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004510 " acl reply: attrlen %u > recvd %u\n",
4511 attrlen, recvd);
4512 return -EINVAL;
4513 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004514 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004515 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004516 } else
4517 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004518
4519out:
4520 return status;
4521}
4522
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523static int
4524decode_savefh(struct xdr_stream *xdr)
4525{
4526 return decode_op_hdr(xdr, OP_SAVEFH);
4527}
4528
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004529static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530{
Al Viro8687b632006-10-19 23:28:48 -07004531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 uint32_t bmlen;
4533 int status;
4534
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 status = decode_op_hdr(xdr, OP_SETATTR);
4536 if (status)
4537 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004538 p = xdr_inline_decode(xdr, 4);
4539 if (unlikely(!p))
4540 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004541 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004542 p = xdr_inline_decode(xdr, bmlen << 2);
4543 if (likely(p))
4544 return 0;
4545out_overflow:
4546 print_overflow_msg(__func__, xdr);
4547 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548}
4549
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004550static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551{
Al Viro8687b632006-10-19 23:28:48 -07004552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 uint32_t opnum;
4554 int32_t nfserr;
4555
Benny Halevyc0eae662009-08-14 17:20:14 +03004556 p = xdr_inline_decode(xdr, 8);
4557 if (unlikely(!p))
4558 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004559 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004561 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004562 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 return -EIO;
4564 }
Benny Halevycccddf42009-08-14 17:20:19 +03004565 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004567 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4568 if (unlikely(!p))
4569 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004570 p = xdr_decode_hyper(p, &res->clientid);
4571 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 } else if (nfserr == NFSERR_CLID_INUSE) {
4573 uint32_t len;
4574
4575 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004576 p = xdr_inline_decode(xdr, 4);
4577 if (unlikely(!p))
4578 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004579 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004580 p = xdr_inline_decode(xdr, len);
4581 if (unlikely(!p))
4582 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583
4584 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004585 p = xdr_inline_decode(xdr, 4);
4586 if (unlikely(!p))
4587 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004588 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004589 p = xdr_inline_decode(xdr, len);
4590 if (unlikely(!p))
4591 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 return -NFSERR_CLID_INUSE;
4593 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004594 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595
4596 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004597out_overflow:
4598 print_overflow_msg(__func__, xdr);
4599 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600}
4601
4602static int decode_setclientid_confirm(struct xdr_stream *xdr)
4603{
4604 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4605}
4606
4607static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4608{
Al Viro8687b632006-10-19 23:28:48 -07004609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 int status;
4611
4612 status = decode_op_hdr(xdr, OP_WRITE);
4613 if (status)
4614 return status;
4615
Benny Halevyc0eae662009-08-14 17:20:14 +03004616 p = xdr_inline_decode(xdr, 16);
4617 if (unlikely(!p))
4618 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004619 res->count = be32_to_cpup(p++);
4620 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004621 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004623out_overflow:
4624 print_overflow_msg(__func__, xdr);
4625 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626}
4627
4628static int decode_delegreturn(struct xdr_stream *xdr)
4629{
4630 return decode_op_hdr(xdr, OP_DELEGRETURN);
4631}
4632
Benny Halevy99fe60d2009-04-01 09:22:29 -04004633#if defined(CONFIG_NFS_V4_1)
4634static int decode_exchange_id(struct xdr_stream *xdr,
4635 struct nfs41_exchange_id_res *res)
4636{
4637 __be32 *p;
4638 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004639 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004640 int status;
4641 struct nfs_client *clp = res->client;
4642
4643 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4644 if (status)
4645 return status;
4646
Benny Halevyc0eae662009-08-14 17:20:14 +03004647 p = xdr_inline_decode(xdr, 8);
4648 if (unlikely(!p))
4649 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004650 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004651 p = xdr_inline_decode(xdr, 12);
4652 if (unlikely(!p))
4653 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004654 clp->cl_seqid = be32_to_cpup(p++);
4655 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004656
4657 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004658 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004659 if (dummy != SP4_NONE)
4660 return -EIO;
4661
4662 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004663 p = xdr_inline_decode(xdr, 8);
4664 if (unlikely(!p))
4665 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004666
4667 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004668 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4669 if (unlikely(status))
4670 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004671
4672 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004673 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4674 if (unlikely(status))
4675 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004676
4677 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004678 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4679 if (unlikely(status))
4680 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004681
4682 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004683out_overflow:
4684 print_overflow_msg(__func__, xdr);
4685 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004686}
Andy Adamsonfc931582009-04-01 09:22:31 -04004687
4688static int decode_chan_attrs(struct xdr_stream *xdr,
4689 struct nfs4_channel_attrs *attrs)
4690{
4691 __be32 *p;
4692 u32 nr_attrs;
4693
Benny Halevyc0eae662009-08-14 17:20:14 +03004694 p = xdr_inline_decode(xdr, 28);
4695 if (unlikely(!p))
4696 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004697 attrs->headerpadsz = be32_to_cpup(p++);
4698 attrs->max_rqst_sz = be32_to_cpup(p++);
4699 attrs->max_resp_sz = be32_to_cpup(p++);
4700 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4701 attrs->max_ops = be32_to_cpup(p++);
4702 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004703 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004704 if (unlikely(nr_attrs > 1)) {
4705 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4706 __func__, nr_attrs);
4707 return -EINVAL;
4708 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004709 if (nr_attrs == 1) {
4710 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4711 if (unlikely(!p))
4712 goto out_overflow;
4713 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004714 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004715out_overflow:
4716 print_overflow_msg(__func__, xdr);
4717 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004718}
4719
Benny Halevye78291e2009-08-14 17:20:00 +03004720static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4721{
4722 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004723}
4724
4725static int decode_create_session(struct xdr_stream *xdr,
4726 struct nfs41_create_session_res *res)
4727{
4728 __be32 *p;
4729 int status;
4730 struct nfs_client *clp = res->client;
4731 struct nfs4_session *session = clp->cl_session;
4732
4733 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004734 if (!status)
4735 status = decode_sessionid(xdr, &session->sess_id);
4736 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004737 return status;
4738
Andy Adamsonfc931582009-04-01 09:22:31 -04004739 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004740 p = xdr_inline_decode(xdr, 8);
4741 if (unlikely(!p))
4742 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004743 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004744 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004745
4746 /* Channel attributes */
4747 status = decode_chan_attrs(xdr, &session->fc_attrs);
4748 if (!status)
4749 status = decode_chan_attrs(xdr, &session->bc_attrs);
4750 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004751out_overflow:
4752 print_overflow_msg(__func__, xdr);
4753 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004754}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004755
4756static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4757{
4758 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4759}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004760
4761static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4762{
4763 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4764}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004765#endif /* CONFIG_NFS_V4_1 */
4766
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004767static int decode_sequence(struct xdr_stream *xdr,
4768 struct nfs4_sequence_res *res,
4769 struct rpc_rqst *rqstp)
4770{
4771#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004772 struct nfs4_sessionid id;
4773 u32 dummy;
4774 int status;
4775 __be32 *p;
4776
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004777 if (!res->sr_session)
4778 return 0;
4779
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004780 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004781 if (!status)
4782 status = decode_sessionid(xdr, &id);
4783 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004784 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004785
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004786 /*
4787 * If the server returns different values for sessionID, slotID or
4788 * sequence number, the server is looney tunes.
4789 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004790 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004791
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004792 if (memcmp(id.data, res->sr_session->sess_id.data,
4793 NFS4_MAX_SESSIONID_LEN)) {
4794 dprintk("%s Invalid session id\n", __func__);
4795 goto out_err;
4796 }
Benny Halevye78291e2009-08-14 17:20:00 +03004797
Benny Halevyc0eae662009-08-14 17:20:14 +03004798 p = xdr_inline_decode(xdr, 20);
4799 if (unlikely(!p))
4800 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004801
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004802 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004803 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004804 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004805 dprintk("%s Invalid sequence number\n", __func__);
4806 goto out_err;
4807 }
4808 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004809 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004810 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004811 dprintk("%s Invalid slot id\n", __func__);
4812 goto out_err;
4813 }
4814 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004815 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004816 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004817 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004818 /* result flags */
4819 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004820 status = 0;
4821out_err:
4822 res->sr_status = status;
4823 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004824out_overflow:
4825 print_overflow_msg(__func__, xdr);
4826 status = -EIO;
4827 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004828#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004829 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004830#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004831}
4832
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833/*
Benny Halevy49c25592008-12-23 16:06:16 -05004834 * END OF "GENERIC" DECODE ROUTINES.
4835 */
4836
4837/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 * Decode OPEN_DOWNGRADE response
4839 */
Al Viro8687b632006-10-19 23:28:48 -07004840static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841{
Andy Adamson05d564f2008-12-23 16:06:15 -05004842 struct xdr_stream xdr;
4843 struct compound_hdr hdr;
4844 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Andy Adamson05d564f2008-12-23 16:06:15 -05004846 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4847 status = decode_compound_hdr(&xdr, &hdr);
4848 if (status)
4849 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004850 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4851 if (status)
4852 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004853 status = decode_putfh(&xdr);
4854 if (status)
4855 goto out;
4856 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004857 if (status != 0)
4858 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004859 decode_getfattr(&xdr, res->fattr, res->server,
4860 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004862 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863}
4864
4865/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 * Decode ACCESS response
4867 */
Al Viro8687b632006-10-19 23:28:48 -07004868static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869{
4870 struct xdr_stream xdr;
4871 struct compound_hdr hdr;
4872 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004873
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004875 status = decode_compound_hdr(&xdr, &hdr);
4876 if (status)
4877 goto out;
4878 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4879 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004881 status = decode_putfh(&xdr);
4882 if (status != 0)
4883 goto out;
4884 status = decode_access(&xdr, res);
4885 if (status != 0)
4886 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004887 decode_getfattr(&xdr, res->fattr, res->server,
4888 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889out:
4890 return status;
4891}
4892
4893/*
4894 * Decode LOOKUP response
4895 */
Al Viro8687b632006-10-19 23:28:48 -07004896static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897{
4898 struct xdr_stream xdr;
4899 struct compound_hdr hdr;
4900 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004901
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004903 status = decode_compound_hdr(&xdr, &hdr);
4904 if (status)
4905 goto out;
4906 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4907 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 goto out;
4909 if ((status = decode_putfh(&xdr)) != 0)
4910 goto out;
4911 if ((status = decode_lookup(&xdr)) != 0)
4912 goto out;
4913 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4914 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004915 status = decode_getfattr(&xdr, res->fattr, res->server
4916 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917out:
4918 return status;
4919}
4920
4921/*
4922 * Decode LOOKUP_ROOT response
4923 */
Al Viro8687b632006-10-19 23:28:48 -07004924static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925{
4926 struct xdr_stream xdr;
4927 struct compound_hdr hdr;
4928 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004929
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004931 status = decode_compound_hdr(&xdr, &hdr);
4932 if (status)
4933 goto out;
4934 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4935 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 goto out;
4937 if ((status = decode_putrootfh(&xdr)) != 0)
4938 goto out;
4939 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004940 status = decode_getfattr(&xdr, res->fattr, res->server,
4941 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942out:
4943 return status;
4944}
4945
4946/*
4947 * Decode REMOVE response
4948 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004949static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950{
4951 struct xdr_stream xdr;
4952 struct compound_hdr hdr;
4953 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004954
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004956 status = decode_compound_hdr(&xdr, &hdr);
4957 if (status)
4958 goto out;
4959 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4960 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004962 if ((status = decode_putfh(&xdr)) != 0)
4963 goto out;
4964 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4965 goto out;
Trond Myklebustd3468902010-04-16 16:22:50 -04004966 decode_getfattr(&xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004967 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968out:
4969 return status;
4970}
4971
4972/*
4973 * Decode RENAME response
4974 */
Jeff Laytone8582a82010-09-17 17:31:06 -04004975static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976{
4977 struct xdr_stream xdr;
4978 struct compound_hdr hdr;
4979 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004980
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004982 status = decode_compound_hdr(&xdr, &hdr);
4983 if (status)
4984 goto out;
4985 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4986 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 goto out;
4988 if ((status = decode_putfh(&xdr)) != 0)
4989 goto out;
4990 if ((status = decode_savefh(&xdr)) != 0)
4991 goto out;
4992 if ((status = decode_putfh(&xdr)) != 0)
4993 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004994 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4995 goto out;
4996 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004997 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4998 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004999 goto out;
5000 if ((status = decode_restorefh(&xdr)) != 0)
5001 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005002 decode_getfattr(&xdr, res->old_fattr, res->server,
5003 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004out:
5005 return status;
5006}
5007
5008/*
5009 * Decode LINK response
5010 */
Al Viro8687b632006-10-19 23:28:48 -07005011static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012{
5013 struct xdr_stream xdr;
5014 struct compound_hdr hdr;
5015 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005016
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005018 status = decode_compound_hdr(&xdr, &hdr);
5019 if (status)
5020 goto out;
5021 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5022 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 goto out;
5024 if ((status = decode_putfh(&xdr)) != 0)
5025 goto out;
5026 if ((status = decode_savefh(&xdr)) != 0)
5027 goto out;
5028 if ((status = decode_putfh(&xdr)) != 0)
5029 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005030 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
5031 goto out;
5032 /*
5033 * Note order: OP_LINK leaves the directory as the current
5034 * filehandle.
5035 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005036 if (decode_getfattr(&xdr, res->dir_attr, res->server,
5037 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005038 goto out;
5039 if ((status = decode_restorefh(&xdr)) != 0)
5040 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005041 decode_getfattr(&xdr, res->fattr, res->server,
5042 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043out:
5044 return status;
5045}
5046
5047/*
5048 * Decode CREATE response
5049 */
Al Viro8687b632006-10-19 23:28:48 -07005050static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051{
5052 struct xdr_stream xdr;
5053 struct compound_hdr hdr;
5054 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005055
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005057 status = decode_compound_hdr(&xdr, &hdr);
5058 if (status)
5059 goto out;
5060 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5061 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 goto out;
5063 if ((status = decode_putfh(&xdr)) != 0)
5064 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005065 if ((status = decode_savefh(&xdr)) != 0)
5066 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
5068 goto out;
5069 if ((status = decode_getfh(&xdr, res->fh)) != 0)
5070 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005071 if (decode_getfattr(&xdr, res->fattr, res->server,
5072 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005073 goto out;
5074 if ((status = decode_restorefh(&xdr)) != 0)
5075 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005076 decode_getfattr(&xdr, res->dir_fattr, res->server,
5077 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078out:
5079 return status;
5080}
5081
5082/*
5083 * Decode SYMLINK response
5084 */
Al Viro8687b632006-10-19 23:28:48 -07005085static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086{
5087 return nfs4_xdr_dec_create(rqstp, p, res);
5088}
5089
5090/*
5091 * Decode GETATTR response
5092 */
Al Viro8687b632006-10-19 23:28:48 -07005093static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094{
5095 struct xdr_stream xdr;
5096 struct compound_hdr hdr;
5097 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005098
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5100 status = decode_compound_hdr(&xdr, &hdr);
5101 if (status)
5102 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005103 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5104 if (status)
5105 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 status = decode_putfh(&xdr);
5107 if (status)
5108 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005109 status = decode_getfattr(&xdr, res->fattr, res->server,
5110 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111out:
5112 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113}
5114
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005115/*
5116 * Encode an SETACL request
5117 */
5118static int
Al Viro8687b632006-10-19 23:28:48 -07005119nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005120{
Andy Adamson05d564f2008-12-23 16:06:15 -05005121 struct xdr_stream xdr;
5122 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005123 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005124 };
5125 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005126
Andy Adamson05d564f2008-12-23 16:06:15 -05005127 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04005128 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005129 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05005130 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005131 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005132 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005133 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005134}
Andy Adamson05d564f2008-12-23 16:06:15 -05005135
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005136/*
5137 * Decode SETACL response
5138 */
5139static int
Benny Halevy73c403a2009-04-01 09:22:01 -04005140nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
5141 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005142{
5143 struct xdr_stream xdr;
5144 struct compound_hdr hdr;
5145 int status;
5146
5147 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5148 status = decode_compound_hdr(&xdr, &hdr);
5149 if (status)
5150 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005151 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5152 if (status)
5153 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005154 status = decode_putfh(&xdr);
5155 if (status)
5156 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005157 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005158out:
5159 return status;
5160}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161
5162/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005163 * Decode GETACL response
5164 */
5165static int
Benny Halevy663c79b2009-04-01 09:21:59 -04005166nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
5167 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005168{
5169 struct xdr_stream xdr;
5170 struct compound_hdr hdr;
5171 int status;
5172
5173 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5174 status = decode_compound_hdr(&xdr, &hdr);
5175 if (status)
5176 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005177 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5178 if (status)
5179 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005180 status = decode_putfh(&xdr);
5181 if (status)
5182 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04005183 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005184
5185out:
5186 return status;
5187}
5188
5189/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 * Decode CLOSE response
5191 */
Al Viro8687b632006-10-19 23:28:48 -07005192static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193{
Andy Adamson05d564f2008-12-23 16:06:15 -05005194 struct xdr_stream xdr;
5195 struct compound_hdr hdr;
5196 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197
Andy Adamson05d564f2008-12-23 16:06:15 -05005198 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5199 status = decode_compound_hdr(&xdr, &hdr);
5200 if (status)
5201 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005202 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5203 if (status)
5204 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005205 status = decode_putfh(&xdr);
5206 if (status)
5207 goto out;
5208 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005209 if (status != 0)
5210 goto out;
5211 /*
5212 * Note: Server may do delete on close for this file
5213 * in which case the getattr call will fail with
5214 * an ESTALE error. Shouldn't be a problem,
5215 * though, since fattr->valid will remain unset.
5216 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005217 decode_getfattr(&xdr, res->fattr, res->server,
5218 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005220 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221}
5222
5223/*
5224 * Decode OPEN response
5225 */
Al Viro8687b632006-10-19 23:28:48 -07005226static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227{
Andy Adamson05d564f2008-12-23 16:06:15 -05005228 struct xdr_stream xdr;
5229 struct compound_hdr hdr;
5230 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231
Andy Adamson05d564f2008-12-23 16:06:15 -05005232 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5233 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005234 if (status)
5235 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005236 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5237 if (status)
5238 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005239 status = decode_putfh(&xdr);
5240 if (status)
5241 goto out;
5242 status = decode_savefh(&xdr);
5243 if (status)
5244 goto out;
5245 status = decode_open(&xdr, res);
5246 if (status)
5247 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005248 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005250 if (decode_getfattr(&xdr, res->f_attr, res->server,
5251 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005252 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005253 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005254 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005255 decode_getfattr(&xdr, res->dir_attr, res->server,
5256 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005258 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259}
5260
5261/*
5262 * Decode OPEN_CONFIRM response
5263 */
Al Viro8687b632006-10-19 23:28:48 -07005264static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265{
Andy Adamson05d564f2008-12-23 16:06:15 -05005266 struct xdr_stream xdr;
5267 struct compound_hdr hdr;
5268 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269
Andy Adamson05d564f2008-12-23 16:06:15 -05005270 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5271 status = decode_compound_hdr(&xdr, &hdr);
5272 if (status)
5273 goto out;
5274 status = decode_putfh(&xdr);
5275 if (status)
5276 goto out;
5277 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005279 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280}
5281
5282/*
5283 * Decode OPEN response
5284 */
Al Viro8687b632006-10-19 23:28:48 -07005285static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286{
Andy Adamson05d564f2008-12-23 16:06:15 -05005287 struct xdr_stream xdr;
5288 struct compound_hdr hdr;
5289 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
Andy Adamson05d564f2008-12-23 16:06:15 -05005291 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;
Andy Adamson05d564f2008-12-23 16:06:15 -05005298 status = decode_putfh(&xdr);
5299 if (status)
5300 goto out;
5301 status = decode_open(&xdr, res);
5302 if (status)
5303 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005304 decode_getfattr(&xdr, res->f_attr, res->server,
5305 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005307 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308}
5309
5310/*
5311 * Decode SETATTR response
5312 */
Al Viro8687b632006-10-19 23:28:48 -07005313static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314{
Andy Adamson05d564f2008-12-23 16:06:15 -05005315 struct xdr_stream xdr;
5316 struct compound_hdr hdr;
5317 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
Andy Adamson05d564f2008-12-23 16:06:15 -05005319 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5320 status = decode_compound_hdr(&xdr, &hdr);
5321 if (status)
5322 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005323 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5324 if (status)
5325 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005326 status = decode_putfh(&xdr);
5327 if (status)
5328 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005329 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005330 if (status)
5331 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005332 decode_getfattr(&xdr, res->fattr, res->server,
5333 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005335 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336}
5337
5338/*
5339 * Decode LOCK response
5340 */
Al Viro8687b632006-10-19 23:28:48 -07005341static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342{
5343 struct xdr_stream xdr;
5344 struct compound_hdr hdr;
5345 int status;
5346
5347 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5348 status = decode_compound_hdr(&xdr, &hdr);
5349 if (status)
5350 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005351 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5352 if (status)
5353 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354 status = decode_putfh(&xdr);
5355 if (status)
5356 goto out;
5357 status = decode_lock(&xdr, res);
5358out:
5359 return status;
5360}
5361
5362/*
5363 * Decode LOCKT response
5364 */
Al Viro8687b632006-10-19 23:28:48 -07005365static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366{
5367 struct xdr_stream xdr;
5368 struct compound_hdr hdr;
5369 int status;
5370
5371 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5372 status = decode_compound_hdr(&xdr, &hdr);
5373 if (status)
5374 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005375 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5376 if (status)
5377 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 status = decode_putfh(&xdr);
5379 if (status)
5380 goto out;
5381 status = decode_lockt(&xdr, res);
5382out:
5383 return status;
5384}
5385
5386/*
5387 * Decode LOCKU response
5388 */
Al Viro8687b632006-10-19 23:28:48 -07005389static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390{
5391 struct xdr_stream xdr;
5392 struct compound_hdr hdr;
5393 int status;
5394
5395 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5396 status = decode_compound_hdr(&xdr, &hdr);
5397 if (status)
5398 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005399 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5400 if (status)
5401 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402 status = decode_putfh(&xdr);
5403 if (status)
5404 goto out;
5405 status = decode_locku(&xdr, res);
5406out:
5407 return status;
5408}
5409
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005410static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
5411{
5412 struct xdr_stream xdr;
5413 struct compound_hdr hdr;
5414 int status;
5415
5416 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5417 status = decode_compound_hdr(&xdr, &hdr);
5418 if (!status)
5419 status = decode_release_lockowner(&xdr);
5420 return status;
5421}
5422
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423/*
5424 * Decode READLINK response
5425 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005426static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5427 struct nfs4_readlink_res *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_readlink(&xdr, rqstp);
5444out:
5445 return status;
5446}
5447
5448/*
5449 * Decode READDIR response
5450 */
Al Viro8687b632006-10-19 23:28:48 -07005451static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452{
5453 struct xdr_stream xdr;
5454 struct compound_hdr hdr;
5455 int status;
5456
5457 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5458 status = decode_compound_hdr(&xdr, &hdr);
5459 if (status)
5460 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005461 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5462 if (status)
5463 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 status = decode_putfh(&xdr);
5465 if (status)
5466 goto out;
5467 status = decode_readdir(&xdr, rqstp, res);
5468out:
5469 return status;
5470}
5471
5472/*
5473 * Decode Read response
5474 */
Al Viro8687b632006-10-19 23:28:48 -07005475static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476{
5477 struct xdr_stream xdr;
5478 struct compound_hdr hdr;
5479 int status;
5480
5481 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5482 status = decode_compound_hdr(&xdr, &hdr);
5483 if (status)
5484 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005485 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5486 if (status)
5487 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488 status = decode_putfh(&xdr);
5489 if (status)
5490 goto out;
5491 status = decode_read(&xdr, rqstp, res);
5492 if (!status)
5493 status = res->count;
5494out:
5495 return status;
5496}
5497
5498/*
5499 * Decode WRITE response
5500 */
Al Viro8687b632006-10-19 23:28:48 -07005501static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502{
5503 struct xdr_stream xdr;
5504 struct compound_hdr hdr;
5505 int status;
5506
5507 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5508 status = decode_compound_hdr(&xdr, &hdr);
5509 if (status)
5510 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005511 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5512 if (status)
5513 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 status = decode_putfh(&xdr);
5515 if (status)
5516 goto out;
5517 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005518 if (status)
5519 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005520 decode_getfattr(&xdr, res->fattr, res->server,
5521 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 if (!status)
5523 status = res->count;
5524out:
5525 return status;
5526}
5527
5528/*
5529 * Decode COMMIT response
5530 */
Al Viro8687b632006-10-19 23:28:48 -07005531static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532{
5533 struct xdr_stream xdr;
5534 struct compound_hdr hdr;
5535 int status;
5536
5537 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5538 status = decode_compound_hdr(&xdr, &hdr);
5539 if (status)
5540 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005541 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5542 if (status)
5543 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544 status = decode_putfh(&xdr);
5545 if (status)
5546 goto out;
5547 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005548 if (status)
5549 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005550 decode_getfattr(&xdr, res->fattr, res->server,
5551 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552out:
5553 return status;
5554}
5555
5556/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005557 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005559static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5560 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561{
5562 struct xdr_stream xdr;
5563 struct compound_hdr hdr;
5564 int status;
5565
5566 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5567 status = decode_compound_hdr(&xdr, &hdr);
5568 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005569 status = decode_sequence(&xdr, &res->seq_res, req);
5570 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571 status = decode_putfh(&xdr);
5572 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005573 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574 return status;
5575}
5576
5577/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005578 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005580static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5581 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582{
5583 struct xdr_stream xdr;
5584 struct compound_hdr hdr;
5585 int status;
5586
5587 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5588 status = decode_compound_hdr(&xdr, &hdr);
5589 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005590 status = decode_sequence(&xdr, &res->seq_res, req);
5591 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005592 status = decode_putfh(&xdr);
5593 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005594 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005595 return status;
5596}
5597
5598/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005599 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005601static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5602 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005603{
5604 struct xdr_stream xdr;
5605 struct compound_hdr hdr;
5606 int status;
5607
5608 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5609 status = decode_compound_hdr(&xdr, &hdr);
5610 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005611 status = decode_sequence(&xdr, &res->seq_res, req);
5612 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005613 status = decode_putfh(&xdr);
5614 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005615 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 return status;
5617}
5618
5619/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005620 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005621 */
Al Viro8687b632006-10-19 23:28:48 -07005622static 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 -07005623{
5624 struct xdr_stream xdr;
5625 struct compound_hdr hdr;
5626 int status;
5627
5628 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005629 status = decode_compound_hdr(&xdr, &hdr);
5630 if (status)
5631 goto out;
5632 status = decode_sequence(&xdr, &res->seq_res, req);
5633 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634 goto out;
5635 if ((status = decode_putfh(&xdr)) != 0)
5636 goto out;
5637 status = decode_server_caps(&xdr, res);
5638out:
5639 return status;
5640}
5641
5642/*
5643 * Decode RENEW response
5644 */
Al Viro8687b632006-10-19 23:28:48 -07005645static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646{
5647 struct xdr_stream xdr;
5648 struct compound_hdr hdr;
5649 int status;
5650
5651 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5652 status = decode_compound_hdr(&xdr, &hdr);
5653 if (!status)
5654 status = decode_renew(&xdr);
5655 return status;
5656}
5657
5658/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005659 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660 */
Al Viro8687b632006-10-19 23:28:48 -07005661static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005662 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663{
5664 struct xdr_stream xdr;
5665 struct compound_hdr hdr;
5666 int status;
5667
5668 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5669 status = decode_compound_hdr(&xdr, &hdr);
5670 if (!status)
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005671 status = decode_setclientid(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672 return status;
5673}
5674
5675/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005676 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677 */
Al Viro8687b632006-10-19 23:28:48 -07005678static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679{
5680 struct xdr_stream xdr;
5681 struct compound_hdr hdr;
5682 int status;
5683
5684 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5685 status = decode_compound_hdr(&xdr, &hdr);
5686 if (!status)
5687 status = decode_setclientid_confirm(&xdr);
5688 if (!status)
5689 status = decode_putrootfh(&xdr);
5690 if (!status)
5691 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 return status;
5693}
5694
5695/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005696 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697 */
Al Viro8687b632006-10-19 23:28:48 -07005698static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699{
5700 struct xdr_stream xdr;
5701 struct compound_hdr hdr;
5702 int status;
5703
5704 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5705 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005706 if (status)
5707 goto out;
5708 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5709 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005710 goto out;
5711 status = decode_putfh(&xdr);
5712 if (status != 0)
5713 goto out;
5714 status = decode_delegreturn(&xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005715 if (status != 0)
5716 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005717 decode_getfattr(&xdr, res->fattr, res->server,
5718 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005719out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720 return status;
5721}
5722
Trond Myklebust683b57b2006-06-09 09:34:22 -04005723/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005724 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005725 */
Benny Halevy22958462009-04-01 09:22:02 -04005726static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5727 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005728{
5729 struct xdr_stream xdr;
5730 struct compound_hdr hdr;
5731 int status;
5732
5733 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5734 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005735 if (status)
5736 goto out;
5737 status = decode_sequence(&xdr, &res->seq_res, req);
5738 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005739 goto out;
5740 if ((status = decode_putfh(&xdr)) != 0)
5741 goto out;
5742 if ((status = decode_lookup(&xdr)) != 0)
5743 goto out;
5744 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005745 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005746 res->fs_locations->server,
5747 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005748out:
5749 return status;
5750}
5751
Benny Halevy99fe60d2009-04-01 09:22:29 -04005752#if defined(CONFIG_NFS_V4_1)
5753/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005754 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005755 */
5756static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5757 void *res)
5758{
5759 struct xdr_stream xdr;
5760 struct compound_hdr hdr;
5761 int status;
5762
5763 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5764 status = decode_compound_hdr(&xdr, &hdr);
5765 if (!status)
5766 status = decode_exchange_id(&xdr, res);
5767 return status;
5768}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005769
5770/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005771 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005772 */
5773static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5774 struct nfs41_create_session_res *res)
5775{
5776 struct xdr_stream xdr;
5777 struct compound_hdr hdr;
5778 int status;
5779
5780 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5781 status = decode_compound_hdr(&xdr, &hdr);
5782 if (!status)
5783 status = decode_create_session(&xdr, res);
5784 return status;
5785}
5786
5787/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005788 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005789 */
5790static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5791 void *dummy)
5792{
5793 struct xdr_stream xdr;
5794 struct compound_hdr hdr;
5795 int status;
5796
5797 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5798 status = decode_compound_hdr(&xdr, &hdr);
5799 if (!status)
5800 status = decode_destroy_session(&xdr, dummy);
5801 return status;
5802}
5803
5804/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005805 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005806 */
5807static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5808 struct nfs4_sequence_res *res)
5809{
5810 struct xdr_stream xdr;
5811 struct compound_hdr hdr;
5812 int status;
5813
5814 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5815 status = decode_compound_hdr(&xdr, &hdr);
5816 if (!status)
5817 status = decode_sequence(&xdr, res, rqstp);
5818 return status;
5819}
5820
5821/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005822 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005823 */
5824static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5825 struct nfs4_get_lease_time_res *res)
5826{
5827 struct xdr_stream xdr;
5828 struct compound_hdr hdr;
5829 int status;
5830
5831 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5832 status = decode_compound_hdr(&xdr, &hdr);
5833 if (!status)
5834 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5835 if (!status)
5836 status = decode_putrootfh(&xdr);
5837 if (!status)
5838 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5839 return status;
5840}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005841
5842/*
5843 * Decode RECLAIM_COMPLETE response
5844 */
5845static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p,
5846 struct nfs41_reclaim_complete_res *res)
5847{
5848 struct xdr_stream xdr;
5849 struct compound_hdr hdr;
5850 int status;
5851
5852 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5853 status = decode_compound_hdr(&xdr, &hdr);
5854 if (!status)
5855 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5856 if (!status)
5857 status = decode_reclaim_complete(&xdr, (void *)NULL);
5858 return status;
5859}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005860#endif /* CONFIG_NFS_V4_1 */
5861
Bryan Schumaker82f2e542010-10-21 16:33:18 -04005862__be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
5863 struct nfs_server *server, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864{
5865 uint32_t bitmap[2] = {0};
5866 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005867 __be32 *p = xdr_inline_decode(xdr, 4);
5868 if (unlikely(!p))
5869 goto out_overflow;
5870 if (!ntohl(*p++)) {
5871 p = xdr_inline_decode(xdr, 4);
5872 if (unlikely(!p))
5873 goto out_overflow;
5874 if (!ntohl(*p++))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 return ERR_PTR(-EAGAIN);
5876 entry->eof = 1;
5877 return ERR_PTR(-EBADCOOKIE);
5878 }
5879
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005880 p = xdr_inline_decode(xdr, 12);
5881 if (unlikely(!p))
5882 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 entry->prev_cookie = entry->cookie;
5884 p = xdr_decode_hyper(p, &entry->cookie);
5885 entry->len = ntohl(*p++);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005886
Trond Myklebust9af8c222010-10-24 11:52:55 -04005887 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005888 if (unlikely(!p))
5889 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891
5892 /*
5893 * In case the server doesn't return an inode number,
5894 * we fake one here. (We don't use inode number 0,
5895 * since glibc seems to choke on it...)
5896 */
5897 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04005898 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899
Trond Myklebust9af8c222010-10-24 11:52:55 -04005900 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005901 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04005902
5903 if (decode_attr_length(xdr, &len, &p) < 0)
5904 goto out_overflow;
5905
5906 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, server, 1) < 0)
5907 goto out_overflow;
5908 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
5909 entry->ino = entry->fattr->fileid;
5910
5911 if (verify_attr_len(xdr, p, len) < 0)
5912 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005914 p = xdr_inline_peek(xdr, 8);
5915 if (p != NULL)
5916 entry->eof = !p[0] && p[1];
5917 else
5918 entry->eof = 0;
5919
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920 return p;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005921
5922out_overflow:
5923 print_overflow_msg(__func__, xdr);
5924 return ERR_PTR(-EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925}
5926
5927/*
5928 * We need to translate between nfs status return values and
5929 * the local errno values which may not be the same.
5930 */
5931static struct {
5932 int stat;
5933 int errno;
5934} nfs_errtbl[] = {
5935 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005936 { NFS4ERR_PERM, -EPERM },
5937 { NFS4ERR_NOENT, -ENOENT },
5938 { NFS4ERR_IO, -errno_NFSERR_IO},
5939 { NFS4ERR_NXIO, -ENXIO },
5940 { NFS4ERR_ACCESS, -EACCES },
5941 { NFS4ERR_EXIST, -EEXIST },
5942 { NFS4ERR_XDEV, -EXDEV },
5943 { NFS4ERR_NOTDIR, -ENOTDIR },
5944 { NFS4ERR_ISDIR, -EISDIR },
5945 { NFS4ERR_INVAL, -EINVAL },
5946 { NFS4ERR_FBIG, -EFBIG },
5947 { NFS4ERR_NOSPC, -ENOSPC },
5948 { NFS4ERR_ROFS, -EROFS },
5949 { NFS4ERR_MLINK, -EMLINK },
5950 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5951 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5952 { NFS4ERR_DQUOT, -EDQUOT },
5953 { NFS4ERR_STALE, -ESTALE },
5954 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5955 { NFS4ERR_BADOWNER, -EINVAL },
5956 { NFS4ERR_BADNAME, -EINVAL },
5957 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5958 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5959 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005960 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03005961 { NFS4ERR_BADTYPE, -EBADTYPE },
5962 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005963 { NFS4ERR_SYMLINK, -ELOOP },
5964 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5965 { NFS4ERR_DEADLOCK, -EDEADLK },
5966 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967 * to be handled by a
5968 * middle-layer.
5969 */
Benny Halevy856dff32008-03-31 17:39:06 +03005970 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971};
5972
5973/*
5974 * Convert an NFS error code to a local one.
5975 * This one is used jointly by NFSv2 and NFSv3.
5976 */
5977static int
David Howells0a8ea432006-08-22 20:06:08 -04005978nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979{
5980 int i;
5981 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5982 if (nfs_errtbl[i].stat == stat)
5983 return nfs_errtbl[i].errno;
5984 }
5985 if (stat <= 10000 || stat > 10100) {
5986 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005987 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988 }
5989 /* If we cannot translate the error, the recovery routines should
5990 * handle it.
5991 * Note: remaining NFSv4 error codes have values > 10000, so should
5992 * not conflict with native Linux error codes.
5993 */
Benny Halevy856dff32008-03-31 17:39:06 +03005994 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995}
5996
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997#define PROC(proc, argtype, restype) \
5998[NFSPROC4_CLNT_##proc] = { \
5999 .p_proc = NFSPROC4_COMPOUND, \
6000 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
6001 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006002 .p_arglen = NFS4_##argtype##_sz, \
6003 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006004 .p_statidx = NFSPROC4_CLNT_##proc, \
6005 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006006}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007
6008struct rpc_procinfo nfs4_procedures[] = {
6009 PROC(READ, enc_read, dec_read),
6010 PROC(WRITE, enc_write, dec_write),
6011 PROC(COMMIT, enc_commit, dec_commit),
6012 PROC(OPEN, enc_open, dec_open),
6013 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6014 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6015 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6016 PROC(CLOSE, enc_close, dec_close),
6017 PROC(SETATTR, enc_setattr, dec_setattr),
6018 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6019 PROC(RENEW, enc_renew, dec_renew),
6020 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6021 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6022 PROC(LOCK, enc_lock, dec_lock),
6023 PROC(LOCKT, enc_lockt, dec_lockt),
6024 PROC(LOCKU, enc_locku, dec_locku),
6025 PROC(ACCESS, enc_access, dec_access),
6026 PROC(GETATTR, enc_getattr, dec_getattr),
6027 PROC(LOOKUP, enc_lookup, dec_lookup),
6028 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6029 PROC(REMOVE, enc_remove, dec_remove),
6030 PROC(RENAME, enc_rename, dec_rename),
6031 PROC(LINK, enc_link, dec_link),
6032 PROC(SYMLINK, enc_symlink, dec_symlink),
6033 PROC(CREATE, enc_create, dec_create),
6034 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6035 PROC(STATFS, enc_statfs, dec_statfs),
6036 PROC(READLINK, enc_readlink, dec_readlink),
6037 PROC(READDIR, enc_readdir, dec_readdir),
6038 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6039 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00006040 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006041 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04006042 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006043 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006044#if defined(CONFIG_NFS_V4_1)
6045 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04006046 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006047 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006048 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04006049 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Ricardo Labiaga180197532009-12-05 16:08:40 -05006050 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006051#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052};
6053
6054struct rpc_version nfs_version4 = {
6055 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006056 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057 .procs = nfs4_procedures
6058};
6059
6060/*
6061 * Local variables:
6062 * c-basic-offset: 8
6063 * End:
6064 */