blob: 49df05afdc646583e568ad6162ba388c62242d4e [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)
223#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
224#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
226 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400227 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000228 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
230#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400231 1 + 2 + nfs4_name_maxsz + \
232 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400233#define decode_create_maxsz (op_decode_hdr_maxsz + \
234 decode_change_info_maxsz + \
235 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_statfs_maxsz (encode_getattr_maxsz)
237#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
239#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400240#define encode_getacl_maxsz (encode_getattr_maxsz)
241#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
242 nfs4_fattr_bitmap_maxsz + 1)
243#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
244 encode_stateid_maxsz + 3)
245#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400246#define encode_fs_locations_maxsz \
247 (encode_getattr_maxsz)
248#define decode_fs_locations_maxsz \
249 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400250
251#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400252#define NFS4_MAX_MACHINE_NAME_LEN (64)
253
Benny Halevy99fe60d2009-04-01 09:22:29 -0400254#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
255 encode_verifier_maxsz + \
256 1 /* co_ownerid.len */ + \
257 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
258 1 /* flags */ + \
259 1 /* spa_how */ + \
260 0 /* SP4_NONE (for now) */ + \
261 1 /* zero implemetation id array */)
262#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
263 2 /* eir_clientid */ + \
264 1 /* eir_sequenceid */ + \
265 1 /* eir_flags */ + \
266 1 /* spr_how */ + \
267 0 /* SP4_NONE (for now) */ + \
268 2 /* eir_server_owner.so_minor_id */ + \
269 /* eir_server_owner.so_major_id<> */ \
270 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
271 /* eir_server_scope<> */ \
272 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
273 1 /* eir_server_impl_id array length */ + \
274 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400275#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
276#define decode_channel_attrs_maxsz (6 + \
277 1 /* ca_rdma_ird.len */ + \
278 1 /* ca_rdma_ird */)
279#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
280 2 /* csa_clientid */ + \
281 1 /* csa_sequence */ + \
282 1 /* csa_flags */ + \
283 encode_channel_attrs_maxsz + \
284 encode_channel_attrs_maxsz + \
285 1 /* csa_cb_program */ + \
286 1 /* csa_sec_parms.len (1) */ + \
287 1 /* cb_secflavor (AUTH_SYS) */ + \
288 1 /* stamp */ + \
289 1 /* machinename.len */ + \
290 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
291 1 /* uid */ + \
292 1 /* gid */ + \
293 1 /* gids.len (0) */)
294#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
295 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
296 1 /* csr_sequence */ + \
297 1 /* csr_flags */ + \
298 decode_channel_attrs_maxsz + \
299 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400300#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
301#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400302#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
303 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
304#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
305 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500306#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
307#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400308#else /* CONFIG_NFS_V4_1 */
309#define encode_sequence_maxsz 0
310#define decode_sequence_maxsz 0
311#endif /* CONFIG_NFS_V4_1 */
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
314#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
315#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400316 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400318 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400320 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400322 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400324 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400326 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400328 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400330 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400332 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400334 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400336 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400338 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400340 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400342 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400343 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400345 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400348 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400353 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400358 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400360 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400361 encode_putfh_maxsz + \
362 encode_savefh_maxsz + \
363 encode_open_maxsz + \
364 encode_getfh_maxsz + \
365 encode_getattr_maxsz + \
366 encode_restorefh_maxsz + \
367 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400369 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400370 decode_putfh_maxsz + \
371 decode_savefh_maxsz + \
372 decode_open_maxsz + \
373 decode_getfh_maxsz + \
374 decode_getattr_maxsz + \
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400377#define NFS4_enc_open_confirm_sz \
378 (compound_encode_hdr_maxsz + \
379 encode_putfh_maxsz + \
380 encode_open_confirm_maxsz)
381#define NFS4_dec_open_confirm_sz \
382 (compound_decode_hdr_maxsz + \
383 decode_putfh_maxsz + \
384 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400386 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400388 encode_open_maxsz + \
389 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400393 decode_open_maxsz + \
394 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_open_downgrade_sz \
396 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400397 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_putfh_maxsz + \
399 encode_open_downgrade_maxsz + \
400 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#define NFS4_dec_open_downgrade_sz \
402 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400404 decode_putfh_maxsz + \
405 decode_open_downgrade_maxsz + \
406 decode_getattr_maxsz)
407#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 encode_putfh_maxsz + \
410 encode_close_maxsz + \
411 encode_getattr_maxsz)
412#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 decode_putfh_maxsz + \
415 decode_close_maxsz + \
416 decode_getattr_maxsz)
417#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 encode_putfh_maxsz + \
420 encode_setattr_maxsz + \
421 encode_getattr_maxsz)
422#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 decode_putfh_maxsz + \
425 decode_setattr_maxsz + \
426 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 encode_putfh_maxsz + \
430 encode_fsinfo_maxsz)
431#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 decode_putfh_maxsz + \
434 decode_fsinfo_maxsz)
435#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
436 encode_renew_maxsz)
437#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
438 decode_renew_maxsz)
439#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
440 encode_setclientid_maxsz)
441#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
442 decode_setclientid_maxsz)
443#define NFS4_enc_setclientid_confirm_sz \
444 (compound_encode_hdr_maxsz + \
445 encode_setclientid_confirm_maxsz + \
446 encode_putrootfh_maxsz + \
447 encode_fsinfo_maxsz)
448#define NFS4_dec_setclientid_confirm_sz \
449 (compound_decode_hdr_maxsz + \
450 decode_setclientid_confirm_maxsz + \
451 decode_putrootfh_maxsz + \
452 decode_fsinfo_maxsz)
453#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 encode_lockt_maxsz)
465#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400467 decode_putfh_maxsz + \
468 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400472 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400480 encode_access_maxsz + \
481 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400483 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400485 decode_access_maxsz + \
486 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400488 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 encode_putfh_maxsz + \
490 encode_getattr_maxsz)
491#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
494 decode_getattr_maxsz)
495#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 encode_putfh_maxsz + \
498 encode_lookup_maxsz + \
499 encode_getattr_maxsz + \
500 encode_getfh_maxsz)
501#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400502 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400504 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_getattr_maxsz + \
506 decode_getfh_maxsz)
507#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 encode_putrootfh_maxsz + \
510 encode_getattr_maxsz + \
511 encode_getfh_maxsz)
512#define NFS4_dec_lookup_root_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_putrootfh_maxsz + \
515 decode_getattr_maxsz + \
516 decode_getfh_maxsz)
517#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400520 encode_remove_maxsz + \
521 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400525 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400526 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
530 encode_savefh_maxsz + \
531 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400532 encode_rename_maxsz + \
533 encode_getattr_maxsz + \
534 encode_restorefh_maxsz + \
535 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400537 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 decode_putfh_maxsz + \
539 decode_savefh_maxsz + \
540 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400541 decode_rename_maxsz + \
542 decode_getattr_maxsz + \
543 decode_restorefh_maxsz + \
544 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 encode_putfh_maxsz + \
548 encode_savefh_maxsz + \
549 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400550 encode_link_maxsz + \
551 decode_getattr_maxsz + \
552 encode_restorefh_maxsz + \
553 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 decode_putfh_maxsz + \
557 decode_savefh_maxsz + \
558 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400559 decode_link_maxsz + \
560 decode_getattr_maxsz + \
561 decode_restorefh_maxsz + \
562 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 encode_putfh_maxsz + \
566 encode_symlink_maxsz + \
567 encode_getattr_maxsz + \
568 encode_getfh_maxsz)
569#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_symlink_maxsz + \
573 decode_getattr_maxsz + \
574 decode_getfh_maxsz)
575#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400578 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400580 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400582 encode_restorefh_maxsz + \
583 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400587 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400589 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400591 decode_restorefh_maxsz + \
592 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 encode_putfh_maxsz + \
596 encode_getattr_maxsz)
597#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_putfh_maxsz + \
600 decode_getattr_maxsz)
601#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400604 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400608 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800611 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 encode_getattr_maxsz)
613#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800615 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_getattr_maxsz)
617#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100620 encode_delegreturn_maxsz + \
621 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100624 decode_delegreturn_maxsz + \
625 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000626#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000628 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400629 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000630#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000632 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400633 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000634#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000636 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400637 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000638#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000640 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400641 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400642#define NFS4_enc_fs_locations_sz \
643 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400645 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400646 encode_lookup_maxsz + \
647 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400648#define NFS4_dec_fs_locations_sz \
649 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400651 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400652 decode_lookup_maxsz + \
653 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400654#if defined(CONFIG_NFS_V4_1)
655#define NFS4_enc_exchange_id_sz \
656 (compound_encode_hdr_maxsz + \
657 encode_exchange_id_maxsz)
658#define NFS4_dec_exchange_id_sz \
659 (compound_decode_hdr_maxsz + \
660 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400661#define NFS4_enc_create_session_sz \
662 (compound_encode_hdr_maxsz + \
663 encode_create_session_maxsz)
664#define NFS4_dec_create_session_sz \
665 (compound_decode_hdr_maxsz + \
666 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400667#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
668 encode_destroy_session_maxsz)
669#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
670 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400671#define NFS4_enc_sequence_sz \
672 (compound_decode_hdr_maxsz + \
673 encode_sequence_maxsz)
674#define NFS4_dec_sequence_sz \
675 (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400677#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
678 encode_sequence_maxsz + \
679 encode_putrootfh_maxsz + \
680 encode_fsinfo_maxsz)
681#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
682 decode_sequence_maxsz + \
683 decode_putrootfh_maxsz + \
684 decode_fsinfo_maxsz)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500685#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
686 encode_sequence_maxsz + \
687 encode_reclaim_complete_maxsz)
688#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
689 decode_sequence_maxsz + \
690 decode_reclaim_complete_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500691
692const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
693 compound_encode_hdr_maxsz +
694 encode_sequence_maxsz +
695 encode_putfh_maxsz +
696 encode_getattr_maxsz) *
697 XDR_UNIT);
698
699const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
700 compound_decode_hdr_maxsz +
701 decode_sequence_maxsz +
702 decode_putfh_maxsz) *
703 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400704#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Trond Myklebustbca79472009-03-11 14:10:26 -0400706static const umode_t nfs_type2fmt[] = {
707 [NF4BAD] = 0,
708 [NF4REG] = S_IFREG,
709 [NF4DIR] = S_IFDIR,
710 [NF4BLK] = S_IFBLK,
711 [NF4CHR] = S_IFCHR,
712 [NF4LNK] = S_IFLNK,
713 [NF4SOCK] = S_IFSOCK,
714 [NF4FIFO] = S_IFIFO,
715 [NF4ATTRDIR] = 0,
716 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717};
718
719struct compound_hdr {
720 int32_t status;
721 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500722 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 uint32_t taglen;
724 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400725 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400726 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727};
728
Benny Halevy13c65ce2009-08-14 17:19:25 +0300729static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
730{
731 __be32 *p = xdr_reserve_space(xdr, nbytes);
732 BUG_ON(!p);
733 return p;
734}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
737{
Al Viro8687b632006-10-19 23:28:48 -0700738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 p = xdr_reserve_space(xdr, 4 + len);
741 BUG_ON(p == NULL);
742 xdr_encode_opaque(p, str, len);
743}
744
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400745static void encode_compound_hdr(struct xdr_stream *xdr,
746 struct rpc_rqst *req,
747 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
Al Viro8687b632006-10-19 23:28:48 -0700749 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400750 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
751
752 /* initialize running count of expected bytes in reply.
753 * NOTE: the replied tag SHOULD be the same is the one sent,
754 * but this is not required as a MUST for the server to do so. */
755 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
758 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300759 p = reserve_space(xdr, 4 + hdr->taglen + 8);
760 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300761 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500762 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300763 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500764}
765
766static void encode_nops(struct compound_hdr *hdr)
767{
Andy Adamsonfc931582009-04-01 09:22:31 -0400768 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500769 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
772static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
773{
Al Viro8687b632006-10-19 23:28:48 -0700774 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
777 BUG_ON(p == NULL);
778 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
779}
780
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500781static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
783 char owner_name[IDMAP_NAMESZ];
784 char owner_group[IDMAP_NAMESZ];
785 int owner_namelen = 0;
786 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700787 __be32 *p;
788 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 int len;
790 uint32_t bmval0 = 0;
791 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 /*
794 * We reserve enough space to write the entire attribute buffer at once.
795 * In the worst-case, this would be
796 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
797 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000798 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 */
800 len = 16;
801
802 /* Sigh */
803 if (iap->ia_valid & ATTR_SIZE)
804 len += 8;
805 if (iap->ia_valid & ATTR_MODE)
806 len += 4;
807 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400808 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400810 dprintk("nfs: couldn't resolve uid %d to string\n",
811 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 /* XXX */
813 strcpy(owner_name, "nobody");
814 owner_namelen = sizeof("nobody") - 1;
815 /* goto out; */
816 }
817 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
818 }
819 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400820 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400822 dprintk("nfs: couldn't resolve gid %d to string\n",
823 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 strcpy(owner_group, "nobody");
825 owner_grouplen = sizeof("nobody") - 1;
826 /* goto out; */
827 }
828 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
829 }
830 if (iap->ia_valid & ATTR_ATIME_SET)
831 len += 16;
832 else if (iap->ia_valid & ATTR_ATIME)
833 len += 4;
834 if (iap->ia_valid & ATTR_MTIME_SET)
835 len += 16;
836 else if (iap->ia_valid & ATTR_MTIME)
837 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300838 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 /*
841 * We write the bitmap length now, but leave the bitmap and the attribute
842 * buffer length to be backfilled at the end of this routine.
843 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300844 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 q = p;
846 p += 3;
847
848 if (iap->ia_valid & ATTR_SIZE) {
849 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300850 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852 if (iap->ia_valid & ATTR_MODE) {
853 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300854 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
856 if (iap->ia_valid & ATTR_UID) {
857 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300858 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860 if (iap->ia_valid & ATTR_GID) {
861 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300862 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 }
864 if (iap->ia_valid & ATTR_ATIME_SET) {
865 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300866 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
867 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400868 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
869 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871 else if (iap->ia_valid & ATTR_ATIME) {
872 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300873 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875 if (iap->ia_valid & ATTR_MTIME_SET) {
876 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300877 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
878 *p++ = cpu_to_be32(0);
879 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
880 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882 else if (iap->ia_valid & ATTR_MTIME) {
883 bmval1 |= FATTR4_WORD1_TIME_MODIFY_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 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 /*
888 * Now we backfill the bitmap and the attribute buffer length.
889 */
890 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400891 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 len, ((char *)p - (char *)q) + 4);
893 BUG();
894 }
895 len = (char *)p - (char *)q - 12;
896 *q++ = htonl(bmval0);
897 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300898 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500903static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
Al Viro8687b632006-10-19 23:28:48 -0700905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Benny Halevy13c65ce2009-08-14 17:19:25 +0300907 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300908 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300909 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500910 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400911 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500914static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, 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+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(OP_CLOSE);
920 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300921 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500922 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400923 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500926static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Al Viro8687b632006-10-19 23:28:48 -0700928 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500929
Benny Halevy13c65ce2009-08-14 17:19:25 +0300930 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300931 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300932 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300933 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500934 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400935 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500938static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
Al Viro8687b632006-10-19 23:28:48 -0700940 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500941
Benny Halevy13c65ce2009-08-14 17:19:25 +0300942 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300943 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300944 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 switch (create->ftype) {
947 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300948 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300949 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400950 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 break;
952
953 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300954 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300955 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300956 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 break;
958
959 default:
960 break;
961 }
962
Benny Halevy811652b2009-08-14 17:19:34 +0300963 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500964 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400965 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500967 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500970static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
Andy Adamson05d564f2008-12-23 16:06:15 -0500972 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Benny Halevy13c65ce2009-08-14 17:19:25 +0300974 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300975 *p++ = cpu_to_be32(OP_GETATTR);
976 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300977 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500978 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400979 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980}
981
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500982static 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 -0700983{
Andy Adamson05d564f2008-12-23 16:06:15 -0500984 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Benny Halevy13c65ce2009-08-14 17:19:25 +0300986 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300987 *p++ = cpu_to_be32(OP_GETATTR);
988 *p++ = cpu_to_be32(2);
989 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +0300990 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500991 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400992 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500995static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500997 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
998 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
1000
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001001static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001003 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1004 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001007static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001008{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001009 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1010 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001011}
1012
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001013static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Al Viro8687b632006-10-19 23:28:48 -07001015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Benny Halevy13c65ce2009-08-14 17:19:25 +03001017 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001018 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001019 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001020 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021}
1022
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001023static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024{
Al Viro8687b632006-10-19 23:28:48 -07001025 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Benny Halevy13c65ce2009-08-14 17:19:25 +03001027 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001028 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001029 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001031 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001034static inline int nfs4_lock_type(struct file_lock *fl, int block)
1035{
1036 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1037 return block ? NFS4_READW_LT : NFS4_READ_LT;
1038 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1039}
1040
1041static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1042{
1043 if (fl->fl_end == OFFSET_MAX)
1044 return ~(uint64_t)0;
1045 return fl->fl_end - fl->fl_start + 1;
1046}
1047
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001048static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1049{
1050 __be32 *p;
1051
1052 p = reserve_space(xdr, 28);
1053 p = xdr_encode_hyper(p, lowner->clientid);
1054 *p++ = cpu_to_be32(16);
1055 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1056 xdr_encode_hyper(p, lowner->id);
1057}
1058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059/*
1060 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1061 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1062 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001063static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Al Viro8687b632006-10-19 23:28:48 -07001065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Benny Halevy13c65ce2009-08-14 17:19:25 +03001067 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001068 *p++ = cpu_to_be32(OP_LOCK);
1069 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1070 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001071 p = xdr_encode_hyper(p, args->fl->fl_start);
1072 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001073 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001074 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001075 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001076 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001077 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001079 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 }
1081 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001082 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001083 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001084 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001087 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Al Viro8687b632006-10-19 23:28:48 -07001092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001094 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001095 *p++ = cpu_to_be32(OP_LOCKT);
1096 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001097 p = xdr_encode_hyper(p, args->fl->fl_start);
1098 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001099 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001100 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001101 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001104static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
Al Viro8687b632006-10-19 23:28:48 -07001106 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Benny Halevy13c65ce2009-08-14 17:19:25 +03001108 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001109 *p++ = cpu_to_be32(OP_LOCKU);
1110 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1111 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001112 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001113 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001114 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001115 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001116 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
1121 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Benny Halevy13c65ce2009-08-14 17:19:25 +03001124 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001125 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001126 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001127 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001128 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001131static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Al Viro8687b632006-10-19 23:28:48 -07001133 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Benny Halevy13c65ce2009-08-14 17:19:25 +03001135 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001136 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001137 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001138 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001139 break;
1140 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001141 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001142 break;
1143 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001144 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001145 break;
1146 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001147 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
Benny Halevy34558512009-08-14 17:19:30 +03001149 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
1152static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1153{
Al Viro8687b632006-10-19 23:28:48 -07001154 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 /*
1156 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1157 * owner 4 = 32
1158 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001159 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001161 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001162 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001163 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001164 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001165 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001166 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001167 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
1170static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1171{
Al Viro8687b632006-10-19 23:28:48 -07001172 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001173 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Benny Halevy13c65ce2009-08-14 17:19:25 +03001175 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001177 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001178 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001179 encode_attrs(xdr, arg->u.attrs, arg->server);
1180 break;
1181 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001182 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001183 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001184 if (nfs4_has_persistent_session(clp)) {
1185 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1186 encode_attrs(xdr, arg->u.attrs, arg->server);
1187 } else {
1188 struct iattr dummy;
1189
1190 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1191 encode_nfs4_verifier(xdr, &arg->u.verifier);
1192 dummy.ia_valid = 0;
1193 encode_attrs(xdr, &dummy, arg->server);
1194 }
1195 } else {
1196 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1197 encode_nfs4_verifier(xdr, &arg->u.verifier);
1198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200}
1201
1202static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1203{
Al Viro8687b632006-10-19 23:28:48 -07001204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Benny Halevy13c65ce2009-08-14 17:19:25 +03001206 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001208 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001209 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001210 break;
1211 default:
1212 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001213 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001214 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 }
1216}
1217
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001218static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Al Viro8687b632006-10-19 23:28:48 -07001220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Benny Halevy13c65ce2009-08-14 17:19:25 +03001222 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001224 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001225 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001226 break;
1227 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001228 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001229 break;
1230 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001231 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001232 break;
1233 default:
1234 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 }
1236}
1237
1238static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1239{
Al Viro8687b632006-10-19 23:28:48 -07001240 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Benny Halevy13c65ce2009-08-14 17:19:25 +03001242 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001243 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 encode_string(xdr, name->len, name->name);
1245}
1246
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001247static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248{
Al Viro8687b632006-10-19 23:28:48 -07001249 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Benny Halevy13c65ce2009-08-14 17:19:25 +03001251 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001252 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 encode_delegation_type(xdr, type);
1254}
1255
1256static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1257{
Al Viro8687b632006-10-19 23:28:48 -07001258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Benny Halevy13c65ce2009-08-14 17:19:25 +03001260 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001261 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001262 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 encode_string(xdr, name->len, name->name);
1264}
1265
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001266static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
1268 encode_openhdr(xdr, arg);
1269 encode_opentype(xdr, arg);
1270 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001271 case NFS4_OPEN_CLAIM_NULL:
1272 encode_claim_null(xdr, arg->name);
1273 break;
1274 case NFS4_OPEN_CLAIM_PREVIOUS:
1275 encode_claim_previous(xdr, arg->u.delegation_type);
1276 break;
1277 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1278 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1279 break;
1280 default:
1281 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 }
Andy Adamsond0179312008-12-23 16:06:17 -05001283 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001284 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285}
1286
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001287static 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 -07001288{
Al Viro8687b632006-10-19 23:28:48 -07001289 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Benny Halevy13c65ce2009-08-14 17:19:25 +03001291 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001292 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001293 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001294 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001295 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001296 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297}
1298
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001299static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Al Viro8687b632006-10-19 23:28:48 -07001301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Benny Halevy13c65ce2009-08-14 17:19:25 +03001303 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001305 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001306 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001307 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001308 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001309 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001312static void
Andy Adamsond0179312008-12-23 16:06:17 -05001313encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
1315 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Benny Halevy13c65ce2009-08-14 17:19:25 +03001318 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001319 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001320 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001321 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001322 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001325static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Andy Adamson05d564f2008-12-23 16:06:15 -05001327 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001328
Benny Halevy13c65ce2009-08-14 17:19:25 +03001329 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001330 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001331 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001332 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333}
1334
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001335static 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 -07001336{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 nfs4_stateid stateid;
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, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (ctx->state != NULL) {
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001342 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner);
Benny Halevy34558512009-08-14 17:19:30 +03001343 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 } else
Benny Halevy34558512009-08-14 17:19:30 +03001345 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001348static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Benny Halevy13c65ce2009-08-14 17:19:25 +03001352 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001353 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001355 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Benny Halevy13c65ce2009-08-14 17:19:25 +03001357 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001358 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001359 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001360 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001361 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001364static 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 -07001365{
Manoj Naik97d312d2005-06-22 17:16:39 +00001366 uint32_t attrs[2] = {
1367 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1368 FATTR4_WORD1_MOUNTED_ON_FILEID,
1369 };
Al Viro8687b632006-10-19 23:28:48 -07001370 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001373 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001374 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001375 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001376 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1377 *p++ = cpu_to_be32(readdir->count);
1378 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001379 /* Switch to mounted_on_fileid if the server supports it */
1380 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1381 attrs[0] &= ~FATTR4_WORD0_FILEID;
1382 else
1383 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001384 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001385 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001386 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001387 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001388 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1389 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001390 (unsigned long long)readdir->cookie,
1391 ((u32 *)readdir->verifier.data)[0],
1392 ((u32 *)readdir->verifier.data)[1],
1393 attrs[0] & readdir->bitmask[0],
1394 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395}
1396
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001397static 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 -07001398{
Al Viro8687b632006-10-19 23:28:48 -07001399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Benny Halevy13c65ce2009-08-14 17:19:25 +03001401 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001402 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001403 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001404 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405}
1406
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001407static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001412 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001413 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001414 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001415 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001418static 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 -07001419{
Al Viro8687b632006-10-19 23:28:48 -07001420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Benny Halevy811652b2009-08-14 17:19:34 +03001422 p = reserve_space(xdr, 4);
1423 *p = cpu_to_be32(OP_RENAME);
1424 encode_string(xdr, oldname->len, oldname->name);
1425 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001426 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001427 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001430static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, 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, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001435 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001436 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001437 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001438 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001441static void
Andy Adamsond0179312008-12-23 16:06:17 -05001442encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001443{
Al Viro8687b632006-10-19 23:28:48 -07001444 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001445
Benny Halevy13c65ce2009-08-14 17:19:25 +03001446 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001447 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001448 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001449 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001450}
1451
1452static int
Andy Adamsond0179312008-12-23 16:06:17 -05001453encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001454{
Al Viro8687b632006-10-19 23:28:48 -07001455 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001456
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001458 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001459 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001461 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001462 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001463 if (arg->acl_len % 4)
1464 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001467 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001468 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001469 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001470 return 0;
1471}
1472
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001473static void
Andy Adamsond0179312008-12-23 16:06:17 -05001474encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Al Viro8687b632006-10-19 23:28:48 -07001476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Benny Halevy13c65ce2009-08-14 17:19:25 +03001478 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001479 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001480 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001481 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static 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 -07001485{
Al Viro8687b632006-10-19 23:28:48 -07001486 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001487
Benny Halevy13c65ce2009-08-14 17:19:25 +03001488 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001489 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001490 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001491 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001492 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001493 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001502 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
1504 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001505 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001506 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1508 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001509 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001510 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001511 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001512 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001515static 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 -07001516{
Andy Adamson05d564f2008-12-23 16:06:15 -05001517 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Benny Halevy13c65ce2009-08-14 17:19:25 +03001519 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001520 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001521 p = xdr_encode_hyper(p, arg->clientid);
1522 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001523 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001524 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Al Viro8687b632006-10-19 23:28:48 -07001529 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Benny Halevy13c65ce2009-08-14 17:19:25 +03001531 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001532 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001534 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Benny Halevy13c65ce2009-08-14 17:19:25 +03001536 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001537 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001538 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001539 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001542 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001543 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544}
1545
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001546static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Al Viro8687b632006-10-19 23:28:48 -07001548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Benny Halevy13c65ce2009-08-14 17:19:25 +03001550 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Benny Halevye75bc1c2009-08-14 17:18:54 +03001552 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001553 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001554 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001555 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001557
Benny Halevy99fe60d2009-04-01 09:22:29 -04001558#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001559/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001560static void encode_exchange_id(struct xdr_stream *xdr,
1561 struct nfs41_exchange_id_args *args,
1562 struct compound_hdr *hdr)
1563{
1564 __be32 *p;
1565
Benny Halevy13c65ce2009-08-14 17:19:25 +03001566 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001567 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001568 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001569
1570 encode_string(xdr, args->id_len, args->id);
1571
Benny Halevy13c65ce2009-08-14 17:19:25 +03001572 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001573 *p++ = cpu_to_be32(args->flags);
1574 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001576 hdr->nops++;
1577 hdr->replen += decode_exchange_id_maxsz;
1578}
Andy Adamsonfc931582009-04-01 09:22:31 -04001579
1580static void encode_create_session(struct xdr_stream *xdr,
1581 struct nfs41_create_session_args *args,
1582 struct compound_hdr *hdr)
1583{
1584 __be32 *p;
1585 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1586 uint32_t len;
1587 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001588 u32 max_resp_sz_cached;
1589
1590 /*
1591 * Assumes OPEN is the biggest non-idempotent compound.
1592 * 2 is the verifier.
1593 */
1594 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1595 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001596
Andy Adamsonfc931582009-04-01 09:22:31 -04001597 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1598 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001599
Benny Halevy13c65ce2009-08-14 17:19:25 +03001600 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001602 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1604 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001605
Andy Adamsonfc931582009-04-01 09:22:31 -04001606 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1608 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1609 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001610 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001611 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1612 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1613 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001614
1615 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001616 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1617 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1618 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1619 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1620 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1621 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1622 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001623
Benny Halevye75bc1c2009-08-14 17:18:54 +03001624 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001625 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001626 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001627
1628 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001629 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001630 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001631 *p++ = cpu_to_be32(0); /* UID */
1632 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001633 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001634 hdr->nops++;
1635 hdr->replen += decode_create_session_maxsz;
1636}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001637
1638static void encode_destroy_session(struct xdr_stream *xdr,
1639 struct nfs4_session *session,
1640 struct compound_hdr *hdr)
1641{
1642 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001643 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001644 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001645 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001646 hdr->nops++;
1647 hdr->replen += decode_destroy_session_maxsz;
1648}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001649
1650static void encode_reclaim_complete(struct xdr_stream *xdr,
1651 struct nfs41_reclaim_complete_args *args,
1652 struct compound_hdr *hdr)
1653{
1654 __be32 *p;
1655
1656 p = reserve_space(xdr, 8);
1657 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1658 *p++ = cpu_to_be32(args->one_fs);
1659 hdr->nops++;
1660 hdr->replen += decode_reclaim_complete_maxsz;
1661}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001662#endif /* CONFIG_NFS_V4_1 */
1663
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001664static void encode_sequence(struct xdr_stream *xdr,
1665 const struct nfs4_sequence_args *args,
1666 struct compound_hdr *hdr)
1667{
1668#if defined(CONFIG_NFS_V4_1)
1669 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001670 struct nfs4_slot_table *tp;
1671 struct nfs4_slot *slot;
1672 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001673
1674 if (!session)
1675 return;
1676
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001677 tp = &session->fc_slot_table;
1678
1679 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1680 slot = tp->slots + args->sa_slotid;
1681
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001683 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001684
1685 /*
1686 * Sessionid + seqid + slotid + max slotid + cache_this
1687 */
1688 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1689 "max_slotid=%d cache_this=%d\n",
1690 __func__,
1691 ((u32 *)session->sess_id.data)[0],
1692 ((u32 *)session->sess_id.data)[1],
1693 ((u32 *)session->sess_id.data)[2],
1694 ((u32 *)session->sess_id.data)[3],
1695 slot->seq_nr, args->sa_slotid,
1696 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001697 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001698 *p++ = cpu_to_be32(slot->seq_nr);
1699 *p++ = cpu_to_be32(args->sa_slotid);
1700 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001701 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001702 hdr->nops++;
1703 hdr->replen += decode_sequence_maxsz;
1704#endif /* CONFIG_NFS_V4_1 */
1705}
1706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707/*
1708 * END OF "GENERIC" ENCODE ROUTINES.
1709 */
1710
Benny Halevy66cc0422009-04-01 09:22:10 -04001711static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1712{
1713#if defined(CONFIG_NFS_V4_1)
1714 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001715 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001716#endif /* CONFIG_NFS_V4_1 */
1717 return 0;
1718}
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720/*
1721 * Encode an ACCESS request
1722 */
Al Viro8687b632006-10-19 23:28:48 -07001723static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
1725 struct xdr_stream xdr;
1726 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001727 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001731 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001732 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001733 encode_putfh(&xdr, args->fh, &hdr);
1734 encode_access(&xdr, args->access, &hdr);
1735 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001736 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738}
1739
1740/*
1741 * Encode LOOKUP request
1742 */
Al Viro8687b632006-10-19 23:28:48 -07001743static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
1745 struct xdr_stream xdr;
1746 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001747 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001751 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001752 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001753 encode_putfh(&xdr, args->dir_fh, &hdr);
1754 encode_lookup(&xdr, args->name, &hdr);
1755 encode_getfh(&xdr, &hdr);
1756 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001757 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001758 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759}
1760
1761/*
1762 * Encode LOOKUP_ROOT request
1763 */
Al Viro8687b632006-10-19 23:28:48 -07001764static 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 -07001765{
1766 struct xdr_stream xdr;
1767 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001768 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001772 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001773 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001774 encode_putrootfh(&xdr, &hdr);
1775 encode_getfh(&xdr, &hdr);
1776 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001777 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779}
1780
1781/*
1782 * Encode REMOVE request
1783 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001784static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
1786 struct xdr_stream xdr;
1787 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001788 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
1791 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001792 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001793 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001794 encode_putfh(&xdr, args->fh, &hdr);
1795 encode_remove(&xdr, &args->name, &hdr);
1796 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001797 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001798 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
1801/*
1802 * Encode RENAME request
1803 */
Al Viro8687b632006-10-19 23:28:48 -07001804static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805{
1806 struct xdr_stream xdr;
1807 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001812 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001813 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001814 encode_putfh(&xdr, args->old_dir, &hdr);
1815 encode_savefh(&xdr, &hdr);
1816 encode_putfh(&xdr, args->new_dir, &hdr);
1817 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1818 encode_getfattr(&xdr, args->bitmask, &hdr);
1819 encode_restorefh(&xdr, &hdr);
1820 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001821 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823}
1824
1825/*
1826 * Encode LINK request
1827 */
Al Viro8687b632006-10-19 23:28:48 -07001828static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829{
1830 struct xdr_stream xdr;
1831 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001832 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001836 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001837 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001838 encode_putfh(&xdr, args->fh, &hdr);
1839 encode_savefh(&xdr, &hdr);
1840 encode_putfh(&xdr, args->dir_fh, &hdr);
1841 encode_link(&xdr, args->name, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
1843 encode_restorefh(&xdr, &hdr);
1844 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001845 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001846 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847}
1848
1849/*
1850 * Encode CREATE request
1851 */
Al Viro8687b632006-10-19 23:28:48 -07001852static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
1854 struct xdr_stream xdr;
1855 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001856 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001860 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001861 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001862 encode_putfh(&xdr, args->dir_fh, &hdr);
1863 encode_savefh(&xdr, &hdr);
1864 encode_create(&xdr, args, &hdr);
1865 encode_getfh(&xdr, &hdr);
1866 encode_getfattr(&xdr, args->bitmask, &hdr);
1867 encode_restorefh(&xdr, &hdr);
1868 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001869 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001870 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
1873/*
1874 * Encode SYMLINK request
1875 */
Al Viro8687b632006-10-19 23:28:48 -07001876static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
1878 return nfs4_xdr_enc_create(req, p, args);
1879}
1880
1881/*
1882 * Encode GETATTR request
1883 */
Al Viro8687b632006-10-19 23:28:48 -07001884static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885{
1886 struct xdr_stream xdr;
1887 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001888 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001892 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001893 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001894 encode_putfh(&xdr, args->fh, &hdr);
1895 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001896 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001897 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898}
1899
1900/*
1901 * Encode a CLOSE request
1902 */
Al Viro8687b632006-10-19 23:28:48 -07001903static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
Andy Adamson05d564f2008-12-23 16:06:15 -05001905 struct xdr_stream xdr;
1906 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001907 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001908 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
Andy Adamson05d564f2008-12-23 16:06:15 -05001910 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001911 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001912 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001913 encode_putfh(&xdr, args->fh, &hdr);
1914 encode_close(&xdr, args, &hdr);
1915 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001916 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001917 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918}
1919
1920/*
1921 * Encode an OPEN request
1922 */
Al Viro8687b632006-10-19 23:28:48 -07001923static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924{
1925 struct xdr_stream xdr;
1926 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001927 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
1930 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001931 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001932 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001933 encode_putfh(&xdr, args->fh, &hdr);
1934 encode_savefh(&xdr, &hdr);
1935 encode_open(&xdr, args, &hdr);
1936 encode_getfh(&xdr, &hdr);
1937 encode_getfattr(&xdr, args->bitmask, &hdr);
1938 encode_restorefh(&xdr, &hdr);
1939 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001940 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001941 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
1943
1944/*
1945 * Encode an OPEN_CONFIRM request
1946 */
Al Viro8687b632006-10-19 23:28:48 -07001947static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
1949 struct xdr_stream xdr;
1950 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001951 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001955 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001956 encode_putfh(&xdr, args->fh, &hdr);
1957 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001958 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001959 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/*
1963 * Encode an OPEN request with no attributes.
1964 */
Al Viro8687b632006-10-19 23:28:48 -07001965static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 struct xdr_stream xdr;
1968 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
1972 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001973 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001974 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001975 encode_putfh(&xdr, args->fh, &hdr);
1976 encode_open(&xdr, args, &hdr);
1977 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001978 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001979 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
1982/*
1983 * Encode an OPEN_DOWNGRADE request
1984 */
Al Viro8687b632006-10-19 23:28:48 -07001985static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986{
1987 struct xdr_stream xdr;
1988 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001989 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
1992 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001993 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001994 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001995 encode_putfh(&xdr, args->fh, &hdr);
1996 encode_open_downgrade(&xdr, args, &hdr);
1997 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001998 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001999 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000}
2001
2002/*
2003 * Encode a LOCK request
2004 */
Al Viro8687b632006-10-19 23:28:48 -07002005static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006{
2007 struct xdr_stream xdr;
2008 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002009 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002013 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002014 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002015 encode_putfh(&xdr, args->fh, &hdr);
2016 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002017 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002018 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019}
2020
2021/*
2022 * Encode a LOCKT request
2023 */
Al Viro8687b632006-10-19 23:28:48 -07002024static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025{
2026 struct xdr_stream xdr;
2027 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002028 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
2031 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002032 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002033 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002034 encode_putfh(&xdr, args->fh, &hdr);
2035 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002036 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002037 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038}
2039
2040/*
2041 * Encode a LOCKU request
2042 */
Al Viro8687b632006-10-19 23:28:48 -07002043static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 struct xdr_stream xdr;
2046 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002047 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002051 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002052 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002053 encode_putfh(&xdr, args->fh, &hdr);
2054 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002055 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002056 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
2059/*
2060 * Encode a READLINK request
2061 */
Al Viro8687b632006-10-19 23:28:48 -07002062static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063{
2064 struct xdr_stream xdr;
2065 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002066 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002070 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002071 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002072 encode_putfh(&xdr, args->fh, &hdr);
2073 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002074
Benny Halevy28f56692009-04-01 09:22:09 -04002075 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002076 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002077 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002078 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
2081/*
2082 * Encode a READDIR request
2083 */
Al Viro8687b632006-10-19 23:28:48 -07002084static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
2086 struct xdr_stream xdr;
2087 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
2091 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002092 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002093 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002094 encode_putfh(&xdr, args->fh, &hdr);
2095 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002096
Benny Halevy28f56692009-04-01 09:22:09 -04002097 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002098 args->pgbase, args->count);
2099 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002100 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002101 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002102 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002103 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104}
2105
2106/*
2107 * Encode a READ request
2108 */
Al Viro8687b632006-10-19 23:28:48 -07002109static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 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_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Benny Halevy28f56692009-04-01 09:22:09 -04002122 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002124 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002126 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127}
2128
2129/*
2130 * Encode an SETATTR request
2131 */
Al Viro8687b632006-10-19 23:28:48 -07002132static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Andy Adamson05d564f2008-12-23 16:06:15 -05002134 struct xdr_stream xdr;
2135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Andy Adamson05d564f2008-12-23 16:06:15 -05002139 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002140 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002141 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002142 encode_putfh(&xdr, args->fh, &hdr);
2143 encode_setattr(&xdr, args, args->server, &hdr);
2144 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002146 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002150 * Encode a GETACL request
2151 */
2152static int
Al Viro8687b632006-10-19 23:28:48 -07002153nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002154 struct nfs_getaclargs *args)
2155{
2156 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002157 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002159 };
Benny Halevy28f56692009-04-01 09:22:09 -04002160 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002161
2162 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002163 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002164 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002165 encode_putfh(&xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002166 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002167 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2168
Benny Halevy28f56692009-04-01 09:22:09 -04002169 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002170 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002171 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002172 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002173}
2174
2175/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 * Encode a WRITE request
2177 */
Al Viro8687b632006-10-19 23:28:48 -07002178static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
2180 struct xdr_stream xdr;
2181 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
2185 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002186 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002187 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002188 encode_putfh(&xdr, args->fh, &hdr);
2189 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002190 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002191 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/*
2197 * a COMMIT request
2198 */
Al Viro8687b632006-10-19 23:28:48 -07002199static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
2201 struct xdr_stream xdr;
2202 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002203 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
2206 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002207 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002208 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002209 encode_putfh(&xdr, args->fh, &hdr);
2210 encode_commit(&xdr, args, &hdr);
2211 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002212 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002213 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214}
2215
2216/*
2217 * FSINFO request
2218 */
Al Viro8687b632006-10-19 23:28:48 -07002219static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
2221 struct xdr_stream xdr;
2222 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002223 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
2226 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002227 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002228 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002229 encode_putfh(&xdr, args->fh, &hdr);
2230 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002231 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002232 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233}
2234
2235/*
2236 * a PATHCONF request
2237 */
Al Viro8687b632006-10-19 23:28:48 -07002238static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 struct xdr_stream xdr;
2241 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002242 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
2245 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002246 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002247 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002248 encode_putfh(&xdr, args->fh, &hdr);
2249 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2250 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002251 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002252 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253}
2254
2255/*
2256 * a STATFS request
2257 */
Al Viro8687b632006-10-19 23:28:48 -07002258static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 struct xdr_stream xdr;
2261 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002262 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
2265 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002266 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002267 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002268 encode_putfh(&xdr, args->fh, &hdr);
2269 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2270 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * GETATTR_BITMAP request
2277 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002278static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2279 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
2281 struct xdr_stream xdr;
2282 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002283 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002287 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002288 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002289 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002290 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2291 FATTR4_WORD0_LINK_SUPPORT|
2292 FATTR4_WORD0_SYMLINK_SUPPORT|
2293 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002294 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002295 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296}
2297
2298/*
2299 * a RENEW request
2300 */
Al Viro8687b632006-10-19 23:28:48 -07002301static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
2303 struct xdr_stream xdr;
2304 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002305 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 };
2307
2308 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002309 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002310 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002311 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002312 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
2315/*
2316 * a SETCLIENTID request
2317 */
Al Viro8687b632006-10-19 23:28:48 -07002318static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319{
2320 struct xdr_stream xdr;
2321 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002322 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
2324
2325 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002326 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002327 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002328 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002329 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
2332/*
2333 * a SETCLIENTID_CONFIRM request
2334 */
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002335static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336{
2337 struct xdr_stream xdr;
2338 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002339 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 };
2341 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
2343 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002344 encode_compound_hdr(&xdr, req, &hdr);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002345 encode_setclientid_confirm(&xdr, arg, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002346 encode_putrootfh(&xdr, &hdr);
2347 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002348 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002349 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350}
2351
2352/*
2353 * DELEGRETURN request
2354 */
Al Viro8687b632006-10-19 23:28:48 -07002355static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
2357 struct xdr_stream xdr;
2358 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002359 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
2362 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002363 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002364 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002365 encode_putfh(&xdr, args->fhandle, &hdr);
2366 encode_delegreturn(&xdr, args->stateid, &hdr);
2367 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002368 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002369 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370}
2371
2372/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002373 * Encode FS_LOCATIONS request
2374 */
Al Viro8687b632006-10-19 23:28:48 -07002375static 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 -04002376{
2377 struct xdr_stream xdr;
2378 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002380 };
Benny Halevy28f56692009-04-01 09:22:09 -04002381 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002382
2383 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002384 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002385 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002386 encode_putfh(&xdr, args->dir_fh, &hdr);
2387 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002388 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002389 encode_fs_locations(&xdr, args->bitmask, &hdr);
2390
Benny Halevy28f56692009-04-01 09:22:09 -04002391 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002392 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002393 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002394 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002395}
2396
Benny Halevy99fe60d2009-04-01 09:22:29 -04002397#if defined(CONFIG_NFS_V4_1)
2398/*
2399 * EXCHANGE_ID request
2400 */
2401static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2402 struct nfs41_exchange_id_args *args)
2403{
2404 struct xdr_stream xdr;
2405 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002406 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002407 };
2408
2409 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2410 encode_compound_hdr(&xdr, req, &hdr);
2411 encode_exchange_id(&xdr, args, &hdr);
2412 encode_nops(&hdr);
2413 return 0;
2414}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002415
2416/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002417 * a CREATE_SESSION request
2418 */
2419static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2420 struct nfs41_create_session_args *args)
2421{
2422 struct xdr_stream xdr;
2423 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002424 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002425 };
2426
2427 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2428 encode_compound_hdr(&xdr, req, &hdr);
2429 encode_create_session(&xdr, args, &hdr);
2430 encode_nops(&hdr);
2431 return 0;
2432}
2433
2434/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002435 * a DESTROY_SESSION request
2436 */
2437static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2438 struct nfs4_session *session)
2439{
2440 struct xdr_stream xdr;
2441 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002442 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002443 };
2444
2445 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2446 encode_compound_hdr(&xdr, req, &hdr);
2447 encode_destroy_session(&xdr, session, &hdr);
2448 encode_nops(&hdr);
2449 return 0;
2450}
2451
2452/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002453 * a SEQUENCE request
2454 */
2455static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2456 struct nfs4_sequence_args *args)
2457{
2458 struct xdr_stream xdr;
2459 struct compound_hdr hdr = {
2460 .minorversion = nfs4_xdr_minorversion(args),
2461 };
2462
2463 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2464 encode_compound_hdr(&xdr, req, &hdr);
2465 encode_sequence(&xdr, args, &hdr);
2466 encode_nops(&hdr);
2467 return 0;
2468}
2469
2470/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002471 * a GET_LEASE_TIME request
2472 */
2473static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2474 struct nfs4_get_lease_time_args *args)
2475{
2476 struct xdr_stream xdr;
2477 struct compound_hdr hdr = {
2478 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2479 };
2480 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2481
2482 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2483 encode_compound_hdr(&xdr, req, &hdr);
2484 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2485 encode_putrootfh(&xdr, &hdr);
2486 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2487 encode_nops(&hdr);
2488 return 0;
2489}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002490
2491/*
2492 * a RECLAIM_COMPLETE request
2493 */
2494static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2495 struct nfs41_reclaim_complete_args *args)
2496{
2497 struct xdr_stream xdr;
2498 struct compound_hdr hdr = {
2499 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2500 };
2501
2502 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2503 encode_compound_hdr(&xdr, req, &hdr);
2504 encode_sequence(&xdr, &args->seq_args, &hdr);
2505 encode_reclaim_complete(&xdr, args, &hdr);
2506 encode_nops(&hdr);
2507 return 0;
2508}
2509
Benny Halevy99fe60d2009-04-01 09:22:29 -04002510#endif /* CONFIG_NFS_V4_1 */
2511
Benny Halevy686841b2009-08-14 17:19:48 +03002512static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2513{
2514 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2515 "Remaining buffer length is %tu words.\n",
2516 func, xdr->end - xdr->p);
2517}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Trond Myklebust683b57b2006-06-09 09:34:22 -04002519static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
Al Viro8687b632006-10-19 23:28:48 -07002521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Benny Halevyc0eae662009-08-14 17:20:14 +03002523 p = xdr_inline_decode(xdr, 4);
2524 if (unlikely(!p))
2525 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002526 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002527 p = xdr_inline_decode(xdr, *len);
2528 if (unlikely(!p))
2529 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 *string = (char *)p;
2531 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002532out_overflow:
2533 print_overflow_msg(__func__, xdr);
2534 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2538{
Al Viro8687b632006-10-19 23:28:48 -07002539 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Benny Halevyc0eae662009-08-14 17:20:14 +03002541 p = xdr_inline_decode(xdr, 8);
2542 if (unlikely(!p))
2543 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002544 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002545 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002546
Benny Halevyc0eae662009-08-14 17:20:14 +03002547 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2548 if (unlikely(!p))
2549 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 hdr->tag = (char *)p;
2551 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002552 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002553 if (unlikely(hdr->nops < 1))
2554 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002556out_overflow:
2557 print_overflow_msg(__func__, xdr);
2558 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559}
2560
2561static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2562{
Al Viro8687b632006-10-19 23:28:48 -07002563 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 uint32_t opnum;
2565 int32_t nfserr;
2566
Benny Halevyc0eae662009-08-14 17:20:14 +03002567 p = xdr_inline_decode(xdr, 8);
2568 if (unlikely(!p))
2569 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002570 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002572 dprintk("nfs: Server returned operation"
2573 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 opnum, expected);
2575 return -EIO;
2576 }
Benny Halevycccddf42009-08-14 17:20:19 +03002577 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002579 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002581out_overflow:
2582 print_overflow_msg(__func__, xdr);
2583 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584}
2585
2586/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002587static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588{
Al Viro8687b632006-10-19 23:28:48 -07002589 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002590 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 char *str;
2592
Benny Halevyc0eae662009-08-14 17:20:14 +03002593 p = xdr_inline_decode(xdr, 12);
2594 if (likely(p))
2595 return decode_opaque_inline(xdr, &strlen, &str);
2596 print_overflow_msg(__func__, xdr);
2597 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598}
2599
2600static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2601{
Al Viro8687b632006-10-19 23:28:48 -07002602 uint32_t bmlen;
2603 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Benny Halevyc0eae662009-08-14 17:20:14 +03002605 p = xdr_inline_decode(xdr, 4);
2606 if (unlikely(!p))
2607 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002608 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609
2610 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002611 p = xdr_inline_decode(xdr, (bmlen << 2));
2612 if (unlikely(!p))
2613 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002615 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002617 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 }
2619 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002620out_overflow:
2621 print_overflow_msg(__func__, xdr);
2622 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
Al Viro8687b632006-10-19 23:28:48 -07002625static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
Al Viro8687b632006-10-19 23:28:48 -07002627 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Benny Halevyc0eae662009-08-14 17:20:14 +03002629 p = xdr_inline_decode(xdr, 4);
2630 if (unlikely(!p))
2631 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002632 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 *savep = xdr->p;
2634 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002635out_overflow:
2636 print_overflow_msg(__func__, xdr);
2637 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638}
2639
2640static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2641{
2642 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2643 decode_attr_bitmap(xdr, bitmask);
2644 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2645 } else
2646 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002647 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 return 0;
2649}
2650
2651static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2652{
Al Viro8687b632006-10-19 23:28:48 -07002653 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002654 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
2656 *type = 0;
2657 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2658 return -EIO;
2659 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002660 p = xdr_inline_decode(xdr, 4);
2661 if (unlikely(!p))
2662 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002663 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002665 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 return -EIO;
2667 }
2668 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002669 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002671 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002672 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002673out_overflow:
2674 print_overflow_msg(__func__, xdr);
2675 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
2678static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2679{
Al Viro8687b632006-10-19 23:28:48 -07002680 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002681 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 *change = 0;
2684 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2685 return -EIO;
2686 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002687 p = xdr_inline_decode(xdr, 8);
2688 if (unlikely(!p))
2689 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002690 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002692 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002694 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002696 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002697out_overflow:
2698 print_overflow_msg(__func__, xdr);
2699 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700}
2701
2702static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2703{
Al Viro8687b632006-10-19 23:28:48 -07002704 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002705 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
2707 *size = 0;
2708 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2709 return -EIO;
2710 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002711 p = xdr_inline_decode(xdr, 8);
2712 if (unlikely(!p))
2713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002714 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002716 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002718 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002719 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002720out_overflow:
2721 print_overflow_msg(__func__, xdr);
2722 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723}
2724
2725static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2726{
Al Viro8687b632006-10-19 23:28:48 -07002727 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
2729 *res = 0;
2730 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2731 return -EIO;
2732 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002733 p = xdr_inline_decode(xdr, 4);
2734 if (unlikely(!p))
2735 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002736 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2738 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002739 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002741out_overflow:
2742 print_overflow_msg(__func__, xdr);
2743 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744}
2745
2746static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2747{
Al Viro8687b632006-10-19 23:28:48 -07002748 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
2750 *res = 0;
2751 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2752 return -EIO;
2753 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002754 p = xdr_inline_decode(xdr, 4);
2755 if (unlikely(!p))
2756 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002757 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002760 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002762out_overflow:
2763 print_overflow_msg(__func__, xdr);
2764 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765}
2766
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002767static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768{
Al Viro8687b632006-10-19 23:28:48 -07002769 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002770 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
2772 fsid->major = 0;
2773 fsid->minor = 0;
2774 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2775 return -EIO;
2776 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002777 p = xdr_inline_decode(xdr, 16);
2778 if (unlikely(!p))
2779 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002780 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002781 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002783 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002785 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 (unsigned long long)fsid->major,
2787 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002788 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002789out_overflow:
2790 print_overflow_msg(__func__, xdr);
2791 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792}
2793
2794static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2795{
Al Viro8687b632006-10-19 23:28:48 -07002796 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 *res = 60;
2799 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2800 return -EIO;
2801 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002802 p = xdr_inline_decode(xdr, 4);
2803 if (unlikely(!p))
2804 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002805 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2807 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002808 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002810out_overflow:
2811 print_overflow_msg(__func__, xdr);
2812 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813}
2814
2815static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2816{
Al Viro8687b632006-10-19 23:28:48 -07002817 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
2819 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2820 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2821 return -EIO;
2822 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002823 p = xdr_inline_decode(xdr, 4);
2824 if (unlikely(!p))
2825 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002826 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2828 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002829 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002831out_overflow:
2832 print_overflow_msg(__func__, xdr);
2833 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834}
2835
2836static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2837{
Al Viro8687b632006-10-19 23:28:48 -07002838 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002839 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
2841 *fileid = 0;
2842 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2843 return -EIO;
2844 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002845 p = xdr_inline_decode(xdr, 8);
2846 if (unlikely(!p))
2847 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002848 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002850 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002852 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002853 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002854out_overflow:
2855 print_overflow_msg(__func__, xdr);
2856 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857}
2858
Manoj Naik99baf622006-06-09 09:34:24 -04002859static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2860{
Al Viro8687b632006-10-19 23:28:48 -07002861 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002862 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002863
2864 *fileid = 0;
2865 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2866 return -EIO;
2867 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002868 p = xdr_inline_decode(xdr, 8);
2869 if (unlikely(!p))
2870 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002871 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002872 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002873 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002874 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002875 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002876 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002877out_overflow:
2878 print_overflow_msg(__func__, xdr);
2879 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002880}
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2883{
Al Viro8687b632006-10-19 23:28:48 -07002884 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 int status = 0;
2886
2887 *res = 0;
2888 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2889 return -EIO;
2890 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002891 p = xdr_inline_decode(xdr, 8);
2892 if (unlikely(!p))
2893 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002894 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2896 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002897 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002899out_overflow:
2900 print_overflow_msg(__func__, xdr);
2901 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902}
2903
2904static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2905{
Al Viro8687b632006-10-19 23:28:48 -07002906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 int status = 0;
2908
2909 *res = 0;
2910 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2911 return -EIO;
2912 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002913 p = xdr_inline_decode(xdr, 8);
2914 if (unlikely(!p))
2915 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002916 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2918 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002919 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002921out_overflow:
2922 print_overflow_msg(__func__, xdr);
2923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924}
2925
2926static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2927{
Al Viro8687b632006-10-19 23:28:48 -07002928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 int status = 0;
2930
2931 *res = 0;
2932 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2933 return -EIO;
2934 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002935 p = xdr_inline_decode(xdr, 8);
2936 if (unlikely(!p))
2937 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002938 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2940 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002941 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002943out_overflow:
2944 print_overflow_msg(__func__, xdr);
2945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946}
2947
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002948static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2949{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002950 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002951 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002952 int status = 0;
2953
Benny Halevyc0eae662009-08-14 17:20:14 +03002954 p = xdr_inline_decode(xdr, 4);
2955 if (unlikely(!p))
2956 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002957 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04002958 if (n == 0)
2959 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002960 dprintk("path ");
2961 path->ncomponents = 0;
2962 while (path->ncomponents < n) {
2963 struct nfs4_string *component = &path->components[path->ncomponents];
2964 status = decode_opaque_inline(xdr, &component->len, &component->data);
2965 if (unlikely(status != 0))
2966 goto out_eio;
2967 if (path->ncomponents != n)
2968 dprintk("/");
2969 dprintk("%s", component->data);
2970 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2971 path->ncomponents++;
2972 else {
2973 dprintk("cannot parse %d components in path\n", n);
2974 goto out_eio;
2975 }
2976 }
2977out:
2978 dprintk("\n");
2979 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002980root_path:
2981/* a root pathname is sent as a zero component4 */
2982 path->ncomponents = 1;
2983 path->components[0].len=0;
2984 path->components[0].data=NULL;
2985 dprintk("path /\n");
2986 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002987out_eio:
2988 dprintk(" status %d", status);
2989 status = -EIO;
2990 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002991out_overflow:
2992 print_overflow_msg(__func__, xdr);
2993 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002994}
2995
2996static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002997{
2998 int n;
Al Viro8687b632006-10-19 23:28:48 -07002999 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003000 int status = -EIO;
3001
3002 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3003 goto out;
3004 status = 0;
3005 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3006 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003007 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003008 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003009 if (unlikely(status != 0))
3010 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003011 p = xdr_inline_decode(xdr, 4);
3012 if (unlikely(!p))
3013 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003014 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003015 if (n <= 0)
3016 goto out_eio;
3017 res->nlocations = 0;
3018 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003019 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003020 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003021
Benny Halevyc0eae662009-08-14 17:20:14 +03003022 p = xdr_inline_decode(xdr, 4);
3023 if (unlikely(!p))
3024 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003025 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003026
3027 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003028 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003029 while (loc->nservers < m) {
3030 struct nfs4_string *server = &loc->servers[loc->nservers];
3031 status = decode_opaque_inline(xdr, &server->len, &server->data);
3032 if (unlikely(status != 0))
3033 goto out_eio;
3034 dprintk("%s ", server->data);
3035 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3036 loc->nservers++;
3037 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003038 unsigned int i;
3039 dprintk("%s: using first %u of %u servers "
3040 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003041 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003042 NFS4_FS_LOCATION_MAXSERVERS,
3043 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003044 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003045 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003046 char *data;
3047 status = decode_opaque_inline(xdr, &len, &data);
3048 if (unlikely(status != 0))
3049 goto out_eio;
3050 }
3051 }
3052 }
3053 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003054 if (unlikely(status != 0))
3055 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003056 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003057 res->nlocations++;
3058 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003059 if (res->nlocations != 0)
3060 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003061out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003062 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003063 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003064out_overflow:
3065 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003066out_eio:
3067 status = -EIO;
3068 goto out;
3069}
3070
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3072{
Al Viro8687b632006-10-19 23:28:48 -07003073 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 int status = 0;
3075
3076 *res = 0;
3077 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3078 return -EIO;
3079 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003080 p = xdr_inline_decode(xdr, 8);
3081 if (unlikely(!p))
3082 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003083 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3085 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003086 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003088out_overflow:
3089 print_overflow_msg(__func__, xdr);
3090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
3093static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3094{
Al Viro8687b632006-10-19 23:28:48 -07003095 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 int status = 0;
3097
3098 *maxlink = 1;
3099 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3100 return -EIO;
3101 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003102 p = xdr_inline_decode(xdr, 4);
3103 if (unlikely(!p))
3104 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003105 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3107 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003108 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003110out_overflow:
3111 print_overflow_msg(__func__, xdr);
3112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113}
3114
3115static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3116{
Al Viro8687b632006-10-19 23:28:48 -07003117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 int status = 0;
3119
3120 *maxname = 1024;
3121 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3122 return -EIO;
3123 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003124 p = xdr_inline_decode(xdr, 4);
3125 if (unlikely(!p))
3126 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003127 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3129 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003130 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003132out_overflow:
3133 print_overflow_msg(__func__, xdr);
3134 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135}
3136
3137static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3138{
Al Viro8687b632006-10-19 23:28:48 -07003139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 int status = 0;
3141
3142 *res = 1024;
3143 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3144 return -EIO;
3145 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3146 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, 8);
3148 if (unlikely(!p))
3149 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003150 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 if (maxread > 0x7FFFFFFF)
3152 maxread = 0x7FFFFFFF;
3153 *res = (uint32_t)maxread;
3154 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3155 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003156 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
3163static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3164{
Al Viro8687b632006-10-19 23:28:48 -07003165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 int status = 0;
3167
3168 *res = 1024;
3169 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3170 return -EIO;
3171 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3172 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 8);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (maxwrite > 0x7FFFFFFF)
3178 maxwrite = 0x7FFFFFFF;
3179 *res = (uint32_t)maxwrite;
3180 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3181 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003182 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
Trond Myklebustbca79472009-03-11 14:10:26 -04003189static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190{
Trond Myklebustbca79472009-03-11 14:10:26 -04003191 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003192 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 *mode = 0;
3196 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3197 return -EIO;
3198 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003199 p = xdr_inline_decode(xdr, 4);
3200 if (unlikely(!p))
3201 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003202 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003203 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003205 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003207 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003208 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003209out_overflow:
3210 print_overflow_msg(__func__, xdr);
3211 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212}
3213
3214static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3215{
Al Viro8687b632006-10-19 23:28:48 -07003216 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
3219 *nlink = 1;
3220 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3221 return -EIO;
3222 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003223 p = xdr_inline_decode(xdr, 4);
3224 if (unlikely(!p))
3225 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003226 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003230 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003231 return ret;
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
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003237static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3238 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239{
Al Viro8687b632006-10-19 23:28:48 -07003240 uint32_t len;
3241 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003242 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 *uid = -2;
3245 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3246 return -EIO;
3247 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003248 p = xdr_inline_decode(xdr, 4);
3249 if (unlikely(!p))
3250 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003251 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003252 p = xdr_inline_decode(xdr, len);
3253 if (unlikely(!p))
3254 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003255 if (!may_sleep) {
3256 /* do nothing */
3257 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003258 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3259 ret = NFS_ATTR_FATTR_OWNER;
3260 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003262 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003264 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003265 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3267 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003268 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003269 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003270out_overflow:
3271 print_overflow_msg(__func__, xdr);
3272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273}
3274
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003275static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3276 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277{
Al Viro8687b632006-10-19 23:28:48 -07003278 uint32_t len;
3279 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003280 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
3282 *gid = -2;
3283 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3284 return -EIO;
3285 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003286 p = xdr_inline_decode(xdr, 4);
3287 if (unlikely(!p))
3288 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003289 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003290 p = xdr_inline_decode(xdr, len);
3291 if (unlikely(!p))
3292 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003293 if (!may_sleep) {
3294 /* do nothing */
3295 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3297 ret = NFS_ATTR_FATTR_GROUP;
3298 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003300 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003302 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003303 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3305 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003306 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003307 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003308out_overflow:
3309 print_overflow_msg(__func__, xdr);
3310 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311}
3312
3313static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3314{
Al Viro8687b632006-10-19 23:28:48 -07003315 uint32_t major = 0, minor = 0;
3316 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003317 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 *rdev = MKDEV(0,0);
3320 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3323 dev_t tmp;
3324
Benny Halevyc0eae662009-08-14 17:20:14 +03003325 p = xdr_inline_decode(xdr, 8);
3326 if (unlikely(!p))
3327 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003328 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003329 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 tmp = MKDEV(major, minor);
3331 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3332 *rdev = tmp;
3333 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003334 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003336 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003337 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003338out_overflow:
3339 print_overflow_msg(__func__, xdr);
3340 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341}
3342
3343static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3344{
Al Viro8687b632006-10-19 23:28:48 -07003345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 int status = 0;
3347
3348 *res = 0;
3349 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3350 return -EIO;
3351 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003352 p = xdr_inline_decode(xdr, 8);
3353 if (unlikely(!p))
3354 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003355 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3357 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003358 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003360out_overflow:
3361 print_overflow_msg(__func__, xdr);
3362 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363}
3364
3365static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3366{
Al Viro8687b632006-10-19 23:28:48 -07003367 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 int status = 0;
3369
3370 *res = 0;
3371 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3372 return -EIO;
3373 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003374 p = xdr_inline_decode(xdr, 8);
3375 if (unlikely(!p))
3376 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003377 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3379 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003380 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003382out_overflow:
3383 print_overflow_msg(__func__, xdr);
3384 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385}
3386
3387static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3388{
Al Viro8687b632006-10-19 23:28:48 -07003389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 int status = 0;
3391
3392 *res = 0;
3393 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3394 return -EIO;
3395 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003396 p = xdr_inline_decode(xdr, 8);
3397 if (unlikely(!p))
3398 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003399 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3401 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003402 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003404out_overflow:
3405 print_overflow_msg(__func__, xdr);
3406 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407}
3408
3409static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3410{
Al Viro8687b632006-10-19 23:28:48 -07003411 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003412 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
3414 *used = 0;
3415 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3416 return -EIO;
3417 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003418 p = xdr_inline_decode(xdr, 8);
3419 if (unlikely(!p))
3420 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003421 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003423 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003425 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003427 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003428out_overflow:
3429 print_overflow_msg(__func__, xdr);
3430 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431}
3432
3433static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3434{
Al Viro8687b632006-10-19 23:28:48 -07003435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 uint64_t sec;
3437 uint32_t nsec;
3438
Benny Halevyc0eae662009-08-14 17:20:14 +03003439 p = xdr_inline_decode(xdr, 12);
3440 if (unlikely(!p))
3441 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003442 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003443 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 time->tv_sec = (time_t)sec;
3445 time->tv_nsec = (long)nsec;
3446 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003447out_overflow:
3448 print_overflow_msg(__func__, xdr);
3449 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450}
3451
3452static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3453{
3454 int status = 0;
3455
3456 time->tv_sec = 0;
3457 time->tv_nsec = 0;
3458 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3459 return -EIO;
3460 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3461 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 if (status == 0)
3463 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3465 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003466 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 return status;
3468}
3469
3470static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3471{
3472 int status = 0;
3473
3474 time->tv_sec = 0;
3475 time->tv_nsec = 0;
3476 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3477 return -EIO;
3478 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3479 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003480 if (status == 0)
3481 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3483 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003484 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 return status;
3486}
3487
3488static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3489{
3490 int status = 0;
3491
3492 time->tv_sec = 0;
3493 time->tv_nsec = 0;
3494 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3495 return -EIO;
3496 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3497 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003498 if (status == 0)
3499 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3501 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003502 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 return status;
3504}
3505
Al Viro8687b632006-10-19 23:28:48 -07003506static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507{
3508 unsigned int attrwords = XDR_QUADLEN(attrlen);
3509 unsigned int nwords = xdr->p - savep;
3510
3511 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003512 dprintk("%s: server returned incorrect attribute length: "
3513 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003514 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 attrwords << 2,
3516 (attrwords < nwords) ? '<' : '>',
3517 nwords << 2);
3518 return -EIO;
3519 }
3520 return 0;
3521}
3522
3523static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3524{
Al Viro8687b632006-10-19 23:28:48 -07003525 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
Benny Halevyc0eae662009-08-14 17:20:14 +03003527 p = xdr_inline_decode(xdr, 20);
3528 if (unlikely(!p))
3529 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003530 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003531 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003532 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003534out_overflow:
3535 print_overflow_msg(__func__, xdr);
3536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537}
3538
3539static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3540{
Al Viro8687b632006-10-19 23:28:48 -07003541 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 uint32_t supp, acc;
3543 int status;
3544
3545 status = decode_op_hdr(xdr, OP_ACCESS);
3546 if (status)
3547 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003548 p = xdr_inline_decode(xdr, 8);
3549 if (unlikely(!p))
3550 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003551 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003552 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 access->supported = supp;
3554 access->access = acc;
3555 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003556out_overflow:
3557 print_overflow_msg(__func__, xdr);
3558 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559}
3560
Benny Halevy07d30432009-08-14 17:19:52 +03003561static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562{
Al Viro8687b632006-10-19 23:28:48 -07003563 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003564
3565 p = xdr_inline_decode(xdr, len);
3566 if (likely(p)) {
3567 memcpy(buf, p, len);
3568 return 0;
3569 }
3570 print_overflow_msg(__func__, xdr);
3571 return -EIO;
3572}
3573
3574static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3575{
3576 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577}
3578
3579static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3580{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 int status;
3582
3583 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003584 if (status != -EIO)
3585 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003586 if (!status)
3587 status = decode_stateid(xdr, &res->stateid);
3588 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589}
3590
Benny Halevydb942bb2009-08-14 17:19:56 +03003591static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3592{
3593 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594}
3595
3596static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 int status;
3599
3600 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003601 if (!status)
3602 status = decode_verifier(xdr, res->verf->verifier);
3603 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604}
3605
3606static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3607{
Al Viro8687b632006-10-19 23:28:48 -07003608 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 uint32_t bmlen;
3610 int status;
3611
3612 status = decode_op_hdr(xdr, OP_CREATE);
3613 if (status)
3614 return status;
3615 if ((status = decode_change_info(xdr, cinfo)))
3616 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003617 p = xdr_inline_decode(xdr, 4);
3618 if (unlikely(!p))
3619 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003620 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003621 p = xdr_inline_decode(xdr, bmlen << 2);
3622 if (likely(p))
3623 return 0;
3624out_overflow:
3625 print_overflow_msg(__func__, xdr);
3626 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627}
3628
3629static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3630{
Al Viro8687b632006-10-19 23:28:48 -07003631 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003632 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 int status;
3634
3635 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3636 goto xdr_error;
3637 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3638 goto xdr_error;
3639 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3640 goto xdr_error;
3641 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3642 goto xdr_error;
3643 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3644 goto xdr_error;
3645 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3646 goto xdr_error;
3647 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3648 goto xdr_error;
3649 status = verify_attr_len(xdr, savep, attrlen);
3650xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003651 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 return status;
3653}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003654
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3656{
Al Viro8687b632006-10-19 23:28:48 -07003657 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003658 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003660
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3662 goto xdr_error;
3663 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3664 goto xdr_error;
3665 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3666 goto xdr_error;
3667
3668 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3669 goto xdr_error;
3670 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3671 goto xdr_error;
3672 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3673 goto xdr_error;
3674 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3675 goto xdr_error;
3676 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3677 goto xdr_error;
3678 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3679 goto xdr_error;
3680
3681 status = verify_attr_len(xdr, savep, attrlen);
3682xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003683 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 return status;
3685}
3686
3687static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3688{
Al Viro8687b632006-10-19 23:28:48 -07003689 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003690 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003692
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3694 goto xdr_error;
3695 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3696 goto xdr_error;
3697 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3698 goto xdr_error;
3699
3700 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3701 goto xdr_error;
3702 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3703 goto xdr_error;
3704
3705 status = verify_attr_len(xdr, savep, attrlen);
3706xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003707 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 return status;
3709}
3710
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003711static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3712 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713{
Al Viro8687b632006-10-19 23:28:48 -07003714 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 uint32_t attrlen,
3716 bitmap[2] = {0},
3717 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003718 int status;
3719 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003720 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003722 status = decode_op_hdr(xdr, OP_GETATTR);
3723 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 goto xdr_error;
3725
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003726 status = decode_attr_bitmap(xdr, bitmap);
3727 if (status < 0)
3728 goto xdr_error;
3729
3730 status = decode_attr_length(xdr, &attrlen, &savep);
3731 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 goto xdr_error;
3733
3734
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003735 status = decode_attr_type(xdr, bitmap, &type);
3736 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003738 fattr->mode = 0;
3739 if (status != 0) {
3740 fattr->mode |= nfs_type2fmt[type];
3741 fattr->valid |= status;
3742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003744 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3745 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003747 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003748
3749 status = decode_attr_size(xdr, bitmap, &fattr->size);
3750 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003752 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003753
3754 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3755 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003757 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003758
3759 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3760 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003762 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003763
3764 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003765 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003766 fattr));
3767 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003768 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003769 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003770
3771 status = decode_attr_mode(xdr, bitmap, &fmode);
3772 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 if (status != 0) {
3775 fattr->mode |= fmode;
3776 fattr->valid |= status;
3777 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003778
3779 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3780 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003782 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003783
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003784 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3785 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003786 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003788 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003789
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003790 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3791 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003792 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003794 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003795
3796 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3797 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003799 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003800
3801 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3802 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003805
3806 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3807 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003809 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003810
3811 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3812 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003814 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003815
3816 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3817 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003820
3821 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3822 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003823 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003824 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003825 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003826 fattr->valid |= status;
3827 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003828
3829 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003831 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 return status;
3833}
3834
3835
3836static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3837{
Al Viro8687b632006-10-19 23:28:48 -07003838 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 uint32_t attrlen, bitmap[2];
3840 int status;
3841
3842 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3843 goto xdr_error;
3844 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3845 goto xdr_error;
3846 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3847 goto xdr_error;
3848
3849 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3850
3851 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3852 goto xdr_error;
3853 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3854 goto xdr_error;
3855 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3856 goto xdr_error;
3857 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3858 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3859 goto xdr_error;
3860 fsinfo->wtpref = fsinfo->wtmax;
3861
3862 status = verify_attr_len(xdr, savep, attrlen);
3863xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003864 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 return status;
3866}
3867
3868static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3869{
Al Viro8687b632006-10-19 23:28:48 -07003870 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 uint32_t len;
3872 int status;
3873
Trond Myklebust99367812007-07-17 21:52:41 -04003874 /* Zero handle first to allow comparisons */
3875 memset(fh, 0, sizeof(*fh));
3876
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 status = decode_op_hdr(xdr, OP_GETFH);
3878 if (status)
3879 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880
Benny Halevyc0eae662009-08-14 17:20:14 +03003881 p = xdr_inline_decode(xdr, 4);
3882 if (unlikely(!p))
3883 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003884 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 if (len > NFS4_FHSIZE)
3886 return -EIO;
3887 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, len);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03003891 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003893out_overflow:
3894 print_overflow_msg(__func__, xdr);
3895 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896}
3897
3898static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3899{
3900 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003901
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 status = decode_op_hdr(xdr, OP_LINK);
3903 if (status)
3904 return status;
3905 return decode_change_info(xdr, cinfo);
3906}
3907
3908/*
3909 * We create the owner, so we know a proper owner.id length is 4.
3910 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003911static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003913 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003914 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003915 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
Benny Halevyc0eae662009-08-14 17:20:14 +03003917 p = xdr_inline_decode(xdr, 32);
3918 if (unlikely(!p))
3919 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003920 p = xdr_decode_hyper(p, &offset);
3921 p = xdr_decode_hyper(p, &length);
Benny Halevy6f723f72009-08-14 17:19:37 +03003922 type = be32_to_cpup(p++);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003923 if (fl != NULL) {
3924 fl->fl_start = (loff_t)offset;
3925 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3926 if (length == ~(uint64_t)0)
3927 fl->fl_end = OFFSET_MAX;
3928 fl->fl_type = F_WRLCK;
3929 if (type & 1)
3930 fl->fl_type = F_RDLCK;
3931 fl->fl_pid = 0;
3932 }
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003933 p = xdr_decode_hyper(p, &clientid);
Benny Halevycccddf42009-08-14 17:20:19 +03003934 namelen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003935 p = xdr_inline_decode(xdr, namelen);
3936 if (likely(p))
3937 return -NFS4ERR_DENIED;
3938out_overflow:
3939 print_overflow_msg(__func__, xdr);
3940 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941}
3942
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003943static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 int status;
3946
3947 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003948 if (status == -EIO)
3949 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03003951 status = decode_stateid(xdr, &res->stateid);
3952 if (unlikely(status))
3953 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003955 status = decode_lock_denied(xdr, NULL);
3956 if (res->open_seqid != NULL)
3957 nfs_increment_open_seqid(status, res->open_seqid);
3958 nfs_increment_lock_seqid(status, res->lock_seqid);
3959out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 return status;
3961}
3962
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003963static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964{
3965 int status;
3966 status = decode_op_hdr(xdr, OP_LOCKT);
3967 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003968 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 return status;
3970}
3971
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003972static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 int status;
3975
3976 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003977 if (status != -EIO)
3978 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003979 if (status == 0)
3980 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 return status;
3982}
3983
3984static int decode_lookup(struct xdr_stream *xdr)
3985{
3986 return decode_op_hdr(xdr, OP_LOOKUP);
3987}
3988
3989/* This is too sick! */
3990static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3991{
Andy Adamson05d564f2008-12-23 16:06:15 -05003992 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 uint32_t limit_type, nblocks, blocksize;
3994
Benny Halevyc0eae662009-08-14 17:20:14 +03003995 p = xdr_inline_decode(xdr, 12);
3996 if (unlikely(!p))
3997 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003998 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004000 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004001 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004002 break;
4003 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004004 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004005 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004006 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 }
4008 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004009out_overflow:
4010 print_overflow_msg(__func__, xdr);
4011 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012}
4013
4014static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4015{
Andy Adamson05d564f2008-12-23 16:06:15 -05004016 __be32 *p;
4017 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004018 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019
Benny Halevyc0eae662009-08-14 17:20:14 +03004020 p = xdr_inline_decode(xdr, 4);
4021 if (unlikely(!p))
4022 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004023 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4025 res->delegation_type = 0;
4026 return 0;
4027 }
Benny Halevy07d30432009-08-14 17:19:52 +03004028 status = decode_stateid(xdr, &res->delegation);
4029 if (unlikely(status))
4030 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004031 p = xdr_inline_decode(xdr, 4);
4032 if (unlikely(!p))
4033 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004034 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004035
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004037 case NFS4_OPEN_DELEGATE_READ:
4038 res->delegation_type = FMODE_READ;
4039 break;
4040 case NFS4_OPEN_DELEGATE_WRITE:
4041 res->delegation_type = FMODE_WRITE|FMODE_READ;
4042 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 return -EIO;
4044 }
David Howells7539bba2006-08-22 20:06:09 -04004045 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004046out_overflow:
4047 print_overflow_msg(__func__, xdr);
4048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049}
4050
4051static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4052{
Andy Adamson05d564f2008-12-23 16:06:15 -05004053 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004054 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004055 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056
Andy Adamson05d564f2008-12-23 16:06:15 -05004057 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004058 if (status != -EIO)
4059 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004060 if (!status)
4061 status = decode_stateid(xdr, &res->stateid);
4062 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004063 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064
Andy Adamson05d564f2008-12-23 16:06:15 -05004065 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Benny Halevyc0eae662009-08-14 17:20:14 +03004067 p = xdr_inline_decode(xdr, 8);
4068 if (unlikely(!p))
4069 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004070 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004071 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004072 if (bmlen > 10)
4073 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074
Benny Halevyc0eae662009-08-14 17:20:14 +03004075 p = xdr_inline_decode(xdr, bmlen << 2);
4076 if (unlikely(!p))
4077 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004078 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4079 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004080 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004081 for (; i < NFS4_BITMAP_SIZE; i++)
4082 res->attrset[i] = 0;
4083
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 return decode_delegation(xdr, res);
4085xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004086 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004088out_overflow:
4089 print_overflow_msg(__func__, xdr);
4090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091}
4092
4093static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4094{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 int status;
4096
Andy Adamson05d564f2008-12-23 16:06:15 -05004097 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004098 if (status != -EIO)
4099 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004100 if (!status)
4101 status = decode_stateid(xdr, &res->stateid);
4102 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103}
4104
4105static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4106{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 int status;
4108
4109 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004110 if (status != -EIO)
4111 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004112 if (!status)
4113 status = decode_stateid(xdr, &res->stateid);
4114 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115}
4116
4117static int decode_putfh(struct xdr_stream *xdr)
4118{
4119 return decode_op_hdr(xdr, OP_PUTFH);
4120}
4121
4122static int decode_putrootfh(struct xdr_stream *xdr)
4123{
4124 return decode_op_hdr(xdr, OP_PUTROOTFH);
4125}
4126
4127static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4128{
4129 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004130 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 uint32_t count, eof, recvd, hdrlen;
4132 int status;
4133
4134 status = decode_op_hdr(xdr, OP_READ);
4135 if (status)
4136 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004137 p = xdr_inline_decode(xdr, 8);
4138 if (unlikely(!p))
4139 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004140 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004141 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4143 recvd = req->rq_rcv_buf.len - hdrlen;
4144 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004145 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 "count %u > recvd %u\n", count, recvd);
4147 count = recvd;
4148 eof = 0;
4149 }
4150 xdr_read_pages(xdr, count);
4151 res->eof = eof;
4152 res->count = count;
4153 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004154out_overflow:
4155 print_overflow_msg(__func__, xdr);
4156 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157}
4158
4159static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4160{
4161 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4162 struct page *page = *rcvbuf->pages;
4163 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004164 size_t hdrlen;
4165 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07004166 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004167 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04004168 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
4170 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004171 if (!status)
4172 status = decode_verifier(xdr, readdir->verifier.data);
4173 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004175 dprintk("%s: verifier = %08x:%08x\n",
4176 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004177 ((u32 *)readdir->verifier.data)[0],
4178 ((u32 *)readdir->verifier.data)[1]);
4179
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180
Benny Halevydb942bb2009-08-14 17:19:56 +03004181 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 recvd = rcvbuf->len - hdrlen;
4183 if (pglen > recvd)
4184 pglen = recvd;
4185 xdr_read_pages(xdr, pglen);
4186
4187 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07004188 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04004189 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004191
4192 /* Make sure the packet actually has a value_follows and EOF entry */
4193 if ((entry + 1) > end)
4194 goto short_pkt;
4195
4196 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004197 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04004198 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004200 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 p += 2; /* cookie */
4202 len = ntohl(*p++); /* filename length */
4203 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004204 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4205 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 goto err_unmap;
4207 }
David Howellse8896492006-08-24 15:44:19 -04004208 xlen = XDR_QUADLEN(len);
4209 if (end - p < xlen + 1)
4210 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004211 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04004212 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04004214 if (end - p < len + 1)
4215 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04004218 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04004220 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 entry = p;
4222 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004223 /*
4224 * Apparently some server sends responses that are a valid size, but
4225 * contain no entries, and have value_follows==0 and EOF==0. For
4226 * those, just set the EOF marker.
4227 */
4228 if (!nr && entry[1] == 0) {
4229 dprintk("NFS: readdir reply truncated!\n");
4230 entry[1] = 1;
4231 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05004232out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 kunmap_atomic(kaddr, KM_USER0);
4234 return 0;
4235short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004236 /*
4237 * When we get a short packet there are 2 possibilities. We can
4238 * return an error, or fix up the response to look like a valid
4239 * response and return what we have so far. If there are no
4240 * entries and the packet was short, then return -EIO. If there
4241 * are valid entries in the response, return them and pretend that
4242 * the call was successful, but incomplete. The caller can retry the
4243 * readdir starting at the last cookie.
4244 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07004245 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004247 if (nr)
4248 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249err_unmap:
4250 kunmap_atomic(kaddr, KM_USER0);
4251 return -errno_NFSERR_IO;
4252}
4253
4254static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4255{
4256 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4257 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004258 size_t hdrlen;
4259 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 char *kaddr;
4262 int status;
4263
4264 status = decode_op_hdr(xdr, OP_READLINK);
4265 if (status)
4266 return status;
4267
4268 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004269 p = xdr_inline_decode(xdr, 4);
4270 if (unlikely(!p))
4271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004272 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004274 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 return -ENAMETOOLONG;
4276 }
4277 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4278 recvd = req->rq_rcv_buf.len - hdrlen;
4279 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004280 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 "count %u > recvd %u\n", len, recvd);
4282 return -EIO;
4283 }
4284 xdr_read_pages(xdr, len);
4285 /*
4286 * The XDR encode routine has set things up so that
4287 * the link text will be copied directly into the
4288 * buffer. We just have to do overflow-checking,
4289 * and and null-terminate the text (the VFS expects
4290 * null-termination).
4291 */
4292 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4293 kaddr[len+rcvbuf->page_base] = '\0';
4294 kunmap_atomic(kaddr, KM_USER0);
4295 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004296out_overflow:
4297 print_overflow_msg(__func__, xdr);
4298 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299}
4300
4301static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4302{
4303 int status;
4304
4305 status = decode_op_hdr(xdr, OP_REMOVE);
4306 if (status)
4307 goto out;
4308 status = decode_change_info(xdr, cinfo);
4309out:
4310 return status;
4311}
4312
4313static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4314 struct nfs4_change_info *new_cinfo)
4315{
4316 int status;
4317
4318 status = decode_op_hdr(xdr, OP_RENAME);
4319 if (status)
4320 goto out;
4321 if ((status = decode_change_info(xdr, old_cinfo)))
4322 goto out;
4323 status = decode_change_info(xdr, new_cinfo);
4324out:
4325 return status;
4326}
4327
4328static int decode_renew(struct xdr_stream *xdr)
4329{
4330 return decode_op_hdr(xdr, OP_RENEW);
4331}
4332
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004333static int
4334decode_restorefh(struct xdr_stream *xdr)
4335{
4336 return decode_op_hdr(xdr, OP_RESTOREFH);
4337}
4338
J. Bruce Fields029d1052005-06-22 17:16:22 +00004339static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4340 size_t *acl_len)
4341{
Al Viro8687b632006-10-19 23:28:48 -07004342 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004343 uint32_t attrlen,
4344 bitmap[2] = {0};
4345 struct kvec *iov = req->rq_rcv_buf.head;
4346 int status;
4347
4348 *acl_len = 0;
4349 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4350 goto out;
4351 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4352 goto out;
4353 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4354 goto out;
4355
4356 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4357 return -EIO;
4358 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004359 size_t hdrlen;
4360 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004361
4362 /* We ignore &savep and don't do consistency checks on
4363 * the attr length. Let userspace figure it out.... */
4364 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4365 recvd = req->rq_rcv_buf.len - hdrlen;
4366 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004367 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004368 " acl reply: attrlen %u > recvd %u\n",
4369 attrlen, recvd);
4370 return -EINVAL;
4371 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004372 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004373 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004374 } else
4375 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004376
4377out:
4378 return status;
4379}
4380
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381static int
4382decode_savefh(struct xdr_stream *xdr)
4383{
4384 return decode_op_hdr(xdr, OP_SAVEFH);
4385}
4386
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004387static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388{
Al Viro8687b632006-10-19 23:28:48 -07004389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 uint32_t bmlen;
4391 int status;
4392
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 status = decode_op_hdr(xdr, OP_SETATTR);
4394 if (status)
4395 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004396 p = xdr_inline_decode(xdr, 4);
4397 if (unlikely(!p))
4398 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004399 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004400 p = xdr_inline_decode(xdr, bmlen << 2);
4401 if (likely(p))
4402 return 0;
4403out_overflow:
4404 print_overflow_msg(__func__, xdr);
4405 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406}
4407
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004408static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409{
Al Viro8687b632006-10-19 23:28:48 -07004410 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 uint32_t opnum;
4412 int32_t nfserr;
4413
Benny Halevyc0eae662009-08-14 17:20:14 +03004414 p = xdr_inline_decode(xdr, 8);
4415 if (unlikely(!p))
4416 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004417 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004419 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004420 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 return -EIO;
4422 }
Benny Halevycccddf42009-08-14 17:20:19 +03004423 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004425 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4426 if (unlikely(!p))
4427 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004428 p = xdr_decode_hyper(p, &res->clientid);
4429 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 } else if (nfserr == NFSERR_CLID_INUSE) {
4431 uint32_t len;
4432
4433 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004434 p = xdr_inline_decode(xdr, 4);
4435 if (unlikely(!p))
4436 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004437 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004438 p = xdr_inline_decode(xdr, len);
4439 if (unlikely(!p))
4440 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441
4442 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004443 p = xdr_inline_decode(xdr, 4);
4444 if (unlikely(!p))
4445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004446 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004447 p = xdr_inline_decode(xdr, len);
4448 if (unlikely(!p))
4449 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 return -NFSERR_CLID_INUSE;
4451 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004452 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453
4454 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004455out_overflow:
4456 print_overflow_msg(__func__, xdr);
4457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458}
4459
4460static int decode_setclientid_confirm(struct xdr_stream *xdr)
4461{
4462 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4463}
4464
4465static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4466{
Al Viro8687b632006-10-19 23:28:48 -07004467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 int status;
4469
4470 status = decode_op_hdr(xdr, OP_WRITE);
4471 if (status)
4472 return status;
4473
Benny Halevyc0eae662009-08-14 17:20:14 +03004474 p = xdr_inline_decode(xdr, 16);
4475 if (unlikely(!p))
4476 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004477 res->count = be32_to_cpup(p++);
4478 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004479 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004481out_overflow:
4482 print_overflow_msg(__func__, xdr);
4483 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484}
4485
4486static int decode_delegreturn(struct xdr_stream *xdr)
4487{
4488 return decode_op_hdr(xdr, OP_DELEGRETURN);
4489}
4490
Benny Halevy99fe60d2009-04-01 09:22:29 -04004491#if defined(CONFIG_NFS_V4_1)
4492static int decode_exchange_id(struct xdr_stream *xdr,
4493 struct nfs41_exchange_id_res *res)
4494{
4495 __be32 *p;
4496 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004497 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004498 int status;
4499 struct nfs_client *clp = res->client;
4500
4501 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4502 if (status)
4503 return status;
4504
Benny Halevyc0eae662009-08-14 17:20:14 +03004505 p = xdr_inline_decode(xdr, 8);
4506 if (unlikely(!p))
4507 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004508 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004509 p = xdr_inline_decode(xdr, 12);
4510 if (unlikely(!p))
4511 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004512 clp->cl_seqid = be32_to_cpup(p++);
4513 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004514
4515 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004516 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004517 if (dummy != SP4_NONE)
4518 return -EIO;
4519
4520 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004521 p = xdr_inline_decode(xdr, 8);
4522 if (unlikely(!p))
4523 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004524
4525 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004526 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4527 if (unlikely(status))
4528 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004529
4530 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004531 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4532 if (unlikely(status))
4533 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004534
4535 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004536 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4537 if (unlikely(status))
4538 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004539
4540 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004541out_overflow:
4542 print_overflow_msg(__func__, xdr);
4543 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004544}
Andy Adamsonfc931582009-04-01 09:22:31 -04004545
4546static int decode_chan_attrs(struct xdr_stream *xdr,
4547 struct nfs4_channel_attrs *attrs)
4548{
4549 __be32 *p;
4550 u32 nr_attrs;
4551
Benny Halevyc0eae662009-08-14 17:20:14 +03004552 p = xdr_inline_decode(xdr, 28);
4553 if (unlikely(!p))
4554 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004555 attrs->headerpadsz = be32_to_cpup(p++);
4556 attrs->max_rqst_sz = be32_to_cpup(p++);
4557 attrs->max_resp_sz = be32_to_cpup(p++);
4558 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4559 attrs->max_ops = be32_to_cpup(p++);
4560 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004561 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004562 if (unlikely(nr_attrs > 1)) {
4563 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4564 __func__, nr_attrs);
4565 return -EINVAL;
4566 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004567 if (nr_attrs == 1) {
4568 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4569 if (unlikely(!p))
4570 goto out_overflow;
4571 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004572 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004573out_overflow:
4574 print_overflow_msg(__func__, xdr);
4575 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004576}
4577
Benny Halevye78291e2009-08-14 17:20:00 +03004578static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4579{
4580 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004581}
4582
4583static int decode_create_session(struct xdr_stream *xdr,
4584 struct nfs41_create_session_res *res)
4585{
4586 __be32 *p;
4587 int status;
4588 struct nfs_client *clp = res->client;
4589 struct nfs4_session *session = clp->cl_session;
4590
4591 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004592 if (!status)
4593 status = decode_sessionid(xdr, &session->sess_id);
4594 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004595 return status;
4596
Andy Adamsonfc931582009-04-01 09:22:31 -04004597 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004598 p = xdr_inline_decode(xdr, 8);
4599 if (unlikely(!p))
4600 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004601 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004602 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004603
4604 /* Channel attributes */
4605 status = decode_chan_attrs(xdr, &session->fc_attrs);
4606 if (!status)
4607 status = decode_chan_attrs(xdr, &session->bc_attrs);
4608 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004609out_overflow:
4610 print_overflow_msg(__func__, xdr);
4611 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004612}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004613
4614static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4615{
4616 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4617}
Ricardo Labiaga18019752009-12-05 16:08:40 -05004618
4619static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4620{
4621 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4622}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004623#endif /* CONFIG_NFS_V4_1 */
4624
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004625static int decode_sequence(struct xdr_stream *xdr,
4626 struct nfs4_sequence_res *res,
4627 struct rpc_rqst *rqstp)
4628{
4629#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004630 struct nfs4_slot *slot;
4631 struct nfs4_sessionid id;
4632 u32 dummy;
4633 int status;
4634 __be32 *p;
4635
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004636 if (!res->sr_session)
4637 return 0;
4638
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004639 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004640 if (!status)
4641 status = decode_sessionid(xdr, &id);
4642 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004643 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004644
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004645 /*
4646 * If the server returns different values for sessionID, slotID or
4647 * sequence number, the server is looney tunes.
4648 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004649 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004650
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004651 if (memcmp(id.data, res->sr_session->sess_id.data,
4652 NFS4_MAX_SESSIONID_LEN)) {
4653 dprintk("%s Invalid session id\n", __func__);
4654 goto out_err;
4655 }
Benny Halevye78291e2009-08-14 17:20:00 +03004656
Benny Halevyc0eae662009-08-14 17:20:14 +03004657 p = xdr_inline_decode(xdr, 20);
4658 if (unlikely(!p))
4659 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004660
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004661 /* seqid */
Benny Halevye78291e2009-08-14 17:20:00 +03004662 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
Benny Halevy6f723f72009-08-14 17:19:37 +03004663 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004664 if (dummy != slot->seq_nr) {
4665 dprintk("%s Invalid sequence number\n", __func__);
4666 goto out_err;
4667 }
4668 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004669 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004670 if (dummy != res->sr_slotid) {
4671 dprintk("%s Invalid slot id\n", __func__);
4672 goto out_err;
4673 }
4674 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004675 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004676 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004677 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004678 /* result flags */
4679 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004680 status = 0;
4681out_err:
4682 res->sr_status = status;
4683 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004684out_overflow:
4685 print_overflow_msg(__func__, xdr);
4686 status = -EIO;
4687 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004688#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004689 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004690#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004691}
4692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693/*
Benny Halevy49c25592008-12-23 16:06:16 -05004694 * END OF "GENERIC" DECODE ROUTINES.
4695 */
4696
4697/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 * Decode OPEN_DOWNGRADE response
4699 */
Al Viro8687b632006-10-19 23:28:48 -07004700static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701{
Andy Adamson05d564f2008-12-23 16:06:15 -05004702 struct xdr_stream xdr;
4703 struct compound_hdr hdr;
4704 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Andy Adamson05d564f2008-12-23 16:06:15 -05004706 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4707 status = decode_compound_hdr(&xdr, &hdr);
4708 if (status)
4709 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004710 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4711 if (status)
4712 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004713 status = decode_putfh(&xdr);
4714 if (status)
4715 goto out;
4716 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004717 if (status != 0)
4718 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004719 decode_getfattr(&xdr, res->fattr, res->server,
4720 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004722 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723}
4724
4725/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 * Decode ACCESS response
4727 */
Al Viro8687b632006-10-19 23:28:48 -07004728static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729{
4730 struct xdr_stream xdr;
4731 struct compound_hdr hdr;
4732 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004733
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004735 status = decode_compound_hdr(&xdr, &hdr);
4736 if (status)
4737 goto out;
4738 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4739 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004741 status = decode_putfh(&xdr);
4742 if (status != 0)
4743 goto out;
4744 status = decode_access(&xdr, res);
4745 if (status != 0)
4746 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004747 decode_getfattr(&xdr, res->fattr, res->server,
4748 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749out:
4750 return status;
4751}
4752
4753/*
4754 * Decode LOOKUP response
4755 */
Al Viro8687b632006-10-19 23:28:48 -07004756static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757{
4758 struct xdr_stream xdr;
4759 struct compound_hdr hdr;
4760 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004761
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004763 status = decode_compound_hdr(&xdr, &hdr);
4764 if (status)
4765 goto out;
4766 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4767 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 goto out;
4769 if ((status = decode_putfh(&xdr)) != 0)
4770 goto out;
4771 if ((status = decode_lookup(&xdr)) != 0)
4772 goto out;
4773 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4774 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004775 status = decode_getfattr(&xdr, res->fattr, res->server
4776 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777out:
4778 return status;
4779}
4780
4781/*
4782 * Decode LOOKUP_ROOT response
4783 */
Al Viro8687b632006-10-19 23:28:48 -07004784static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785{
4786 struct xdr_stream xdr;
4787 struct compound_hdr hdr;
4788 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004789
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004791 status = decode_compound_hdr(&xdr, &hdr);
4792 if (status)
4793 goto out;
4794 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4795 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796 goto out;
4797 if ((status = decode_putrootfh(&xdr)) != 0)
4798 goto out;
4799 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004800 status = decode_getfattr(&xdr, res->fattr, res->server,
4801 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802out:
4803 return status;
4804}
4805
4806/*
4807 * Decode REMOVE response
4808 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004809static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810{
4811 struct xdr_stream xdr;
4812 struct compound_hdr hdr;
4813 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004814
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004816 status = decode_compound_hdr(&xdr, &hdr);
4817 if (status)
4818 goto out;
4819 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4820 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004822 if ((status = decode_putfh(&xdr)) != 0)
4823 goto out;
4824 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4825 goto out;
Trond Myklebustd3468902010-04-16 16:22:50 -04004826 decode_getfattr(&xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004827 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828out:
4829 return status;
4830}
4831
4832/*
4833 * Decode RENAME response
4834 */
Al Viro8687b632006-10-19 23:28:48 -07004835static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836{
4837 struct xdr_stream xdr;
4838 struct compound_hdr hdr;
4839 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004840
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004842 status = decode_compound_hdr(&xdr, &hdr);
4843 if (status)
4844 goto out;
4845 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4846 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 goto out;
4848 if ((status = decode_putfh(&xdr)) != 0)
4849 goto out;
4850 if ((status = decode_savefh(&xdr)) != 0)
4851 goto out;
4852 if ((status = decode_putfh(&xdr)) != 0)
4853 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004854 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4855 goto out;
4856 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004857 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4858 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004859 goto out;
4860 if ((status = decode_restorefh(&xdr)) != 0)
4861 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004862 decode_getfattr(&xdr, res->old_fattr, res->server,
4863 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864out:
4865 return status;
4866}
4867
4868/*
4869 * Decode LINK response
4870 */
Al Viro8687b632006-10-19 23:28:48 -07004871static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872{
4873 struct xdr_stream xdr;
4874 struct compound_hdr hdr;
4875 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004876
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004878 status = decode_compound_hdr(&xdr, &hdr);
4879 if (status)
4880 goto out;
4881 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4882 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 goto out;
4884 if ((status = decode_putfh(&xdr)) != 0)
4885 goto out;
4886 if ((status = decode_savefh(&xdr)) != 0)
4887 goto out;
4888 if ((status = decode_putfh(&xdr)) != 0)
4889 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004890 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4891 goto out;
4892 /*
4893 * Note order: OP_LINK leaves the directory as the current
4894 * filehandle.
4895 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004896 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4897 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004898 goto out;
4899 if ((status = decode_restorefh(&xdr)) != 0)
4900 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004901 decode_getfattr(&xdr, res->fattr, res->server,
4902 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903out:
4904 return status;
4905}
4906
4907/*
4908 * Decode CREATE response
4909 */
Al Viro8687b632006-10-19 23:28:48 -07004910static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911{
4912 struct xdr_stream xdr;
4913 struct compound_hdr hdr;
4914 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004915
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004917 status = decode_compound_hdr(&xdr, &hdr);
4918 if (status)
4919 goto out;
4920 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4921 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 goto out;
4923 if ((status = decode_putfh(&xdr)) != 0)
4924 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004925 if ((status = decode_savefh(&xdr)) != 0)
4926 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4928 goto out;
4929 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4930 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004931 if (decode_getfattr(&xdr, res->fattr, res->server,
4932 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004933 goto out;
4934 if ((status = decode_restorefh(&xdr)) != 0)
4935 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004936 decode_getfattr(&xdr, res->dir_fattr, res->server,
4937 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938out:
4939 return status;
4940}
4941
4942/*
4943 * Decode SYMLINK response
4944 */
Al Viro8687b632006-10-19 23:28:48 -07004945static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946{
4947 return nfs4_xdr_dec_create(rqstp, p, res);
4948}
4949
4950/*
4951 * Decode GETATTR response
4952 */
Al Viro8687b632006-10-19 23:28:48 -07004953static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954{
4955 struct xdr_stream xdr;
4956 struct compound_hdr hdr;
4957 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004958
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4960 status = decode_compound_hdr(&xdr, &hdr);
4961 if (status)
4962 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004963 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4964 if (status)
4965 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 status = decode_putfh(&xdr);
4967 if (status)
4968 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004969 status = decode_getfattr(&xdr, res->fattr, res->server,
4970 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971out:
4972 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973}
4974
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004975/*
4976 * Encode an SETACL request
4977 */
4978static int
Al Viro8687b632006-10-19 23:28:48 -07004979nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004980{
Andy Adamson05d564f2008-12-23 16:06:15 -05004981 struct xdr_stream xdr;
4982 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004983 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004984 };
4985 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004986
Andy Adamson05d564f2008-12-23 16:06:15 -05004987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004988 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004989 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004990 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004991 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004992 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004993 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004994}
Andy Adamson05d564f2008-12-23 16:06:15 -05004995
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004996/*
4997 * Decode SETACL response
4998 */
4999static int
Benny Halevy73c403a2009-04-01 09:22:01 -04005000nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
5001 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005002{
5003 struct xdr_stream xdr;
5004 struct compound_hdr hdr;
5005 int status;
5006
5007 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5008 status = decode_compound_hdr(&xdr, &hdr);
5009 if (status)
5010 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005011 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5012 if (status)
5013 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005014 status = decode_putfh(&xdr);
5015 if (status)
5016 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005017 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005018out:
5019 return status;
5020}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021
5022/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005023 * Decode GETACL response
5024 */
5025static int
Benny Halevy663c79b2009-04-01 09:21:59 -04005026nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
5027 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005028{
5029 struct xdr_stream xdr;
5030 struct compound_hdr hdr;
5031 int status;
5032
5033 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5034 status = decode_compound_hdr(&xdr, &hdr);
5035 if (status)
5036 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005037 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5038 if (status)
5039 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005040 status = decode_putfh(&xdr);
5041 if (status)
5042 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04005043 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005044
5045out:
5046 return status;
5047}
5048
5049/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 * Decode CLOSE response
5051 */
Al Viro8687b632006-10-19 23:28:48 -07005052static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053{
Andy Adamson05d564f2008-12-23 16:06:15 -05005054 struct xdr_stream xdr;
5055 struct compound_hdr hdr;
5056 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057
Andy Adamson05d564f2008-12-23 16:06:15 -05005058 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5059 status = decode_compound_hdr(&xdr, &hdr);
5060 if (status)
5061 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005062 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5063 if (status)
5064 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005065 status = decode_putfh(&xdr);
5066 if (status)
5067 goto out;
5068 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005069 if (status != 0)
5070 goto out;
5071 /*
5072 * Note: Server may do delete on close for this file
5073 * in which case the getattr call will fail with
5074 * an ESTALE error. Shouldn't be a problem,
5075 * though, since fattr->valid will remain unset.
5076 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005077 decode_getfattr(&xdr, res->fattr, res->server,
5078 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005080 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081}
5082
5083/*
5084 * Decode OPEN response
5085 */
Al Viro8687b632006-10-19 23:28:48 -07005086static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087{
Andy Adamson05d564f2008-12-23 16:06:15 -05005088 struct xdr_stream xdr;
5089 struct compound_hdr hdr;
5090 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091
Andy Adamson05d564f2008-12-23 16:06:15 -05005092 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5093 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005094 if (status)
5095 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005096 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5097 if (status)
5098 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005099 status = decode_putfh(&xdr);
5100 if (status)
5101 goto out;
5102 status = decode_savefh(&xdr);
5103 if (status)
5104 goto out;
5105 status = decode_open(&xdr, res);
5106 if (status)
5107 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005108 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005110 if (decode_getfattr(&xdr, res->f_attr, res->server,
5111 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005112 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005113 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005114 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005115 decode_getfattr(&xdr, res->dir_attr, res->server,
5116 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005118 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119}
5120
5121/*
5122 * Decode OPEN_CONFIRM response
5123 */
Al Viro8687b632006-10-19 23:28:48 -07005124static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125{
Andy Adamson05d564f2008-12-23 16:06:15 -05005126 struct xdr_stream xdr;
5127 struct compound_hdr hdr;
5128 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129
Andy Adamson05d564f2008-12-23 16:06:15 -05005130 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5131 status = decode_compound_hdr(&xdr, &hdr);
5132 if (status)
5133 goto out;
5134 status = decode_putfh(&xdr);
5135 if (status)
5136 goto out;
5137 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005139 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140}
5141
5142/*
5143 * Decode OPEN response
5144 */
Al Viro8687b632006-10-19 23:28:48 -07005145static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146{
Andy Adamson05d564f2008-12-23 16:06:15 -05005147 struct xdr_stream xdr;
5148 struct compound_hdr hdr;
5149 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150
Andy Adamson05d564f2008-12-23 16:06:15 -05005151 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5152 status = decode_compound_hdr(&xdr, &hdr);
5153 if (status)
5154 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005155 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5156 if (status)
5157 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005158 status = decode_putfh(&xdr);
5159 if (status)
5160 goto out;
5161 status = decode_open(&xdr, res);
5162 if (status)
5163 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005164 decode_getfattr(&xdr, res->f_attr, res->server,
5165 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005167 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168}
5169
5170/*
5171 * Decode SETATTR response
5172 */
Al Viro8687b632006-10-19 23:28:48 -07005173static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174{
Andy Adamson05d564f2008-12-23 16:06:15 -05005175 struct xdr_stream xdr;
5176 struct compound_hdr hdr;
5177 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178
Andy Adamson05d564f2008-12-23 16:06:15 -05005179 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5180 status = decode_compound_hdr(&xdr, &hdr);
5181 if (status)
5182 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005183 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5184 if (status)
5185 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005186 status = decode_putfh(&xdr);
5187 if (status)
5188 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005189 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005190 if (status)
5191 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005192 decode_getfattr(&xdr, res->fattr, res->server,
5193 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005195 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196}
5197
5198/*
5199 * Decode LOCK response
5200 */
Al Viro8687b632006-10-19 23:28:48 -07005201static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202{
5203 struct xdr_stream xdr;
5204 struct compound_hdr hdr;
5205 int status;
5206
5207 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5208 status = decode_compound_hdr(&xdr, &hdr);
5209 if (status)
5210 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005211 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5212 if (status)
5213 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 status = decode_putfh(&xdr);
5215 if (status)
5216 goto out;
5217 status = decode_lock(&xdr, res);
5218out:
5219 return status;
5220}
5221
5222/*
5223 * Decode LOCKT response
5224 */
Al Viro8687b632006-10-19 23:28:48 -07005225static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226{
5227 struct xdr_stream xdr;
5228 struct compound_hdr hdr;
5229 int status;
5230
5231 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5232 status = decode_compound_hdr(&xdr, &hdr);
5233 if (status)
5234 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005235 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5236 if (status)
5237 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 status = decode_putfh(&xdr);
5239 if (status)
5240 goto out;
5241 status = decode_lockt(&xdr, res);
5242out:
5243 return status;
5244}
5245
5246/*
5247 * Decode LOCKU response
5248 */
Al Viro8687b632006-10-19 23:28:48 -07005249static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250{
5251 struct xdr_stream xdr;
5252 struct compound_hdr hdr;
5253 int status;
5254
5255 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5256 status = decode_compound_hdr(&xdr, &hdr);
5257 if (status)
5258 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005259 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5260 if (status)
5261 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 status = decode_putfh(&xdr);
5263 if (status)
5264 goto out;
5265 status = decode_locku(&xdr, res);
5266out:
5267 return status;
5268}
5269
5270/*
5271 * Decode READLINK response
5272 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005273static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5274 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275{
5276 struct xdr_stream xdr;
5277 struct compound_hdr hdr;
5278 int status;
5279
5280 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5281 status = decode_compound_hdr(&xdr, &hdr);
5282 if (status)
5283 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005284 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5285 if (status)
5286 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287 status = decode_putfh(&xdr);
5288 if (status)
5289 goto out;
5290 status = decode_readlink(&xdr, rqstp);
5291out:
5292 return status;
5293}
5294
5295/*
5296 * Decode READDIR response
5297 */
Al Viro8687b632006-10-19 23:28:48 -07005298static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299{
5300 struct xdr_stream xdr;
5301 struct compound_hdr hdr;
5302 int status;
5303
5304 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5305 status = decode_compound_hdr(&xdr, &hdr);
5306 if (status)
5307 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005308 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5309 if (status)
5310 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 status = decode_putfh(&xdr);
5312 if (status)
5313 goto out;
5314 status = decode_readdir(&xdr, rqstp, res);
5315out:
5316 return status;
5317}
5318
5319/*
5320 * Decode Read response
5321 */
Al Viro8687b632006-10-19 23:28:48 -07005322static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323{
5324 struct xdr_stream xdr;
5325 struct compound_hdr hdr;
5326 int status;
5327
5328 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5329 status = decode_compound_hdr(&xdr, &hdr);
5330 if (status)
5331 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005332 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5333 if (status)
5334 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335 status = decode_putfh(&xdr);
5336 if (status)
5337 goto out;
5338 status = decode_read(&xdr, rqstp, res);
5339 if (!status)
5340 status = res->count;
5341out:
5342 return status;
5343}
5344
5345/*
5346 * Decode WRITE response
5347 */
Al Viro8687b632006-10-19 23:28:48 -07005348static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349{
5350 struct xdr_stream xdr;
5351 struct compound_hdr hdr;
5352 int status;
5353
5354 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5355 status = decode_compound_hdr(&xdr, &hdr);
5356 if (status)
5357 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005358 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5359 if (status)
5360 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 status = decode_putfh(&xdr);
5362 if (status)
5363 goto out;
5364 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005365 if (status)
5366 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005367 decode_getfattr(&xdr, res->fattr, res->server,
5368 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369 if (!status)
5370 status = res->count;
5371out:
5372 return status;
5373}
5374
5375/*
5376 * Decode COMMIT response
5377 */
Al Viro8687b632006-10-19 23:28:48 -07005378static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379{
5380 struct xdr_stream xdr;
5381 struct compound_hdr hdr;
5382 int status;
5383
5384 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5385 status = decode_compound_hdr(&xdr, &hdr);
5386 if (status)
5387 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005388 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5389 if (status)
5390 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 status = decode_putfh(&xdr);
5392 if (status)
5393 goto out;
5394 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005395 if (status)
5396 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005397 decode_getfattr(&xdr, res->fattr, res->server,
5398 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399out:
5400 return status;
5401}
5402
5403/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005404 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005406static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5407 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408{
5409 struct xdr_stream xdr;
5410 struct compound_hdr hdr;
5411 int status;
5412
5413 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5414 status = decode_compound_hdr(&xdr, &hdr);
5415 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005416 status = decode_sequence(&xdr, &res->seq_res, req);
5417 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418 status = decode_putfh(&xdr);
5419 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005420 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421 return status;
5422}
5423
5424/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005425 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005427static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5428 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005429{
5430 struct xdr_stream xdr;
5431 struct compound_hdr hdr;
5432 int status;
5433
5434 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5435 status = decode_compound_hdr(&xdr, &hdr);
5436 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005437 status = decode_sequence(&xdr, &res->seq_res, req);
5438 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439 status = decode_putfh(&xdr);
5440 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005441 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442 return status;
5443}
5444
5445/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005446 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005448static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5449 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450{
5451 struct xdr_stream xdr;
5452 struct compound_hdr hdr;
5453 int status;
5454
5455 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5456 status = decode_compound_hdr(&xdr, &hdr);
5457 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005458 status = decode_sequence(&xdr, &res->seq_res, req);
5459 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 status = decode_putfh(&xdr);
5461 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005462 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463 return status;
5464}
5465
5466/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005467 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468 */
Al Viro8687b632006-10-19 23:28:48 -07005469static 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 -07005470{
5471 struct xdr_stream xdr;
5472 struct compound_hdr hdr;
5473 int status;
5474
5475 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005476 status = decode_compound_hdr(&xdr, &hdr);
5477 if (status)
5478 goto out;
5479 status = decode_sequence(&xdr, &res->seq_res, req);
5480 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481 goto out;
5482 if ((status = decode_putfh(&xdr)) != 0)
5483 goto out;
5484 status = decode_server_caps(&xdr, res);
5485out:
5486 return status;
5487}
5488
5489/*
5490 * Decode RENEW response
5491 */
Al Viro8687b632006-10-19 23:28:48 -07005492static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493{
5494 struct xdr_stream xdr;
5495 struct compound_hdr hdr;
5496 int status;
5497
5498 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5499 status = decode_compound_hdr(&xdr, &hdr);
5500 if (!status)
5501 status = decode_renew(&xdr);
5502 return status;
5503}
5504
5505/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005506 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507 */
Al Viro8687b632006-10-19 23:28:48 -07005508static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005509 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510{
5511 struct xdr_stream xdr;
5512 struct compound_hdr hdr;
5513 int status;
5514
5515 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5516 status = decode_compound_hdr(&xdr, &hdr);
5517 if (!status)
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005518 status = decode_setclientid(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519 return status;
5520}
5521
5522/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005523 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 */
Al Viro8687b632006-10-19 23:28:48 -07005525static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526{
5527 struct xdr_stream xdr;
5528 struct compound_hdr hdr;
5529 int status;
5530
5531 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5532 status = decode_compound_hdr(&xdr, &hdr);
5533 if (!status)
5534 status = decode_setclientid_confirm(&xdr);
5535 if (!status)
5536 status = decode_putrootfh(&xdr);
5537 if (!status)
5538 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005539 return status;
5540}
5541
5542/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005543 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544 */
Al Viro8687b632006-10-19 23:28:48 -07005545static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546{
5547 struct xdr_stream xdr;
5548 struct compound_hdr hdr;
5549 int status;
5550
5551 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5552 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005553 if (status)
5554 goto out;
5555 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5556 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005557 goto out;
5558 status = decode_putfh(&xdr);
5559 if (status != 0)
5560 goto out;
5561 status = decode_delegreturn(&xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005562 if (status != 0)
5563 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005564 decode_getfattr(&xdr, res->fattr, res->server,
5565 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005566out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 return status;
5568}
5569
Trond Myklebust683b57b2006-06-09 09:34:22 -04005570/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005571 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005572 */
Benny Halevy22958462009-04-01 09:22:02 -04005573static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5574 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005575{
5576 struct xdr_stream xdr;
5577 struct compound_hdr hdr;
5578 int status;
5579
5580 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5581 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005582 if (status)
5583 goto out;
5584 status = decode_sequence(&xdr, &res->seq_res, req);
5585 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005586 goto out;
5587 if ((status = decode_putfh(&xdr)) != 0)
5588 goto out;
5589 if ((status = decode_lookup(&xdr)) != 0)
5590 goto out;
5591 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005592 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005593 res->fs_locations->server,
5594 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005595out:
5596 return status;
5597}
5598
Benny Halevy99fe60d2009-04-01 09:22:29 -04005599#if defined(CONFIG_NFS_V4_1)
5600/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005601 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005602 */
5603static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5604 void *res)
5605{
5606 struct xdr_stream xdr;
5607 struct compound_hdr hdr;
5608 int status;
5609
5610 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5611 status = decode_compound_hdr(&xdr, &hdr);
5612 if (!status)
5613 status = decode_exchange_id(&xdr, res);
5614 return status;
5615}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005616
5617/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005618 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005619 */
5620static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5621 struct nfs41_create_session_res *res)
5622{
5623 struct xdr_stream xdr;
5624 struct compound_hdr hdr;
5625 int status;
5626
5627 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5628 status = decode_compound_hdr(&xdr, &hdr);
5629 if (!status)
5630 status = decode_create_session(&xdr, res);
5631 return status;
5632}
5633
5634/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005635 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005636 */
5637static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5638 void *dummy)
5639{
5640 struct xdr_stream xdr;
5641 struct compound_hdr hdr;
5642 int status;
5643
5644 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5645 status = decode_compound_hdr(&xdr, &hdr);
5646 if (!status)
5647 status = decode_destroy_session(&xdr, dummy);
5648 return status;
5649}
5650
5651/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005652 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005653 */
5654static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5655 struct nfs4_sequence_res *res)
5656{
5657 struct xdr_stream xdr;
5658 struct compound_hdr hdr;
5659 int status;
5660
5661 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5662 status = decode_compound_hdr(&xdr, &hdr);
5663 if (!status)
5664 status = decode_sequence(&xdr, res, rqstp);
5665 return status;
5666}
5667
5668/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005669 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005670 */
5671static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5672 struct nfs4_get_lease_time_res *res)
5673{
5674 struct xdr_stream xdr;
5675 struct compound_hdr hdr;
5676 int status;
5677
5678 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5679 status = decode_compound_hdr(&xdr, &hdr);
5680 if (!status)
5681 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5682 if (!status)
5683 status = decode_putrootfh(&xdr);
5684 if (!status)
5685 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5686 return status;
5687}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005688
5689/*
5690 * Decode RECLAIM_COMPLETE response
5691 */
5692static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p,
5693 struct nfs41_reclaim_complete_res *res)
5694{
5695 struct xdr_stream xdr;
5696 struct compound_hdr hdr;
5697 int status;
5698
5699 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5700 status = decode_compound_hdr(&xdr, &hdr);
5701 if (!status)
5702 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5703 if (!status)
5704 status = decode_reclaim_complete(&xdr, (void *)NULL);
5705 return status;
5706}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005707#endif /* CONFIG_NFS_V4_1 */
5708
Al Viro0dbb4c62006-10-19 23:28:49 -07005709__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005710{
5711 uint32_t bitmap[2] = {0};
5712 uint32_t len;
5713
5714 if (!*p++) {
5715 if (!*p)
5716 return ERR_PTR(-EAGAIN);
5717 entry->eof = 1;
5718 return ERR_PTR(-EBADCOOKIE);
5719 }
5720
5721 entry->prev_cookie = entry->cookie;
5722 p = xdr_decode_hyper(p, &entry->cookie);
5723 entry->len = ntohl(*p++);
5724 entry->name = (const char *) p;
5725 p += XDR_QUADLEN(entry->len);
5726
5727 /*
5728 * In case the server doesn't return an inode number,
5729 * we fake one here. (We don't use inode number 0,
5730 * since glibc seems to choke on it...)
5731 */
5732 entry->ino = 1;
5733
5734 len = ntohl(*p++); /* bitmap length */
5735 if (len-- > 0) {
5736 bitmap[0] = ntohl(*p++);
5737 if (len-- > 0) {
5738 bitmap[1] = ntohl(*p++);
5739 p += len;
5740 }
5741 }
5742 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5743 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005744 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5745 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5746 /* Ignore the return value of rdattr_error for now */
5747 p++;
5748 len--;
5749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5751 xdr_decode_hyper(p, &entry->ino);
5752 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5753 xdr_decode_hyper(p, &entry->ino);
5754 p += len;
5755 }
5756
5757 entry->eof = !p[0] && p[1];
5758 return p;
5759}
5760
5761/*
5762 * We need to translate between nfs status return values and
5763 * the local errno values which may not be the same.
5764 */
5765static struct {
5766 int stat;
5767 int errno;
5768} nfs_errtbl[] = {
5769 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005770 { NFS4ERR_PERM, -EPERM },
5771 { NFS4ERR_NOENT, -ENOENT },
5772 { NFS4ERR_IO, -errno_NFSERR_IO},
5773 { NFS4ERR_NXIO, -ENXIO },
5774 { NFS4ERR_ACCESS, -EACCES },
5775 { NFS4ERR_EXIST, -EEXIST },
5776 { NFS4ERR_XDEV, -EXDEV },
5777 { NFS4ERR_NOTDIR, -ENOTDIR },
5778 { NFS4ERR_ISDIR, -EISDIR },
5779 { NFS4ERR_INVAL, -EINVAL },
5780 { NFS4ERR_FBIG, -EFBIG },
5781 { NFS4ERR_NOSPC, -ENOSPC },
5782 { NFS4ERR_ROFS, -EROFS },
5783 { NFS4ERR_MLINK, -EMLINK },
5784 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5785 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5786 { NFS4ERR_DQUOT, -EDQUOT },
5787 { NFS4ERR_STALE, -ESTALE },
5788 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5789 { NFS4ERR_BADOWNER, -EINVAL },
5790 { NFS4ERR_BADNAME, -EINVAL },
5791 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5792 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5793 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005794 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03005795 { NFS4ERR_BADTYPE, -EBADTYPE },
5796 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005797 { NFS4ERR_SYMLINK, -ELOOP },
5798 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5799 { NFS4ERR_DEADLOCK, -EDEADLK },
5800 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801 * to be handled by a
5802 * middle-layer.
5803 */
Benny Halevy856dff32008-03-31 17:39:06 +03005804 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805};
5806
5807/*
5808 * Convert an NFS error code to a local one.
5809 * This one is used jointly by NFSv2 and NFSv3.
5810 */
5811static int
David Howells0a8ea432006-08-22 20:06:08 -04005812nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813{
5814 int i;
5815 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5816 if (nfs_errtbl[i].stat == stat)
5817 return nfs_errtbl[i].errno;
5818 }
5819 if (stat <= 10000 || stat > 10100) {
5820 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005821 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 }
5823 /* If we cannot translate the error, the recovery routines should
5824 * handle it.
5825 * Note: remaining NFSv4 error codes have values > 10000, so should
5826 * not conflict with native Linux error codes.
5827 */
Benny Halevy856dff32008-03-31 17:39:06 +03005828 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829}
5830
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831#define PROC(proc, argtype, restype) \
5832[NFSPROC4_CLNT_##proc] = { \
5833 .p_proc = NFSPROC4_COMPOUND, \
5834 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5835 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005836 .p_arglen = NFS4_##argtype##_sz, \
5837 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005838 .p_statidx = NFSPROC4_CLNT_##proc, \
5839 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005840}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841
5842struct rpc_procinfo nfs4_procedures[] = {
5843 PROC(READ, enc_read, dec_read),
5844 PROC(WRITE, enc_write, dec_write),
5845 PROC(COMMIT, enc_commit, dec_commit),
5846 PROC(OPEN, enc_open, dec_open),
5847 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5848 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5849 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5850 PROC(CLOSE, enc_close, dec_close),
5851 PROC(SETATTR, enc_setattr, dec_setattr),
5852 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5853 PROC(RENEW, enc_renew, dec_renew),
5854 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5855 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5856 PROC(LOCK, enc_lock, dec_lock),
5857 PROC(LOCKT, enc_lockt, dec_lockt),
5858 PROC(LOCKU, enc_locku, dec_locku),
5859 PROC(ACCESS, enc_access, dec_access),
5860 PROC(GETATTR, enc_getattr, dec_getattr),
5861 PROC(LOOKUP, enc_lookup, dec_lookup),
5862 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5863 PROC(REMOVE, enc_remove, dec_remove),
5864 PROC(RENAME, enc_rename, dec_rename),
5865 PROC(LINK, enc_link, dec_link),
5866 PROC(SYMLINK, enc_symlink, dec_symlink),
5867 PROC(CREATE, enc_create, dec_create),
5868 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5869 PROC(STATFS, enc_statfs, dec_statfs),
5870 PROC(READLINK, enc_readlink, dec_readlink),
5871 PROC(READDIR, enc_readdir, dec_readdir),
5872 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5873 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005874 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005875 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005876 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005877#if defined(CONFIG_NFS_V4_1)
5878 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005879 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005880 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005881 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005882 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Ricardo Labiaga18019752009-12-05 16:08:40 -05005883 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005884#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885};
5886
5887struct rpc_version nfs_version4 = {
5888 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005889 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 .procs = nfs4_procedures
5891};
5892
5893/*
5894 * Local variables:
5895 * c-basic-offset: 8
5896 * End:
5897 */