blob: 009aef9e12bc3d5a5cef83b659da8f67251983b0 [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"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040055#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define NFSDBG_FACILITY NFSDBG_XDR
58
59/* Mapping from NFS error code to "errno" error code. */
60#define errno_NFSERR_IO EIO
61
David Howells0a8ea432006-08-22 20:06:08 -040062static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65#ifdef DEBUG
66#define NFS4_MAXTAGLEN 20
67#else
68#define NFS4_MAXTAGLEN 0
69#endif
70
Andy Adamson6c0195a2008-12-23 16:06:15 -050071/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040072 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
Trond Myklebustd035c362010-12-21 10:45:27 -050074#define open_owner_id_maxsz (1 + 1 + 4)
75#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040076#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define op_encode_hdr_maxsz (1)
80#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 (NFS4_FHSIZE >> 2))
87#define decode_putfh_maxsz (op_decode_hdr_maxsz)
88#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
89#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
90#define encode_getfh_maxsz (op_encode_hdr_maxsz)
91#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
92 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000093#define nfs4_fattr_bitmap_maxsz 3
94#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
96#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040097#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000099/* This is based on getfattr, which uses the most attributes: */
100#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400101 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
103 nfs4_fattr_value_maxsz)
104#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400105#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
106 1 + 2 + 1 + \
107 nfs4_owner_maxsz + \
108 nfs4_group_maxsz + \
109 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define encode_savefh_maxsz (op_encode_hdr_maxsz)
111#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400112#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
113#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200114#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
116#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
117#define decode_renew_maxsz (op_decode_hdr_maxsz)
118#define encode_setclientid_maxsz \
119 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500120 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
121 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 1 /* sc_prog */ + \
123 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
124 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define decode_setclientid_maxsz \
127 (op_decode_hdr_maxsz + \
128 2 + \
129 1024) /* large value for CLID_INUSE */
130#define encode_setclientid_confirm_maxsz \
131 (op_encode_hdr_maxsz + \
132 3 + (NFS4_VERIFIER_SIZE >> 2))
133#define decode_setclientid_confirm_maxsz \
134 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400135#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
136#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400137#define encode_share_access_maxsz \
138 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500139#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400140#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
141#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
142#define encode_open_maxsz (op_encode_hdr_maxsz + \
143 2 + encode_share_access_maxsz + 2 + \
144 open_owner_id_maxsz + \
145 encode_opentype_maxsz + \
146 encode_claim_null_maxsz)
147#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400148#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149 decode_ace_maxsz)
150#define decode_change_info_maxsz (5)
151#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400152 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153 decode_change_info_maxsz + 1 + \
154 nfs4_fattr_bitmap_maxsz + \
155 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400156#define encode_open_confirm_maxsz \
157 (op_encode_hdr_maxsz + \
158 encode_stateid_maxsz + 1)
159#define decode_open_confirm_maxsz \
160 (op_decode_hdr_maxsz + \
161 decode_stateid_maxsz)
162#define encode_open_downgrade_maxsz \
163 (op_encode_hdr_maxsz + \
164 encode_stateid_maxsz + 1 + \
165 encode_share_access_maxsz)
166#define decode_open_downgrade_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_close_maxsz (op_encode_hdr_maxsz + \
170 1 + encode_stateid_maxsz)
171#define decode_close_maxsz (op_decode_hdr_maxsz + \
172 decode_stateid_maxsz)
173#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
174 encode_stateid_maxsz + \
175 encode_attrs_maxsz)
176#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
177 nfs4_fattr_bitmap_maxsz)
178#define encode_read_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 3)
180#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
181#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
182 2 + encode_verifier_maxsz + 5)
183#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
184 decode_verifier_maxsz)
185#define encode_readlink_maxsz (op_encode_hdr_maxsz)
186#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
187#define encode_write_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 4)
189#define decode_write_maxsz (op_decode_hdr_maxsz + \
190 2 + decode_verifier_maxsz)
191#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
192#define decode_commit_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400196#define decode_remove_maxsz (op_decode_hdr_maxsz + \
197 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400200#define decode_rename_maxsz (op_decode_hdr_maxsz + \
201 decode_change_info_maxsz + \
202 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define encode_link_maxsz (op_encode_hdr_maxsz + \
204 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400205#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400206#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define encode_lock_maxsz (op_encode_hdr_maxsz + \
208 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400209 1 + encode_stateid_maxsz + 1 + \
210 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400211#define decode_lock_denied_maxsz \
212 (8 + decode_lockowner_maxsz)
213#define decode_lock_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400215#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
216 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400217#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
218 decode_lock_denied_maxsz)
219#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
220 encode_stateid_maxsz + \
221 4)
222#define decode_locku_maxsz (op_decode_hdr_maxsz + \
223 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400224#define encode_release_lockowner_maxsz \
225 (op_encode_hdr_maxsz + \
226 encode_lockowner_maxsz)
227#define decode_release_lockowner_maxsz \
228 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
230#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
232 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400233 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000234 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
236#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400237 1 + 2 + nfs4_name_maxsz + \
238 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400239#define decode_create_maxsz (op_decode_hdr_maxsz + \
240 decode_change_info_maxsz + \
241 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define encode_statfs_maxsz (encode_getattr_maxsz)
243#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
245#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400246#define encode_getacl_maxsz (encode_getattr_maxsz)
247#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
248 nfs4_fattr_bitmap_maxsz + 1)
249#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
250 encode_stateid_maxsz + 3)
251#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400252#define encode_fs_locations_maxsz \
253 (encode_getattr_maxsz)
254#define decode_fs_locations_maxsz \
255 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400256
257#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400258#define NFS4_MAX_MACHINE_NAME_LEN (64)
259
Benny Halevy99fe60d2009-04-01 09:22:29 -0400260#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
261 encode_verifier_maxsz + \
262 1 /* co_ownerid.len */ + \
263 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
264 1 /* flags */ + \
265 1 /* spa_how */ + \
266 0 /* SP4_NONE (for now) */ + \
267 1 /* zero implemetation id array */)
268#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
269 2 /* eir_clientid */ + \
270 1 /* eir_sequenceid */ + \
271 1 /* eir_flags */ + \
272 1 /* spr_how */ + \
273 0 /* SP4_NONE (for now) */ + \
274 2 /* eir_server_owner.so_minor_id */ + \
275 /* eir_server_owner.so_major_id<> */ \
276 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
277 /* eir_server_scope<> */ \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
279 1 /* eir_server_impl_id array length */ + \
280 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400281#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
282#define decode_channel_attrs_maxsz (6 + \
283 1 /* ca_rdma_ird.len */ + \
284 1 /* ca_rdma_ird */)
285#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
286 2 /* csa_clientid */ + \
287 1 /* csa_sequence */ + \
288 1 /* csa_flags */ + \
289 encode_channel_attrs_maxsz + \
290 encode_channel_attrs_maxsz + \
291 1 /* csa_cb_program */ + \
292 1 /* csa_sec_parms.len (1) */ + \
293 1 /* cb_secflavor (AUTH_SYS) */ + \
294 1 /* stamp */ + \
295 1 /* machinename.len */ + \
296 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
297 1 /* uid */ + \
298 1 /* gid */ + \
299 1 /* gids.len (0) */)
300#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
302 1 /* csr_sequence */ + \
303 1 /* csr_flags */ + \
304 decode_channel_attrs_maxsz + \
305 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400306#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
307#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400308#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
309 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
310#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
311 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500312#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
313#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400314#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
315 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
316#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
317 1 /* layout type */ + \
318 1 /* opaque devaddr4 length */ + \
319 /* devaddr4 payload is read into page */ \
320 1 /* notification bitmap length */ + \
321 1 /* notification bitmap */)
322#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
323 encode_stateid_maxsz)
324#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
325 decode_stateid_maxsz + \
326 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400327#else /* CONFIG_NFS_V4_1 */
328#define encode_sequence_maxsz 0
329#define decode_sequence_maxsz 0
330#endif /* CONFIG_NFS_V4_1 */
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
333#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
334#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400335 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400337 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400339 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400341 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400343 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400345 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400347 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400349 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400353 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_dec_readdir_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_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400359 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400361 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400362 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400366 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400367 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400369 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400371 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400372 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400377 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400379 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400380 encode_putfh_maxsz + \
381 encode_savefh_maxsz + \
382 encode_open_maxsz + \
383 encode_getfh_maxsz + \
384 encode_getattr_maxsz + \
385 encode_restorefh_maxsz + \
386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400389 decode_putfh_maxsz + \
390 decode_savefh_maxsz + \
391 decode_open_maxsz + \
392 decode_getfh_maxsz + \
393 decode_getattr_maxsz + \
394 decode_restorefh_maxsz + \
395 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400396#define NFS4_enc_open_confirm_sz \
397 (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_open_confirm_maxsz)
400#define NFS4_dec_open_confirm_sz \
401 (compound_decode_hdr_maxsz + \
402 decode_putfh_maxsz + \
403 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400407 encode_open_maxsz + \
408 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400410 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400412 decode_open_maxsz + \
413 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#define NFS4_enc_open_downgrade_sz \
415 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400417 encode_putfh_maxsz + \
418 encode_open_downgrade_maxsz + \
419 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_dec_open_downgrade_sz \
421 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400423 decode_putfh_maxsz + \
424 decode_open_downgrade_maxsz + \
425 decode_getattr_maxsz)
426#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_putfh_maxsz + \
429 encode_close_maxsz + \
430 encode_getattr_maxsz)
431#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400433 decode_putfh_maxsz + \
434 decode_close_maxsz + \
435 decode_getattr_maxsz)
436#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_putfh_maxsz + \
439 encode_setattr_maxsz + \
440 encode_getattr_maxsz)
441#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400443 decode_putfh_maxsz + \
444 decode_setattr_maxsz + \
445 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
449 encode_fsinfo_maxsz)
450#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
453 decode_fsinfo_maxsz)
454#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
455 encode_renew_maxsz)
456#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
457 decode_renew_maxsz)
458#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
459 encode_setclientid_maxsz)
460#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
461 decode_setclientid_maxsz)
462#define NFS4_enc_setclientid_confirm_sz \
463 (compound_encode_hdr_maxsz + \
464 encode_setclientid_confirm_maxsz + \
465 encode_putrootfh_maxsz + \
466 encode_fsinfo_maxsz)
467#define NFS4_dec_setclientid_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_setclientid_confirm_maxsz + \
470 decode_putrootfh_maxsz + \
471 decode_fsinfo_maxsz)
472#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400479 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400481 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400483 encode_lockt_maxsz)
484#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400495 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400496#define NFS4_enc_release_lockowner_sz \
497 (compound_encode_hdr_maxsz + \
498 encode_lockowner_maxsz)
499#define NFS4_dec_release_lockowner_sz \
500 (compound_decode_hdr_maxsz + \
501 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400505 encode_access_maxsz + \
506 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400510 decode_access_maxsz + \
511 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 encode_putfh_maxsz + \
515 encode_getattr_maxsz)
516#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 decode_putfh_maxsz + \
519 decode_getattr_maxsz)
520#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 encode_putfh_maxsz + \
523 encode_lookup_maxsz + \
524 encode_getattr_maxsz + \
525 encode_getfh_maxsz)
526#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400529 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 decode_getattr_maxsz + \
531 decode_getfh_maxsz)
532#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 encode_putrootfh_maxsz + \
535 encode_getattr_maxsz + \
536 encode_getfh_maxsz)
537#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putrootfh_maxsz + \
540 decode_getattr_maxsz + \
541 decode_getfh_maxsz)
542#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400545 encode_remove_maxsz + \
546 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400550 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400551 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 encode_putfh_maxsz + \
555 encode_savefh_maxsz + \
556 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400557 encode_rename_maxsz + \
558 encode_getattr_maxsz + \
559 encode_restorefh_maxsz + \
560 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
564 decode_savefh_maxsz + \
565 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400566 decode_rename_maxsz + \
567 decode_getattr_maxsz + \
568 decode_restorefh_maxsz + \
569 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
573 encode_savefh_maxsz + \
574 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400575 encode_link_maxsz + \
576 decode_getattr_maxsz + \
577 encode_restorefh_maxsz + \
578 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
582 decode_savefh_maxsz + \
583 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400584 decode_link_maxsz + \
585 decode_getattr_maxsz + \
586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_putfh_maxsz + \
591 encode_symlink_maxsz + \
592 encode_getattr_maxsz + \
593 encode_getfh_maxsz)
594#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
597 decode_symlink_maxsz + \
598 decode_getattr_maxsz + \
599 decode_getfh_maxsz)
600#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400603 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400605 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400607 encode_restorefh_maxsz + \
608 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400612 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400614 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400616 decode_restorefh_maxsz + \
617 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 encode_putfh_maxsz + \
621 encode_getattr_maxsz)
622#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 decode_putfh_maxsz + \
625 decode_getattr_maxsz)
626#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400629 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400633 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800636 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_getattr_maxsz)
638#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800640 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_getattr_maxsz)
642#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100645 encode_delegreturn_maxsz + \
646 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100649 decode_delegreturn_maxsz + \
650 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000651#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000653 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400654 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000655#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000657 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400658 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000659#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000661 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400662 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000663#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000665 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400666 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400667#define NFS4_enc_fs_locations_sz \
668 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400670 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400671 encode_lookup_maxsz + \
672 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400673#define NFS4_dec_fs_locations_sz \
674 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400676 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400677 decode_lookup_maxsz + \
678 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400679#if defined(CONFIG_NFS_V4_1)
680#define NFS4_enc_exchange_id_sz \
681 (compound_encode_hdr_maxsz + \
682 encode_exchange_id_maxsz)
683#define NFS4_dec_exchange_id_sz \
684 (compound_decode_hdr_maxsz + \
685 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400686#define NFS4_enc_create_session_sz \
687 (compound_encode_hdr_maxsz + \
688 encode_create_session_maxsz)
689#define NFS4_dec_create_session_sz \
690 (compound_decode_hdr_maxsz + \
691 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400692#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
693 encode_destroy_session_maxsz)
694#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
695 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400696#define NFS4_enc_sequence_sz \
697 (compound_decode_hdr_maxsz + \
698 encode_sequence_maxsz)
699#define NFS4_dec_sequence_sz \
700 (compound_decode_hdr_maxsz + \
701 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400702#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
703 encode_sequence_maxsz + \
704 encode_putrootfh_maxsz + \
705 encode_fsinfo_maxsz)
706#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
707 decode_sequence_maxsz + \
708 decode_putrootfh_maxsz + \
709 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500710#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_reclaim_complete_maxsz)
713#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
714 decode_sequence_maxsz + \
715 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400716#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
717 encode_sequence_maxsz +\
718 encode_getdeviceinfo_maxsz)
719#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
720 decode_sequence_maxsz + \
721 decode_getdeviceinfo_maxsz)
722#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
725 encode_layoutget_maxsz)
726#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
729 decode_layoutget_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500730
731const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
732 compound_encode_hdr_maxsz +
733 encode_sequence_maxsz +
734 encode_putfh_maxsz +
735 encode_getattr_maxsz) *
736 XDR_UNIT);
737
738const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
739 compound_decode_hdr_maxsz +
740 decode_sequence_maxsz +
741 decode_putfh_maxsz) *
742 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400743#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Trond Myklebustbca79472009-03-11 14:10:26 -0400745static const umode_t nfs_type2fmt[] = {
746 [NF4BAD] = 0,
747 [NF4REG] = S_IFREG,
748 [NF4DIR] = S_IFDIR,
749 [NF4BLK] = S_IFBLK,
750 [NF4CHR] = S_IFCHR,
751 [NF4LNK] = S_IFLNK,
752 [NF4SOCK] = S_IFSOCK,
753 [NF4FIFO] = S_IFIFO,
754 [NF4ATTRDIR] = 0,
755 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756};
757
758struct compound_hdr {
759 int32_t status;
760 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500761 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 uint32_t taglen;
763 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400764 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400765 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766};
767
Benny Halevy13c65ce2009-08-14 17:19:25 +0300768static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
769{
770 __be32 *p = xdr_reserve_space(xdr, nbytes);
771 BUG_ON(!p);
772 return p;
773}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
776{
Al Viro8687b632006-10-19 23:28:48 -0700777 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 p = xdr_reserve_space(xdr, 4 + len);
780 BUG_ON(p == NULL);
781 xdr_encode_opaque(p, str, len);
782}
783
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400784static void encode_compound_hdr(struct xdr_stream *xdr,
785 struct rpc_rqst *req,
786 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Al Viro8687b632006-10-19 23:28:48 -0700788 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400789 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400790
791 /* initialize running count of expected bytes in reply.
792 * NOTE: the replied tag SHOULD be the same is the one sent,
793 * but this is not required as a MUST for the server to do so. */
794 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
797 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300798 p = reserve_space(xdr, 4 + hdr->taglen + 8);
799 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300800 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500801 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300802 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500803}
804
805static void encode_nops(struct compound_hdr *hdr)
806{
Andy Adamsonfc931582009-04-01 09:22:31 -0400807 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500808 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
812{
Al Viro8687b632006-10-19 23:28:48 -0700813 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
816 BUG_ON(p == NULL);
817 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
818}
819
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500820static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 char owner_name[IDMAP_NAMESZ];
823 char owner_group[IDMAP_NAMESZ];
824 int owner_namelen = 0;
825 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700826 __be32 *p;
827 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 int len;
829 uint32_t bmval0 = 0;
830 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 /*
833 * We reserve enough space to write the entire attribute buffer at once.
834 * In the worst-case, this would be
835 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
836 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000837 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 */
839 len = 16;
840
841 /* Sigh */
842 if (iap->ia_valid & ATTR_SIZE)
843 len += 8;
844 if (iap->ia_valid & ATTR_MODE)
845 len += 4;
846 if (iap->ia_valid & ATTR_UID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400847 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400849 dprintk("nfs: couldn't resolve uid %d to string\n",
850 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /* XXX */
852 strcpy(owner_name, "nobody");
853 owner_namelen = sizeof("nobody") - 1;
854 /* goto out; */
855 }
856 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
857 }
858 if (iap->ia_valid & ATTR_GID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400859 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400861 dprintk("nfs: couldn't resolve gid %d to string\n",
862 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 strcpy(owner_group, "nobody");
864 owner_grouplen = sizeof("nobody") - 1;
865 /* goto out; */
866 }
867 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
868 }
869 if (iap->ia_valid & ATTR_ATIME_SET)
870 len += 16;
871 else if (iap->ia_valid & ATTR_ATIME)
872 len += 4;
873 if (iap->ia_valid & ATTR_MTIME_SET)
874 len += 16;
875 else if (iap->ia_valid & ATTR_MTIME)
876 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300877 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 /*
880 * We write the bitmap length now, but leave the bitmap and the attribute
881 * buffer length to be backfilled at the end of this routine.
882 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300883 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 q = p;
885 p += 3;
886
887 if (iap->ia_valid & ATTR_SIZE) {
888 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300889 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 }
891 if (iap->ia_valid & ATTR_MODE) {
892 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300893 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
895 if (iap->ia_valid & ATTR_UID) {
896 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300897 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899 if (iap->ia_valid & ATTR_GID) {
900 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300901 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903 if (iap->ia_valid & ATTR_ATIME_SET) {
904 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300905 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
906 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400907 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
908 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910 else if (iap->ia_valid & ATTR_ATIME) {
911 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300912 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 if (iap->ia_valid & ATTR_MTIME_SET) {
915 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300916 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
917 *p++ = cpu_to_be32(0);
918 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
919 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921 else if (iap->ia_valid & ATTR_MTIME) {
922 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300923 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 /*
927 * Now we backfill the bitmap and the attribute buffer length.
928 */
929 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400930 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 len, ((char *)p - (char *)q) + 4);
932 BUG();
933 }
934 len = (char *)p - (char *)q - 12;
935 *q++ = htonl(bmval0);
936 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300937 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500942static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Al Viro8687b632006-10-19 23:28:48 -0700944 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Benny Halevy13c65ce2009-08-14 17:19:25 +0300946 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300947 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300948 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500949 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400950 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500953static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Al Viro8687b632006-10-19 23:28:48 -0700955 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Benny Halevy13c65ce2009-08-14 17:19:25 +0300957 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300958 *p++ = cpu_to_be32(OP_CLOSE);
959 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300960 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500961 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400962 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500965static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Al Viro8687b632006-10-19 23:28:48 -0700967 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500968
Benny Halevy13c65ce2009-08-14 17:19:25 +0300969 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300970 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300971 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300972 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500973 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400974 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500977static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Al Viro8687b632006-10-19 23:28:48 -0700979 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500980
Benny Halevy13c65ce2009-08-14 17:19:25 +0300981 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300982 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300983 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 switch (create->ftype) {
986 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300987 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300988 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400989 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 break;
991
992 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300993 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300994 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300995 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 break;
997
998 default:
999 break;
1000 }
1001
Benny Halevy811652b2009-08-14 17:19:34 +03001002 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001003 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001004 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001009static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
Andy Adamson05d564f2008-12-23 16:06:15 -05001011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Benny Halevy13c65ce2009-08-14 17:19:25 +03001013 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(OP_GETATTR);
1015 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001016 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001017 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001018 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001021static 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 -07001022{
Andy Adamson05d564f2008-12-23 16:06:15 -05001023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Benny Halevy13c65ce2009-08-14 17:19:25 +03001025 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001026 *p++ = cpu_to_be32(OP_GETATTR);
1027 *p++ = cpu_to_be32(2);
1028 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001031 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001034static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001036 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1037 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038}
1039
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001040static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001042 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1043 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001046static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001047{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001048 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1049 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001050}
1051
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001052static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
Al Viro8687b632006-10-19 23:28:48 -07001054 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Benny Halevy13c65ce2009-08-14 17:19:25 +03001056 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001057 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001058 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001059 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001062static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Benny Halevy13c65ce2009-08-14 17:19:25 +03001066 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001068 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001073static inline int nfs4_lock_type(struct file_lock *fl, int block)
1074{
1075 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1076 return block ? NFS4_READW_LT : NFS4_READ_LT;
1077 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1078}
1079
1080static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1081{
1082 if (fl->fl_end == OFFSET_MAX)
1083 return ~(uint64_t)0;
1084 return fl->fl_end - fl->fl_start + 1;
1085}
1086
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001087static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1088{
1089 __be32 *p;
1090
Trond Myklebustd035c362010-12-21 10:45:27 -05001091 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001092 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001093 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001094 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001095 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001096 xdr_encode_hyper(p, lowner->id);
1097}
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099/*
1100 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1101 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1102 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Al Viro8687b632006-10-19 23:28:48 -07001105 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Benny Halevy13c65ce2009-08-14 17:19:25 +03001107 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001108 *p++ = cpu_to_be32(OP_LOCK);
1109 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1110 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001111 p = xdr_encode_hyper(p, args->fl->fl_start);
1112 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001113 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001114 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001115 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001116 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001117 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001118 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001119 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 }
1121 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001122 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001123 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001124 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 }
Andy Adamsond0179312008-12-23 16:06:17 -05001126 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001127 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001130static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Al Viro8687b632006-10-19 23:28:48 -07001132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001134 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001135 *p++ = cpu_to_be32(OP_LOCKT);
1136 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001137 p = xdr_encode_hyper(p, args->fl->fl_start);
1138 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001139 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001140 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001141 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Al Viro8687b632006-10-19 23:28:48 -07001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Benny Halevy13c65ce2009-08-14 17:19:25 +03001148 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001149 *p++ = cpu_to_be32(OP_LOCKU);
1150 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1151 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001152 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001153 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001154 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001155 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001156 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001159static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1160{
1161 __be32 *p;
1162
1163 p = reserve_space(xdr, 4);
1164 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1165 encode_lockowner(xdr, lowner);
1166 hdr->nops++;
1167 hdr->replen += decode_release_lockowner_maxsz;
1168}
1169
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001170static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
1172 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Benny Halevy13c65ce2009-08-14 17:19:25 +03001175 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001176 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001177 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001178 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001179 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001182static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Al Viro8687b632006-10-19 23:28:48 -07001184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Benny Halevy13c65ce2009-08-14 17:19:25 +03001186 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001187 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001188 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001189 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001190 break;
1191 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001192 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001193 break;
1194 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001195 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001196 break;
1197 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001198 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
Benny Halevy34558512009-08-14 17:19:30 +03001200 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
1203static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 /*
1207 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1208 * owner 4 = 32
1209 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001210 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001211 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001212 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001213 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001214 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001215 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001216 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001217 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001218 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001219 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
1222static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1223{
Al Viro8687b632006-10-19 23:28:48 -07001224 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001225 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Benny Halevy13c65ce2009-08-14 17:19:25 +03001227 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001229 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001230 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001231 encode_attrs(xdr, arg->u.attrs, arg->server);
1232 break;
1233 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001234 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001235 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001236 if (nfs4_has_persistent_session(clp)) {
1237 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1238 encode_attrs(xdr, arg->u.attrs, arg->server);
1239 } else {
1240 struct iattr dummy;
1241
1242 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1243 encode_nfs4_verifier(xdr, &arg->u.verifier);
1244 dummy.ia_valid = 0;
1245 encode_attrs(xdr, &dummy, arg->server);
1246 }
1247 } else {
1248 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1249 encode_nfs4_verifier(xdr, &arg->u.verifier);
1250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
1252}
1253
1254static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1255{
Al Viro8687b632006-10-19 23:28:48 -07001256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Benny Halevy13c65ce2009-08-14 17:19:25 +03001258 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001260 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001261 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001262 break;
1263 default:
1264 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001266 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
1268}
1269
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001270static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Al Viro8687b632006-10-19 23:28:48 -07001272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Benny Halevy13c65ce2009-08-14 17:19:25 +03001274 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001276 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001277 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001278 break;
1279 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001280 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001281 break;
1282 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001283 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001284 break;
1285 default:
1286 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 }
1288}
1289
1290static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1291{
Al Viro8687b632006-10-19 23:28:48 -07001292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Benny Halevy13c65ce2009-08-14 17:19:25 +03001294 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001295 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 encode_string(xdr, name->len, name->name);
1297}
1298
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001299static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
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);
Benny Halevy34558512009-08-14 17:19:30 +03001304 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 encode_delegation_type(xdr, type);
1306}
1307
1308static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1309{
Al Viro8687b632006-10-19 23:28:48 -07001310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Benny Halevy13c65ce2009-08-14 17:19:25 +03001312 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001313 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001314 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 encode_string(xdr, name->len, name->name);
1316}
1317
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001318static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 encode_openhdr(xdr, arg);
1321 encode_opentype(xdr, arg);
1322 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001323 case NFS4_OPEN_CLAIM_NULL:
1324 encode_claim_null(xdr, arg->name);
1325 break;
1326 case NFS4_OPEN_CLAIM_PREVIOUS:
1327 encode_claim_previous(xdr, arg->u.delegation_type);
1328 break;
1329 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1330 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1331 break;
1332 default:
1333 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
Andy Adamsond0179312008-12-23 16:06:17 -05001335 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001336 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static 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 -07001340{
Al Viro8687b632006-10-19 23:28:48 -07001341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Benny Halevy13c65ce2009-08-14 17:19:25 +03001343 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001345 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001346 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001347 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001348 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001351static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001357 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001358 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001359 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001360 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001361 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001364static void
Andy Adamsond0179312008-12-23 16:06:17 -05001365encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Benny Halevy13c65ce2009-08-14 17:19:25 +03001370 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001371 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001372 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001373 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001374 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
1376
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001377static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Andy Adamson05d564f2008-12-23 16:06:15 -05001379 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001380
Benny Halevy13c65ce2009-08-14 17:19:25 +03001381 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001382 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001383 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001384 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001387static 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 -07001388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001390 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Benny Halevy13c65ce2009-08-14 17:19:25 +03001392 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001394 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Benny Halevy34558512009-08-14 17:19:30 +03001395 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 } else
Benny Halevy34558512009-08-14 17:19:30 +03001397 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001400static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
Al Viro8687b632006-10-19 23:28:48 -07001402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Benny Halevy13c65ce2009-08-14 17:19:25 +03001404 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001405 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001407 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Benny Halevy13c65ce2009-08-14 17:19:25 +03001409 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001410 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001411 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001412 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001413 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414}
1415
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001416static 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 -07001417{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001418 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001419 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001422 if (readdir->plus) {
1423 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1424 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1425 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1426 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1427 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1428 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001429 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001430 }
1431 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1432 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001433 /* Switch to mounted_on_fileid if the server supports it */
1434 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1435 attrs[0] &= ~FATTR4_WORD0_FILEID;
1436 else
1437 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001438
Benny Halevy13c65ce2009-08-14 17:19:25 +03001439 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001440 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001441 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001442 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001443 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001444 *p++ = cpu_to_be32(readdir->count);
1445 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001446
Benny Halevye75bc1c2009-08-14 17:18:54 +03001447 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001449 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001450 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001451 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1452 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001453 (unsigned long long)readdir->cookie,
1454 ((u32 *)readdir->verifier.data)[0],
1455 ((u32 *)readdir->verifier.data)[1],
1456 attrs[0] & readdir->bitmask[0],
1457 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458}
1459
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001460static 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 -07001461{
Al Viro8687b632006-10-19 23:28:48 -07001462 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Benny Halevy13c65ce2009-08-14 17:19:25 +03001464 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001465 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001466 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001467 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468}
1469
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001470static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
Al Viro8687b632006-10-19 23:28:48 -07001472 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Benny Halevy13c65ce2009-08-14 17:19:25 +03001474 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001475 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001476 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001477 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001478 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001481static 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 -07001482{
Al Viro8687b632006-10-19 23:28:48 -07001483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Benny Halevy811652b2009-08-14 17:19:34 +03001485 p = reserve_space(xdr, 4);
1486 *p = cpu_to_be32(OP_RENAME);
1487 encode_string(xdr, oldname->len, oldname->name);
1488 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001489 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001490 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491}
1492
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001493static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Al Viro8687b632006-10-19 23:28:48 -07001495 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Benny Halevy13c65ce2009-08-14 17:19:25 +03001497 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001498 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001499 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001500 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001501 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001504static void
Andy Adamsond0179312008-12-23 16:06:17 -05001505encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001506{
Al Viro8687b632006-10-19 23:28:48 -07001507 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001508
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(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001511 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001512 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001513}
1514
Chuck Lever9f06c712010-12-14 14:59:18 +00001515static void
Andy Adamsond0179312008-12-23 16:06:17 -05001516encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001517{
Al Viro8687b632006-10-19 23:28:48 -07001518 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001519
Benny Halevy13c65ce2009-08-14 17:19:25 +03001520 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001521 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001522 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001523 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001524 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001525 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001526 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001527 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001528 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001529 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001530 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001531 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001532}
1533
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534static void
Andy Adamsond0179312008-12-23 16:06:17 -05001535encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
Al Viro8687b632006-10-19 23:28:48 -07001537 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Benny Halevy13c65ce2009-08-14 17:19:25 +03001539 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001540 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001541 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001542 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static 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 -07001546{
Al Viro8687b632006-10-19 23:28:48 -07001547 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001548
Benny Halevy13c65ce2009-08-14 17:19:25 +03001549 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001550 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001551 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001552 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001553 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001557static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Al Viro8687b632006-10-19 23:28:48 -07001559 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Benny Halevy13c65ce2009-08-14 17:19:25 +03001561 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001562 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001563 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001566 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001567 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1569 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001570 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001571 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001572 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001573 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001576static 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 -07001577{
Andy Adamson05d564f2008-12-23 16:06:15 -05001578 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Benny Halevy13c65ce2009-08-14 17:19:25 +03001580 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001581 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001582 p = xdr_encode_hyper(p, arg->clientid);
1583 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001584 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001585 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
1587
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001588static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
Al Viro8687b632006-10-19 23:28:48 -07001590 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Benny Halevy13c65ce2009-08-14 17:19:25 +03001592 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001593 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001595 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Benny Halevy13c65ce2009-08-14 17:19:25 +03001597 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001598 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001599 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001600 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001603 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001604 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001607static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
Al Viro8687b632006-10-19 23:28:48 -07001609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Benny Halevy13c65ce2009-08-14 17:19:25 +03001611 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Benny Halevye75bc1c2009-08-14 17:18:54 +03001613 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001614 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001615 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001616 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001618
Benny Halevy99fe60d2009-04-01 09:22:29 -04001619#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001620/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001621static void encode_exchange_id(struct xdr_stream *xdr,
1622 struct nfs41_exchange_id_args *args,
1623 struct compound_hdr *hdr)
1624{
1625 __be32 *p;
1626
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001628 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001629 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001630
1631 encode_string(xdr, args->id_len, args->id);
1632
Benny Halevy13c65ce2009-08-14 17:19:25 +03001633 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001634 *p++ = cpu_to_be32(args->flags);
1635 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001636 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001637 hdr->nops++;
1638 hdr->replen += decode_exchange_id_maxsz;
1639}
Andy Adamsonfc931582009-04-01 09:22:31 -04001640
1641static void encode_create_session(struct xdr_stream *xdr,
1642 struct nfs41_create_session_args *args,
1643 struct compound_hdr *hdr)
1644{
1645 __be32 *p;
1646 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1647 uint32_t len;
1648 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001649 u32 max_resp_sz_cached;
1650
1651 /*
1652 * Assumes OPEN is the biggest non-idempotent compound.
1653 * 2 is the verifier.
1654 */
1655 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1656 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001657
Andy Adamsonfc931582009-04-01 09:22:31 -04001658 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1659 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001660
Benny Halevy13c65ce2009-08-14 17:19:25 +03001661 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001662 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001663 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001664 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1665 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001666
Andy Adamsonfc931582009-04-01 09:22:31 -04001667 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001668 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1669 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1670 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001671 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001672 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1673 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1674 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001675
1676 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001677 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1678 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1679 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1680 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1681 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1682 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1683 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001684
Benny Halevye75bc1c2009-08-14 17:18:54 +03001685 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001686 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001687 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001688
1689 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001690 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001691 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001692 *p++ = cpu_to_be32(0); /* UID */
1693 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001694 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001695 hdr->nops++;
1696 hdr->replen += decode_create_session_maxsz;
1697}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001698
1699static void encode_destroy_session(struct xdr_stream *xdr,
1700 struct nfs4_session *session,
1701 struct compound_hdr *hdr)
1702{
1703 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001704 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001705 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001706 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001707 hdr->nops++;
1708 hdr->replen += decode_destroy_session_maxsz;
1709}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001710
1711static void encode_reclaim_complete(struct xdr_stream *xdr,
1712 struct nfs41_reclaim_complete_args *args,
1713 struct compound_hdr *hdr)
1714{
1715 __be32 *p;
1716
1717 p = reserve_space(xdr, 8);
1718 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1719 *p++ = cpu_to_be32(args->one_fs);
1720 hdr->nops++;
1721 hdr->replen += decode_reclaim_complete_maxsz;
1722}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001723#endif /* CONFIG_NFS_V4_1 */
1724
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001725static void encode_sequence(struct xdr_stream *xdr,
1726 const struct nfs4_sequence_args *args,
1727 struct compound_hdr *hdr)
1728{
1729#if defined(CONFIG_NFS_V4_1)
1730 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001731 struct nfs4_slot_table *tp;
1732 struct nfs4_slot *slot;
1733 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001734
1735 if (!session)
1736 return;
1737
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001738 tp = &session->fc_slot_table;
1739
1740 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1741 slot = tp->slots + args->sa_slotid;
1742
Benny Halevy13c65ce2009-08-14 17:19:25 +03001743 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001744 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001745
1746 /*
1747 * Sessionid + seqid + slotid + max slotid + cache_this
1748 */
1749 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1750 "max_slotid=%d cache_this=%d\n",
1751 __func__,
1752 ((u32 *)session->sess_id.data)[0],
1753 ((u32 *)session->sess_id.data)[1],
1754 ((u32 *)session->sess_id.data)[2],
1755 ((u32 *)session->sess_id.data)[3],
1756 slot->seq_nr, args->sa_slotid,
1757 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001758 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001759 *p++ = cpu_to_be32(slot->seq_nr);
1760 *p++ = cpu_to_be32(args->sa_slotid);
1761 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001762 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001763 hdr->nops++;
1764 hdr->replen += decode_sequence_maxsz;
1765#endif /* CONFIG_NFS_V4_1 */
1766}
1767
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001768#ifdef CONFIG_NFS_V4_1
1769static void
1770encode_getdeviceinfo(struct xdr_stream *xdr,
1771 const struct nfs4_getdeviceinfo_args *args,
1772 struct compound_hdr *hdr)
1773{
1774 __be32 *p;
1775
1776 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1777 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1778 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1779 NFS4_DEVICEID4_SIZE);
1780 *p++ = cpu_to_be32(args->pdev->layout_type);
1781 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1782 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1783 hdr->nops++;
1784 hdr->replen += decode_getdeviceinfo_maxsz;
1785}
1786
1787static void
1788encode_layoutget(struct xdr_stream *xdr,
1789 const struct nfs4_layoutget_args *args,
1790 struct compound_hdr *hdr)
1791{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001792 __be32 *p;
1793
1794 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1795 *p++ = cpu_to_be32(OP_LAYOUTGET);
1796 *p++ = cpu_to_be32(0); /* Signal layout available */
1797 *p++ = cpu_to_be32(args->type);
1798 *p++ = cpu_to_be32(args->range.iomode);
1799 p = xdr_encode_hyper(p, args->range.offset);
1800 p = xdr_encode_hyper(p, args->range.length);
1801 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001802 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001803 *p = cpu_to_be32(args->maxcount);
1804
1805 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1806 __func__,
1807 args->type,
1808 args->range.iomode,
1809 (unsigned long)args->range.offset,
1810 (unsigned long)args->range.length,
1811 args->maxcount);
1812 hdr->nops++;
1813 hdr->replen += decode_layoutget_maxsz;
1814}
1815#endif /* CONFIG_NFS_V4_1 */
1816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817/*
1818 * END OF "GENERIC" ENCODE ROUTINES.
1819 */
1820
Benny Halevy66cc0422009-04-01 09:22:10 -04001821static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1822{
1823#if defined(CONFIG_NFS_V4_1)
1824 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001825 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001826#endif /* CONFIG_NFS_V4_1 */
1827 return 0;
1828}
1829
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830/*
1831 * Encode an ACCESS request
1832 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001833static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1834 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001837 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Chuck Lever9f06c712010-12-14 14:59:18 +00001840 encode_compound_hdr(xdr, req, &hdr);
1841 encode_sequence(xdr, &args->seq_args, &hdr);
1842 encode_putfh(xdr, args->fh, &hdr);
1843 encode_access(xdr, args->access, &hdr);
1844 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001845 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
1848/*
1849 * Encode LOOKUP request
1850 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001851static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1852 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001855 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
Chuck Lever9f06c712010-12-14 14:59:18 +00001858 encode_compound_hdr(xdr, req, &hdr);
1859 encode_sequence(xdr, &args->seq_args, &hdr);
1860 encode_putfh(xdr, args->dir_fh, &hdr);
1861 encode_lookup(xdr, args->name, &hdr);
1862 encode_getfh(xdr, &hdr);
1863 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001864 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865}
1866
1867/*
1868 * Encode LOOKUP_ROOT request
1869 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001870static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1871 struct xdr_stream *xdr,
1872 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001875 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Chuck Lever9f06c712010-12-14 14:59:18 +00001878 encode_compound_hdr(xdr, req, &hdr);
1879 encode_sequence(xdr, &args->seq_args, &hdr);
1880 encode_putrootfh(xdr, &hdr);
1881 encode_getfh(xdr, &hdr);
1882 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001883 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884}
1885
1886/*
1887 * Encode REMOVE request
1888 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001889static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1890 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001893 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Chuck Lever9f06c712010-12-14 14:59:18 +00001896 encode_compound_hdr(xdr, req, &hdr);
1897 encode_sequence(xdr, &args->seq_args, &hdr);
1898 encode_putfh(xdr, args->fh, &hdr);
1899 encode_remove(xdr, &args->name, &hdr);
1900 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001901 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902}
1903
1904/*
1905 * Encode RENAME request
1906 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001907static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1908 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001911 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Chuck Lever9f06c712010-12-14 14:59:18 +00001914 encode_compound_hdr(xdr, req, &hdr);
1915 encode_sequence(xdr, &args->seq_args, &hdr);
1916 encode_putfh(xdr, args->old_dir, &hdr);
1917 encode_savefh(xdr, &hdr);
1918 encode_putfh(xdr, args->new_dir, &hdr);
1919 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1920 encode_getfattr(xdr, args->bitmask, &hdr);
1921 encode_restorefh(xdr, &hdr);
1922 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001923 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924}
1925
1926/*
1927 * Encode LINK request
1928 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001929static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1930 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
Chuck Lever9f06c712010-12-14 14:59:18 +00001936 encode_compound_hdr(xdr, req, &hdr);
1937 encode_sequence(xdr, &args->seq_args, &hdr);
1938 encode_putfh(xdr, args->fh, &hdr);
1939 encode_savefh(xdr, &hdr);
1940 encode_putfh(xdr, args->dir_fh, &hdr);
1941 encode_link(xdr, args->name, &hdr);
1942 encode_getfattr(xdr, args->bitmask, &hdr);
1943 encode_restorefh(xdr, &hdr);
1944 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001945 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
1947
1948/*
1949 * Encode CREATE request
1950 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001951static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
1952 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Chuck Lever9f06c712010-12-14 14:59:18 +00001958 encode_compound_hdr(xdr, req, &hdr);
1959 encode_sequence(xdr, &args->seq_args, &hdr);
1960 encode_putfh(xdr, args->dir_fh, &hdr);
1961 encode_savefh(xdr, &hdr);
1962 encode_create(xdr, args, &hdr);
1963 encode_getfh(xdr, &hdr);
1964 encode_getfattr(xdr, args->bitmask, &hdr);
1965 encode_restorefh(xdr, &hdr);
1966 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001967 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
1970/*
1971 * Encode SYMLINK request
1972 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001973static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
1974 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975{
Chuck Lever9f06c712010-12-14 14:59:18 +00001976 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977}
1978
1979/*
1980 * Encode GETATTR request
1981 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001982static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1983 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Chuck Lever9f06c712010-12-14 14:59:18 +00001989 encode_compound_hdr(xdr, req, &hdr);
1990 encode_sequence(xdr, &args->seq_args, &hdr);
1991 encode_putfh(xdr, args->fh, &hdr);
1992 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001993 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994}
1995
1996/*
1997 * Encode a CLOSE request
1998 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001999static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2000 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001{
Andy Adamson05d564f2008-12-23 16:06:15 -05002002 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002003 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002004 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Chuck Lever9f06c712010-12-14 14:59:18 +00002006 encode_compound_hdr(xdr, req, &hdr);
2007 encode_sequence(xdr, &args->seq_args, &hdr);
2008 encode_putfh(xdr, args->fh, &hdr);
2009 encode_close(xdr, args, &hdr);
2010 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002011 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
2014/*
2015 * Encode an OPEN request
2016 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002017static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2018 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Chuck Lever9f06c712010-12-14 14:59:18 +00002024 encode_compound_hdr(xdr, req, &hdr);
2025 encode_sequence(xdr, &args->seq_args, &hdr);
2026 encode_putfh(xdr, args->fh, &hdr);
2027 encode_savefh(xdr, &hdr);
2028 encode_open(xdr, args, &hdr);
2029 encode_getfh(xdr, &hdr);
2030 encode_getfattr(xdr, args->bitmask, &hdr);
2031 encode_restorefh(xdr, &hdr);
2032 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002033 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034}
2035
2036/*
2037 * Encode an OPEN_CONFIRM request
2038 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002039static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2040 struct xdr_stream *xdr,
2041 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002044 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Chuck Lever9f06c712010-12-14 14:59:18 +00002047 encode_compound_hdr(xdr, req, &hdr);
2048 encode_putfh(xdr, args->fh, &hdr);
2049 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002050 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051}
2052
2053/*
2054 * Encode an OPEN request with no attributes.
2055 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002056static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2057 struct xdr_stream *xdr,
2058 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Chuck Lever9f06c712010-12-14 14:59:18 +00002064 encode_compound_hdr(xdr, req, &hdr);
2065 encode_sequence(xdr, &args->seq_args, &hdr);
2066 encode_putfh(xdr, args->fh, &hdr);
2067 encode_open(xdr, args, &hdr);
2068 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002069 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}
2071
2072/*
2073 * Encode an OPEN_DOWNGRADE request
2074 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002075static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2076 struct xdr_stream *xdr,
2077 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Chuck Lever9f06c712010-12-14 14:59:18 +00002083 encode_compound_hdr(xdr, req, &hdr);
2084 encode_sequence(xdr, &args->seq_args, &hdr);
2085 encode_putfh(xdr, args->fh, &hdr);
2086 encode_open_downgrade(xdr, args, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Encode a LOCK request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode a LOCKT request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->fh, &hdr);
2121 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002122 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
2125/*
2126 * Encode a LOCKU request
2127 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002128static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2129 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Chuck Lever9f06c712010-12-14 14:59:18 +00002135 encode_compound_hdr(xdr, req, &hdr);
2136 encode_sequence(xdr, &args->seq_args, &hdr);
2137 encode_putfh(xdr, args->fh, &hdr);
2138 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002139 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140}
2141
Chuck Lever9f06c712010-12-14 14:59:18 +00002142static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2143 struct xdr_stream *xdr,
2144 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002145{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002146 struct compound_hdr hdr = {
2147 .minorversion = 0,
2148 };
2149
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002152 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002153}
2154
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155/*
2156 * Encode a READLINK request
2157 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002158static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002169
Benny Halevy28f56692009-04-01 09:22:09 -04002170 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002171 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002172 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
2175/*
2176 * Encode a READDIR request
2177 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002178static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 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
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->fh, &hdr);
2188 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002189
Benny Halevy28f56692009-04-01 09:22:09 -04002190 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002191 args->pgbase, args->count);
2192 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002193 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002194 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002195 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196}
2197
2198/*
2199 * Encode a READ request
2200 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002201static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2202 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002205 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Chuck Lever9f06c712010-12-14 14:59:18 +00002208 encode_compound_hdr(xdr, req, &hdr);
2209 encode_sequence(xdr, &args->seq_args, &hdr);
2210 encode_putfh(xdr, args->fh, &hdr);
2211 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Benny Halevy28f56692009-04-01 09:22:09 -04002213 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002215 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002216 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217}
2218
2219/*
2220 * Encode an SETATTR request
2221 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002222static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2223 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224{
Andy Adamson05d564f2008-12-23 16:06:15 -05002225 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002227 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
Chuck Lever9f06c712010-12-14 14:59:18 +00002229 encode_compound_hdr(xdr, req, &hdr);
2230 encode_sequence(xdr, &args->seq_args, &hdr);
2231 encode_putfh(xdr, args->fh, &hdr);
2232 encode_setattr(xdr, args, args->server, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002234 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235}
2236
2237/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002238 * Encode a GETACL request
2239 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002240static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2241 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002242{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002243 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002245 };
Benny Halevy28f56692009-04-01 09:22:09 -04002246 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002251 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002252 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002253
Benny Halevy28f56692009-04-01 09:22:09 -04002254 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002255 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002256 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002257}
2258
2259/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 * Encode a WRITE request
2261 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002262static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2263 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002266 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Chuck Lever9f06c712010-12-14 14:59:18 +00002269 encode_compound_hdr(xdr, req, &hdr);
2270 encode_sequence(xdr, &args->seq_args, &hdr);
2271 encode_putfh(xdr, args->fh, &hdr);
2272 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002273 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Chuck Lever9f06c712010-12-14 14:59:18 +00002274 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002275 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276}
2277
2278/*
2279 * a COMMIT request
2280 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002281static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2282 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Chuck Lever9f06c712010-12-14 14:59:18 +00002288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_commit(xdr, args, &hdr);
2292 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002293 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
2297 * FSINFO request
2298 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002299static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2300 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002303 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Chuck Lever9f06c712010-12-14 14:59:18 +00002306 encode_compound_hdr(xdr, req, &hdr);
2307 encode_sequence(xdr, &args->seq_args, &hdr);
2308 encode_putfh(xdr, args->fh, &hdr);
2309 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002310 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313/*
2314 * a PATHCONF request
2315 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002316static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2317 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
2326 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002327 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002328 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329}
2330
2331/*
2332 * a STATFS request
2333 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002334static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2335 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002338 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
Chuck Lever9f06c712010-12-14 14:59:18 +00002341 encode_compound_hdr(xdr, req, &hdr);
2342 encode_sequence(xdr, &args->seq_args, &hdr);
2343 encode_putfh(xdr, args->fh, &hdr);
2344 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002345 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002346 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
2349/*
2350 * GETATTR_BITMAP request
2351 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002352static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2353 struct xdr_stream *xdr,
2354 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
Chuck Lever9f06c712010-12-14 14:59:18 +00002360 encode_compound_hdr(xdr, req, &hdr);
2361 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_putfh(xdr, args->fhandle, &hdr);
2363 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002364 FATTR4_WORD0_LINK_SUPPORT|
2365 FATTR4_WORD0_SYMLINK_SUPPORT|
2366 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002367 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
2370/*
2371 * a RENEW request
2372 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002373static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2374 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002377 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 };
2379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002382 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383}
2384
2385/*
2386 * a SETCLIENTID request
2387 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002388static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2389 struct xdr_stream *xdr,
2390 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002393 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 };
2395
Chuck Lever9f06c712010-12-14 14:59:18 +00002396 encode_compound_hdr(xdr, req, &hdr);
2397 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002398 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
2401/*
2402 * a SETCLIENTID_CONFIRM request
2403 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002404static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2405 struct xdr_stream *xdr,
2406 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002409 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 };
2411 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Chuck Lever9f06c712010-12-14 14:59:18 +00002413 encode_compound_hdr(xdr, req, &hdr);
2414 encode_setclientid_confirm(xdr, arg, &hdr);
2415 encode_putrootfh(xdr, &hdr);
2416 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002417 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418}
2419
2420/*
2421 * DELEGRETURN request
2422 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002423static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2424 struct xdr_stream *xdr,
2425 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002428 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Chuck Lever9f06c712010-12-14 14:59:18 +00002431 encode_compound_hdr(xdr, req, &hdr);
2432 encode_sequence(xdr, &args->seq_args, &hdr);
2433 encode_putfh(xdr, args->fhandle, &hdr);
2434 encode_delegreturn(xdr, args->stateid, &hdr);
2435 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002436 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437}
2438
2439/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002440 * Encode FS_LOCATIONS request
2441 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002442static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2443 struct xdr_stream *xdr,
2444 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002445{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002446 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002447 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002448 };
Benny Halevy28f56692009-04-01 09:22:09 -04002449 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->dir_fh, &hdr);
2454 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002455 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002456 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002457
Benny Halevy28f56692009-04-01 09:22:09 -04002458 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002459 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002460 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002461}
2462
Benny Halevy99fe60d2009-04-01 09:22:29 -04002463#if defined(CONFIG_NFS_V4_1)
2464/*
2465 * EXCHANGE_ID request
2466 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002467static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2468 struct xdr_stream *xdr,
2469 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002470{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002471 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002472 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002473 };
2474
Chuck Lever9f06c712010-12-14 14:59:18 +00002475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002477 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002478}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002479
2480/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002481 * a CREATE_SESSION request
2482 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002483static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2484 struct xdr_stream *xdr,
2485 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002486{
Andy Adamsonfc931582009-04-01 09:22:31 -04002487 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002488 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002489 };
2490
Chuck Lever9f06c712010-12-14 14:59:18 +00002491 encode_compound_hdr(xdr, req, &hdr);
2492 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002493 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002494}
2495
2496/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002497 * a DESTROY_SESSION request
2498 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002499static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2500 struct xdr_stream *xdr,
2501 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002502{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002503 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002504 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002505 };
2506
Chuck Lever9f06c712010-12-14 14:59:18 +00002507 encode_compound_hdr(xdr, req, &hdr);
2508 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002509 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002510}
2511
2512/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002513 * a SEQUENCE request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002517{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002518 struct compound_hdr hdr = {
2519 .minorversion = nfs4_xdr_minorversion(args),
2520 };
2521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002524 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002525}
2526
2527/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002528 * a GET_LEASE_TIME request
2529 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002530static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2531 struct xdr_stream *xdr,
2532 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002533{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002534 struct compound_hdr hdr = {
2535 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2536 };
2537 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2538
Chuck Lever9f06c712010-12-14 14:59:18 +00002539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->la_seq_args, &hdr);
2541 encode_putrootfh(xdr, &hdr);
2542 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002543 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002544}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002545
2546/*
2547 * a RECLAIM_COMPLETE request
2548 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002549static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2550 struct xdr_stream *xdr,
2551 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002552{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002553 struct compound_hdr hdr = {
2554 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2555 };
2556
Chuck Lever9f06c712010-12-14 14:59:18 +00002557 encode_compound_hdr(xdr, req, &hdr);
2558 encode_sequence(xdr, &args->seq_args, &hdr);
2559 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002560 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002561}
2562
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002563/*
2564 * Encode GETDEVICEINFO request
2565 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002566static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2567 struct xdr_stream *xdr,
2568 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002569{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002570 struct compound_hdr hdr = {
2571 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2572 };
2573
Chuck Lever9f06c712010-12-14 14:59:18 +00002574 encode_compound_hdr(xdr, req, &hdr);
2575 encode_sequence(xdr, &args->seq_args, &hdr);
2576 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002577
2578 /* set up reply kvec. Subtract notification bitmap max size (2)
2579 * so that notification bitmap is put in xdr_buf tail */
2580 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2581 args->pdev->pages, args->pdev->pgbase,
2582 args->pdev->pglen);
2583
2584 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002585}
2586
2587/*
2588 * Encode LAYOUTGET request
2589 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002590static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2591 struct xdr_stream *xdr,
2592 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002593{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002594 struct compound_hdr hdr = {
2595 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2596 };
2597
Chuck Lever9f06c712010-12-14 14:59:18 +00002598 encode_compound_hdr(xdr, req, &hdr);
2599 encode_sequence(xdr, &args->seq_args, &hdr);
2600 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2601 encode_layoutget(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002602 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002603}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002604#endif /* CONFIG_NFS_V4_1 */
2605
Benny Halevy686841b2009-08-14 17:19:48 +03002606static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2607{
2608 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2609 "Remaining buffer length is %tu words.\n",
2610 func, xdr->end - xdr->p);
2611}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
Trond Myklebust683b57b2006-06-09 09:34:22 -04002613static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614{
Al Viro8687b632006-10-19 23:28:48 -07002615 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
Benny Halevyc0eae662009-08-14 17:20:14 +03002617 p = xdr_inline_decode(xdr, 4);
2618 if (unlikely(!p))
2619 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002620 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002621 p = xdr_inline_decode(xdr, *len);
2622 if (unlikely(!p))
2623 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 *string = (char *)p;
2625 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002626out_overflow:
2627 print_overflow_msg(__func__, xdr);
2628 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629}
2630
2631static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2632{
Al Viro8687b632006-10-19 23:28:48 -07002633 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
Benny Halevyc0eae662009-08-14 17:20:14 +03002635 p = xdr_inline_decode(xdr, 8);
2636 if (unlikely(!p))
2637 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002638 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002639 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002640
Benny Halevyc0eae662009-08-14 17:20:14 +03002641 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2642 if (unlikely(!p))
2643 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 hdr->tag = (char *)p;
2645 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002646 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002647 if (unlikely(hdr->nops < 1))
2648 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002650out_overflow:
2651 print_overflow_msg(__func__, xdr);
2652 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653}
2654
2655static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2656{
Al Viro8687b632006-10-19 23:28:48 -07002657 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 uint32_t opnum;
2659 int32_t nfserr;
2660
Benny Halevyc0eae662009-08-14 17:20:14 +03002661 p = xdr_inline_decode(xdr, 8);
2662 if (unlikely(!p))
2663 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002664 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002666 dprintk("nfs: Server returned operation"
2667 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 opnum, expected);
2669 return -EIO;
2670 }
Benny Halevycccddf42009-08-14 17:20:19 +03002671 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002673 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002675out_overflow:
2676 print_overflow_msg(__func__, xdr);
2677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678}
2679
2680/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002681static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
Al Viro8687b632006-10-19 23:28:48 -07002683 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002684 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 char *str;
2686
Benny Halevyc0eae662009-08-14 17:20:14 +03002687 p = xdr_inline_decode(xdr, 12);
2688 if (likely(p))
2689 return decode_opaque_inline(xdr, &strlen, &str);
2690 print_overflow_msg(__func__, xdr);
2691 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692}
2693
2694static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2695{
Al Viro8687b632006-10-19 23:28:48 -07002696 uint32_t bmlen;
2697 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
Benny Halevyc0eae662009-08-14 17:20:14 +03002699 p = xdr_inline_decode(xdr, 4);
2700 if (unlikely(!p))
2701 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002702 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
2704 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002705 p = xdr_inline_decode(xdr, (bmlen << 2));
2706 if (unlikely(!p))
2707 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002709 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002711 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 }
2713 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002714out_overflow:
2715 print_overflow_msg(__func__, xdr);
2716 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717}
2718
Al Viro8687b632006-10-19 23:28:48 -07002719static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720{
Al Viro8687b632006-10-19 23:28:48 -07002721 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Benny Halevyc0eae662009-08-14 17:20:14 +03002723 p = xdr_inline_decode(xdr, 4);
2724 if (unlikely(!p))
2725 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002726 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 *savep = xdr->p;
2728 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002729out_overflow:
2730 print_overflow_msg(__func__, xdr);
2731 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732}
2733
2734static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2735{
2736 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002737 int ret;
2738 ret = decode_attr_bitmap(xdr, bitmask);
2739 if (unlikely(ret < 0))
2740 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2742 } else
2743 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002744 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return 0;
2746}
2747
2748static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2749{
Al Viro8687b632006-10-19 23:28:48 -07002750 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002751 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
2753 *type = 0;
2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2755 return -EIO;
2756 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002757 p = xdr_inline_decode(xdr, 4);
2758 if (unlikely(!p))
2759 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002760 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002762 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 return -EIO;
2764 }
2765 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002766 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002768 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002769 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002770out_overflow:
2771 print_overflow_msg(__func__, xdr);
2772 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773}
2774
2775static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2776{
Al Viro8687b632006-10-19 23:28:48 -07002777 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002778 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779
2780 *change = 0;
2781 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2782 return -EIO;
2783 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002784 p = xdr_inline_decode(xdr, 8);
2785 if (unlikely(!p))
2786 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002787 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002789 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002791 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002793 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002794out_overflow:
2795 print_overflow_msg(__func__, xdr);
2796 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797}
2798
2799static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2800{
Al Viro8687b632006-10-19 23:28:48 -07002801 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002802 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
2804 *size = 0;
2805 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2806 return -EIO;
2807 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002808 p = xdr_inline_decode(xdr, 8);
2809 if (unlikely(!p))
2810 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002811 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002813 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002815 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002816 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002817out_overflow:
2818 print_overflow_msg(__func__, xdr);
2819 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820}
2821
2822static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2823{
Al Viro8687b632006-10-19 23:28:48 -07002824 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826 *res = 0;
2827 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2828 return -EIO;
2829 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002830 p = xdr_inline_decode(xdr, 4);
2831 if (unlikely(!p))
2832 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002833 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2835 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002836 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002838out_overflow:
2839 print_overflow_msg(__func__, xdr);
2840 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841}
2842
2843static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2844{
Al Viro8687b632006-10-19 23:28:48 -07002845 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
2847 *res = 0;
2848 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2849 return -EIO;
2850 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002851 p = xdr_inline_decode(xdr, 4);
2852 if (unlikely(!p))
2853 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002854 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2856 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002857 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002859out_overflow:
2860 print_overflow_msg(__func__, xdr);
2861 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862}
2863
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002864static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865{
Al Viro8687b632006-10-19 23:28:48 -07002866 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002867 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868
2869 fsid->major = 0;
2870 fsid->minor = 0;
2871 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2872 return -EIO;
2873 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002874 p = xdr_inline_decode(xdr, 16);
2875 if (unlikely(!p))
2876 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002877 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002878 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002880 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002882 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 (unsigned long long)fsid->major,
2884 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002885 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002886out_overflow:
2887 print_overflow_msg(__func__, xdr);
2888 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889}
2890
2891static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2892{
Al Viro8687b632006-10-19 23:28:48 -07002893 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
2895 *res = 60;
2896 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2897 return -EIO;
2898 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002899 p = xdr_inline_decode(xdr, 4);
2900 if (unlikely(!p))
2901 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002902 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2904 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002905 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002907out_overflow:
2908 print_overflow_msg(__func__, xdr);
2909 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910}
2911
Bryan Schumakerae42c702010-10-21 16:33:17 -04002912static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2913{
2914 __be32 *p;
2915
2916 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2917 return -EIO;
2918 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2919 p = xdr_inline_decode(xdr, 4);
2920 if (unlikely(!p))
2921 goto out_overflow;
2922 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2923 }
2924 return 0;
2925out_overflow:
2926 print_overflow_msg(__func__, xdr);
2927 return -EIO;
2928}
2929
2930static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2931{
2932 __be32 *p;
2933 int len;
2934
Trond Myklebust7ad07352010-10-23 15:34:20 -04002935 if (fh != NULL)
2936 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002937
2938 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2939 return -EIO;
2940 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2941 p = xdr_inline_decode(xdr, 4);
2942 if (unlikely(!p))
2943 goto out_overflow;
2944 len = be32_to_cpup(p);
2945 if (len > NFS4_FHSIZE)
2946 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002947 p = xdr_inline_decode(xdr, len);
2948 if (unlikely(!p))
2949 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002950 if (fh != NULL) {
2951 memcpy(fh->data, p, len);
2952 fh->size = len;
2953 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04002954 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2955 }
2956 return 0;
2957out_overflow:
2958 print_overflow_msg(__func__, xdr);
2959 return -EIO;
2960}
2961
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2963{
Al Viro8687b632006-10-19 23:28:48 -07002964 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965
2966 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2967 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2968 return -EIO;
2969 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002970 p = xdr_inline_decode(xdr, 4);
2971 if (unlikely(!p))
2972 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002973 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2975 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002976 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002978out_overflow:
2979 print_overflow_msg(__func__, xdr);
2980 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981}
2982
2983static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2984{
Al Viro8687b632006-10-19 23:28:48 -07002985 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002986 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987
2988 *fileid = 0;
2989 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2990 return -EIO;
2991 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002992 p = xdr_inline_decode(xdr, 8);
2993 if (unlikely(!p))
2994 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002995 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002997 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002999 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003000 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003001out_overflow:
3002 print_overflow_msg(__func__, xdr);
3003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004}
3005
Manoj Naik99baf622006-06-09 09:34:24 -04003006static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3007{
Al Viro8687b632006-10-19 23:28:48 -07003008 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003009 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003010
3011 *fileid = 0;
3012 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3013 return -EIO;
3014 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, 8);
3016 if (unlikely(!p))
3017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003018 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003019 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003020 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003021 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003022 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003023 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003024out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003027}
3028
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3030{
Al Viro8687b632006-10-19 23:28:48 -07003031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 int status = 0;
3033
3034 *res = 0;
3035 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3036 return -EIO;
3037 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003038 p = xdr_inline_decode(xdr, 8);
3039 if (unlikely(!p))
3040 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003041 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3043 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003044 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003046out_overflow:
3047 print_overflow_msg(__func__, xdr);
3048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049}
3050
3051static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3052{
Al Viro8687b632006-10-19 23:28:48 -07003053 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 int status = 0;
3055
3056 *res = 0;
3057 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3058 return -EIO;
3059 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003060 p = xdr_inline_decode(xdr, 8);
3061 if (unlikely(!p))
3062 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003063 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3065 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003066 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003068out_overflow:
3069 print_overflow_msg(__func__, xdr);
3070 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071}
3072
3073static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3074{
Al Viro8687b632006-10-19 23:28:48 -07003075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 int status = 0;
3077
3078 *res = 0;
3079 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3080 return -EIO;
3081 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003082 p = xdr_inline_decode(xdr, 8);
3083 if (unlikely(!p))
3084 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003085 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3087 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003088 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003090out_overflow:
3091 print_overflow_msg(__func__, xdr);
3092 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093}
3094
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003095static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3096{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003097 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003098 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003099 int status = 0;
3100
Benny Halevyc0eae662009-08-14 17:20:14 +03003101 p = xdr_inline_decode(xdr, 4);
3102 if (unlikely(!p))
3103 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003104 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003105 if (n == 0)
3106 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003107 dprintk("path ");
3108 path->ncomponents = 0;
3109 while (path->ncomponents < n) {
3110 struct nfs4_string *component = &path->components[path->ncomponents];
3111 status = decode_opaque_inline(xdr, &component->len, &component->data);
3112 if (unlikely(status != 0))
3113 goto out_eio;
3114 if (path->ncomponents != n)
3115 dprintk("/");
3116 dprintk("%s", component->data);
3117 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3118 path->ncomponents++;
3119 else {
3120 dprintk("cannot parse %d components in path\n", n);
3121 goto out_eio;
3122 }
3123 }
3124out:
3125 dprintk("\n");
3126 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003127root_path:
3128/* a root pathname is sent as a zero component4 */
3129 path->ncomponents = 1;
3130 path->components[0].len=0;
3131 path->components[0].data=NULL;
3132 dprintk("path /\n");
3133 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003134out_eio:
3135 dprintk(" status %d", status);
3136 status = -EIO;
3137 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003138out_overflow:
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003141}
3142
3143static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003144{
3145 int n;
Al Viro8687b632006-10-19 23:28:48 -07003146 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003147 int status = -EIO;
3148
3149 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3150 goto out;
3151 status = 0;
3152 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3153 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003154 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003155 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003156 if (unlikely(status != 0))
3157 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158 p = xdr_inline_decode(xdr, 4);
3159 if (unlikely(!p))
3160 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003161 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003162 if (n <= 0)
3163 goto out_eio;
3164 res->nlocations = 0;
3165 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003166 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003167 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003168
Benny Halevyc0eae662009-08-14 17:20:14 +03003169 p = xdr_inline_decode(xdr, 4);
3170 if (unlikely(!p))
3171 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003172 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003173
3174 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003175 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003176 while (loc->nservers < m) {
3177 struct nfs4_string *server = &loc->servers[loc->nservers];
3178 status = decode_opaque_inline(xdr, &server->len, &server->data);
3179 if (unlikely(status != 0))
3180 goto out_eio;
3181 dprintk("%s ", server->data);
3182 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3183 loc->nservers++;
3184 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003185 unsigned int i;
3186 dprintk("%s: using first %u of %u servers "
3187 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003188 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003189 NFS4_FS_LOCATION_MAXSERVERS,
3190 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003191 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003192 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003193 char *data;
3194 status = decode_opaque_inline(xdr, &len, &data);
3195 if (unlikely(status != 0))
3196 goto out_eio;
3197 }
3198 }
3199 }
3200 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003201 if (unlikely(status != 0))
3202 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003203 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003204 res->nlocations++;
3205 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003206 if (res->nlocations != 0)
3207 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003208out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003209 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003210 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003211out_overflow:
3212 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003213out_eio:
3214 status = -EIO;
3215 goto out;
3216}
3217
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3219{
Al Viro8687b632006-10-19 23:28:48 -07003220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 int status = 0;
3222
3223 *res = 0;
3224 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3225 return -EIO;
3226 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003227 p = xdr_inline_decode(xdr, 8);
3228 if (unlikely(!p))
3229 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003230 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3232 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003233 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003235out_overflow:
3236 print_overflow_msg(__func__, xdr);
3237 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238}
3239
3240static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3241{
Al Viro8687b632006-10-19 23:28:48 -07003242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 int status = 0;
3244
3245 *maxlink = 1;
3246 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3247 return -EIO;
3248 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003249 p = xdr_inline_decode(xdr, 4);
3250 if (unlikely(!p))
3251 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003252 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3254 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003255 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003257out_overflow:
3258 print_overflow_msg(__func__, xdr);
3259 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260}
3261
3262static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3263{
Al Viro8687b632006-10-19 23:28:48 -07003264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 int status = 0;
3266
3267 *maxname = 1024;
3268 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3269 return -EIO;
3270 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003271 p = xdr_inline_decode(xdr, 4);
3272 if (unlikely(!p))
3273 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003274 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3276 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003277 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003279out_overflow:
3280 print_overflow_msg(__func__, xdr);
3281 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282}
3283
3284static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3285{
Al Viro8687b632006-10-19 23:28:48 -07003286 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 int status = 0;
3288
3289 *res = 1024;
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3291 return -EIO;
3292 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3293 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003294 p = xdr_inline_decode(xdr, 8);
3295 if (unlikely(!p))
3296 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003297 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 if (maxread > 0x7FFFFFFF)
3299 maxread = 0x7FFFFFFF;
3300 *res = (uint32_t)maxread;
3301 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3302 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003303 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003305out_overflow:
3306 print_overflow_msg(__func__, xdr);
3307 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308}
3309
3310static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3311{
Al Viro8687b632006-10-19 23:28:48 -07003312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 int status = 0;
3314
3315 *res = 1024;
3316 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3317 return -EIO;
3318 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3319 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003320 p = xdr_inline_decode(xdr, 8);
3321 if (unlikely(!p))
3322 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003323 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 if (maxwrite > 0x7FFFFFFF)
3325 maxwrite = 0x7FFFFFFF;
3326 *res = (uint32_t)maxwrite;
3327 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3328 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003329 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003331out_overflow:
3332 print_overflow_msg(__func__, xdr);
3333 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334}
3335
Trond Myklebustbca79472009-03-11 14:10:26 -04003336static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337{
Trond Myklebustbca79472009-03-11 14:10:26 -04003338 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003339 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 *mode = 0;
3343 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003346 p = xdr_inline_decode(xdr, 4);
3347 if (unlikely(!p))
3348 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003349 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003350 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003352 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003354 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003356out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359}
3360
3361static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3362{
Al Viro8687b632006-10-19 23:28:48 -07003363 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003364 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
3366 *nlink = 1;
3367 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3368 return -EIO;
3369 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003370 p = xdr_inline_decode(xdr, 4);
3371 if (unlikely(!p))
3372 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003373 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003375 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003377 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003378 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382}
3383
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003384static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3385 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386{
Al Viro8687b632006-10-19 23:28:48 -07003387 uint32_t len;
3388 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003389 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390
3391 *uid = -2;
3392 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3393 return -EIO;
3394 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003395 p = xdr_inline_decode(xdr, 4);
3396 if (unlikely(!p))
3397 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003398 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003399 p = xdr_inline_decode(xdr, len);
3400 if (unlikely(!p))
3401 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003402 if (!may_sleep) {
3403 /* do nothing */
3404 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003405 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3406 ret = NFS_ATTR_FATTR_OWNER;
3407 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003409 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003411 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003412 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3414 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003415 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003416 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003417out_overflow:
3418 print_overflow_msg(__func__, xdr);
3419 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420}
3421
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003422static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3423 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424{
Al Viro8687b632006-10-19 23:28:48 -07003425 uint32_t len;
3426 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003427 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
3429 *gid = -2;
3430 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3431 return -EIO;
3432 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003433 p = xdr_inline_decode(xdr, 4);
3434 if (unlikely(!p))
3435 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003436 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003437 p = xdr_inline_decode(xdr, len);
3438 if (unlikely(!p))
3439 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003440 if (!may_sleep) {
3441 /* do nothing */
3442 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003443 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3444 ret = NFS_ATTR_FATTR_GROUP;
3445 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003447 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003449 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003450 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3452 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003453 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003454 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003455out_overflow:
3456 print_overflow_msg(__func__, xdr);
3457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458}
3459
3460static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3461{
Al Viro8687b632006-10-19 23:28:48 -07003462 uint32_t major = 0, minor = 0;
3463 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003464 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465
3466 *rdev = MKDEV(0,0);
3467 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3468 return -EIO;
3469 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3470 dev_t tmp;
3471
Benny Halevyc0eae662009-08-14 17:20:14 +03003472 p = xdr_inline_decode(xdr, 8);
3473 if (unlikely(!p))
3474 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003475 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003476 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 tmp = MKDEV(major, minor);
3478 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3479 *rdev = tmp;
3480 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003481 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003483 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003484 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003485out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488}
3489
3490static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3491{
Al Viro8687b632006-10-19 23:28:48 -07003492 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 int status = 0;
3494
3495 *res = 0;
3496 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3497 return -EIO;
3498 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003499 p = xdr_inline_decode(xdr, 8);
3500 if (unlikely(!p))
3501 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003502 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3504 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003505 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003507out_overflow:
3508 print_overflow_msg(__func__, xdr);
3509 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510}
3511
3512static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3513{
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 int status = 0;
3516
3517 *res = 0;
3518 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3519 return -EIO;
3520 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003521 p = xdr_inline_decode(xdr, 8);
3522 if (unlikely(!p))
3523 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003524 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3526 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003527 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003529out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532}
3533
3534static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3535{
Al Viro8687b632006-10-19 23:28:48 -07003536 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 int status = 0;
3538
3539 *res = 0;
3540 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3541 return -EIO;
3542 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003543 p = xdr_inline_decode(xdr, 8);
3544 if (unlikely(!p))
3545 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003546 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3548 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003549 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003551out_overflow:
3552 print_overflow_msg(__func__, xdr);
3553 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554}
3555
3556static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3557{
Al Viro8687b632006-10-19 23:28:48 -07003558 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003559 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560
3561 *used = 0;
3562 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3563 return -EIO;
3564 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, 8);
3566 if (unlikely(!p))
3567 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003568 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003570 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003572 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003574 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003575out_overflow:
3576 print_overflow_msg(__func__, xdr);
3577 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578}
3579
3580static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3581{
Al Viro8687b632006-10-19 23:28:48 -07003582 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 uint64_t sec;
3584 uint32_t nsec;
3585
Benny Halevyc0eae662009-08-14 17:20:14 +03003586 p = xdr_inline_decode(xdr, 12);
3587 if (unlikely(!p))
3588 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003589 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003590 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 time->tv_sec = (time_t)sec;
3592 time->tv_nsec = (long)nsec;
3593 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003594out_overflow:
3595 print_overflow_msg(__func__, xdr);
3596 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597}
3598
3599static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3600{
3601 int status = 0;
3602
3603 time->tv_sec = 0;
3604 time->tv_nsec = 0;
3605 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3606 return -EIO;
3607 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3608 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003609 if (status == 0)
3610 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3612 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003613 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 return status;
3615}
3616
3617static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3618{
3619 int status = 0;
3620
3621 time->tv_sec = 0;
3622 time->tv_nsec = 0;
3623 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3624 return -EIO;
3625 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3626 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003627 if (status == 0)
3628 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3630 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003631 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 return status;
3633}
3634
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003635static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3636 struct timespec *time)
3637{
3638 int status = 0;
3639
3640 time->tv_sec = 0;
3641 time->tv_nsec = 0;
3642 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3643 return -EIO;
3644 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3645 status = decode_attr_time(xdr, time);
3646 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3647 }
3648 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3649 (long)time->tv_nsec);
3650 return status;
3651}
3652
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3654{
3655 int status = 0;
3656
3657 time->tv_sec = 0;
3658 time->tv_nsec = 0;
3659 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3660 return -EIO;
3661 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3662 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003663 if (status == 0)
3664 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3666 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003667 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 return status;
3669}
3670
Al Viro8687b632006-10-19 23:28:48 -07003671static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672{
3673 unsigned int attrwords = XDR_QUADLEN(attrlen);
3674 unsigned int nwords = xdr->p - savep;
3675
3676 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003677 dprintk("%s: server returned incorrect attribute length: "
3678 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003679 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 attrwords << 2,
3681 (attrwords < nwords) ? '<' : '>',
3682 nwords << 2);
3683 return -EIO;
3684 }
3685 return 0;
3686}
3687
3688static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3689{
Al Viro8687b632006-10-19 23:28:48 -07003690 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
Benny Halevyc0eae662009-08-14 17:20:14 +03003692 p = xdr_inline_decode(xdr, 20);
3693 if (unlikely(!p))
3694 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003695 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003696 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003697 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003699out_overflow:
3700 print_overflow_msg(__func__, xdr);
3701 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702}
3703
3704static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3705{
Al Viro8687b632006-10-19 23:28:48 -07003706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 uint32_t supp, acc;
3708 int status;
3709
3710 status = decode_op_hdr(xdr, OP_ACCESS);
3711 if (status)
3712 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003713 p = xdr_inline_decode(xdr, 8);
3714 if (unlikely(!p))
3715 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003716 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003717 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 access->supported = supp;
3719 access->access = acc;
3720 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003721out_overflow:
3722 print_overflow_msg(__func__, xdr);
3723 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724}
3725
Benny Halevy07d30432009-08-14 17:19:52 +03003726static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727{
Al Viro8687b632006-10-19 23:28:48 -07003728 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003729
3730 p = xdr_inline_decode(xdr, len);
3731 if (likely(p)) {
3732 memcpy(buf, p, len);
3733 return 0;
3734 }
3735 print_overflow_msg(__func__, xdr);
3736 return -EIO;
3737}
3738
3739static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3740{
3741 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742}
3743
3744static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3745{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 int status;
3747
3748 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003749 if (status != -EIO)
3750 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003751 if (!status)
3752 status = decode_stateid(xdr, &res->stateid);
3753 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754}
3755
Benny Halevydb942bb2009-08-14 17:19:56 +03003756static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3757{
3758 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
3761static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3762{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 int status;
3764
3765 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003766 if (!status)
3767 status = decode_verifier(xdr, res->verf->verifier);
3768 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
3771static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3772{
Al Viro8687b632006-10-19 23:28:48 -07003773 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 uint32_t bmlen;
3775 int status;
3776
3777 status = decode_op_hdr(xdr, OP_CREATE);
3778 if (status)
3779 return status;
3780 if ((status = decode_change_info(xdr, cinfo)))
3781 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003782 p = xdr_inline_decode(xdr, 4);
3783 if (unlikely(!p))
3784 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003785 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003786 p = xdr_inline_decode(xdr, bmlen << 2);
3787 if (likely(p))
3788 return 0;
3789out_overflow:
3790 print_overflow_msg(__func__, xdr);
3791 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792}
3793
3794static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3795{
Al Viro8687b632006-10-19 23:28:48 -07003796 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003797 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 int status;
3799
3800 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3801 goto xdr_error;
3802 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3803 goto xdr_error;
3804 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3805 goto xdr_error;
3806 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3807 goto xdr_error;
3808 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3809 goto xdr_error;
3810 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3811 goto xdr_error;
3812 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3813 goto xdr_error;
3814 status = verify_attr_len(xdr, savep, attrlen);
3815xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003816 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 return status;
3818}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003819
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3821{
Al Viro8687b632006-10-19 23:28:48 -07003822 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003823 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003825
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3827 goto xdr_error;
3828 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3829 goto xdr_error;
3830 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3831 goto xdr_error;
3832
3833 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3834 goto xdr_error;
3835 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3836 goto xdr_error;
3837 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3838 goto xdr_error;
3839 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3840 goto xdr_error;
3841 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3842 goto xdr_error;
3843 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3844 goto xdr_error;
3845
3846 status = verify_attr_len(xdr, savep, attrlen);
3847xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003848 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 return status;
3850}
3851
3852static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3853{
Al Viro8687b632006-10-19 23:28:48 -07003854 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003855 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003857
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3859 goto xdr_error;
3860 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3861 goto xdr_error;
3862 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3863 goto xdr_error;
3864
3865 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3866 goto xdr_error;
3867 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3868 goto xdr_error;
3869
3870 status = verify_attr_len(xdr, savep, attrlen);
3871xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003872 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 return status;
3874}
3875
Bryan Schumakerae42c702010-10-21 16:33:17 -04003876static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3877 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003878 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879{
Trond Myklebustbca79472009-03-11 14:10:26 -04003880 int status;
3881 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003882 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003883 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003885 status = decode_attr_type(xdr, bitmap, &type);
3886 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003888 fattr->mode = 0;
3889 if (status != 0) {
3890 fattr->mode |= nfs_type2fmt[type];
3891 fattr->valid |= status;
3892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003894 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3895 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003898
3899 status = decode_attr_size(xdr, bitmap, &fattr->size);
3900 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003902 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003903
3904 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3905 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003907 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003908
Bryan Schumakerae42c702010-10-21 16:33:17 -04003909 status = decode_attr_error(xdr, bitmap);
3910 if (status < 0)
3911 goto xdr_error;
3912
3913 status = decode_attr_filehandle(xdr, bitmap, fh);
3914 if (status < 0)
3915 goto xdr_error;
3916
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003917 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3918 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003921
3922 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003923 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003924 fattr));
3925 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003926 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003927 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003928
3929 status = decode_attr_mode(xdr, bitmap, &fmode);
3930 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003932 if (status != 0) {
3933 fattr->mode |= fmode;
3934 fattr->valid |= status;
3935 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003936
3937 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3938 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003940 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003941
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003942 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3943 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003944 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003946 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003947
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003948 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3949 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003950 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003952 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003953
3954 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3955 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003957 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003958
3959 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3960 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003962 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003963
3964 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3965 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003967 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003968
3969 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3970 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003972 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003973
3974 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3975 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003977 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003978
3979 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3980 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003981 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04003982 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003983 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003984 fattr->valid |= status;
3985 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003986
Bryan Schumakerae42c702010-10-21 16:33:17 -04003987xdr_error:
3988 dprintk("%s: xdr returned %d\n", __func__, -status);
3989 return status;
3990}
3991
3992static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3993 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3994{
3995 __be32 *savep;
3996 uint32_t attrlen,
3997 bitmap[2] = {0};
3998 int status;
3999
4000 status = decode_op_hdr(xdr, OP_GETATTR);
4001 if (status < 0)
4002 goto xdr_error;
4003
4004 status = decode_attr_bitmap(xdr, bitmap);
4005 if (status < 0)
4006 goto xdr_error;
4007
4008 status = decode_attr_length(xdr, &attrlen, &savep);
4009 if (status < 0)
4010 goto xdr_error;
4011
4012 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4013 if (status < 0)
4014 goto xdr_error;
4015
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004016 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004018 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 return status;
4020}
4021
Bryan Schumakerae42c702010-10-21 16:33:17 -04004022static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4023 const struct nfs_server *server, int may_sleep)
4024{
4025 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4026}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027
Andy Adamson504913f2010-10-20 00:17:57 -04004028/*
4029 * Decode potentially multiple layout types. Currently we only support
4030 * one layout driver per file system.
4031 */
4032static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4033 uint32_t *layouttype)
4034{
4035 uint32_t *p;
4036 int num;
4037
4038 p = xdr_inline_decode(xdr, 4);
4039 if (unlikely(!p))
4040 goto out_overflow;
4041 num = be32_to_cpup(p);
4042
4043 /* pNFS is not supported by the underlying file system */
4044 if (num == 0) {
4045 *layouttype = 0;
4046 return 0;
4047 }
4048 if (num > 1)
4049 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4050 "per filesystem not supported\n", __func__);
4051
4052 /* Decode and set first layout type, move xdr->p past unused types */
4053 p = xdr_inline_decode(xdr, num * 4);
4054 if (unlikely(!p))
4055 goto out_overflow;
4056 *layouttype = be32_to_cpup(p);
4057 return 0;
4058out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
4061}
4062
4063/*
4064 * The type of file system exported.
4065 * Note we must ensure that layouttype is set in any non-error case.
4066 */
4067static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4068 uint32_t *layouttype)
4069{
4070 int status = 0;
4071
4072 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4073 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4074 return -EIO;
4075 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4076 status = decode_first_pnfs_layout_type(xdr, layouttype);
4077 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4078 } else
4079 *layouttype = 0;
4080 return status;
4081}
4082
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4084{
Al Viro8687b632006-10-19 23:28:48 -07004085 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 uint32_t attrlen, bitmap[2];
4087 int status;
4088
4089 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4090 goto xdr_error;
4091 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4092 goto xdr_error;
4093 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4094 goto xdr_error;
4095
4096 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4097
4098 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4099 goto xdr_error;
4100 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4101 goto xdr_error;
4102 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4103 goto xdr_error;
4104 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4105 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4106 goto xdr_error;
4107 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004108 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4109 if (status != 0)
4110 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004111 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4112 if (status != 0)
4113 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114
4115 status = verify_attr_len(xdr, savep, attrlen);
4116xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004117 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 return status;
4119}
4120
4121static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4122{
Al Viro8687b632006-10-19 23:28:48 -07004123 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 uint32_t len;
4125 int status;
4126
Trond Myklebust99367812007-07-17 21:52:41 -04004127 /* Zero handle first to allow comparisons */
4128 memset(fh, 0, sizeof(*fh));
4129
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 status = decode_op_hdr(xdr, OP_GETFH);
4131 if (status)
4132 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133
Benny Halevyc0eae662009-08-14 17:20:14 +03004134 p = xdr_inline_decode(xdr, 4);
4135 if (unlikely(!p))
4136 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004137 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 if (len > NFS4_FHSIZE)
4139 return -EIO;
4140 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004141 p = xdr_inline_decode(xdr, len);
4142 if (unlikely(!p))
4143 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004144 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004146out_overflow:
4147 print_overflow_msg(__func__, xdr);
4148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149}
4150
4151static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4152{
4153 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 status = decode_op_hdr(xdr, OP_LINK);
4156 if (status)
4157 return status;
4158 return decode_change_info(xdr, cinfo);
4159}
4160
4161/*
4162 * We create the owner, so we know a proper owner.id length is 4.
4163 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004164static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004166 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004167 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004168 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004170 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004171 if (unlikely(!p))
4172 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004173 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004174 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004175 type = be32_to_cpup(p++); /* 4 byte read */
4176 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004177 fl->fl_start = (loff_t)offset;
4178 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4179 if (length == ~(uint64_t)0)
4180 fl->fl_end = OFFSET_MAX;
4181 fl->fl_type = F_WRLCK;
4182 if (type & 1)
4183 fl->fl_type = F_RDLCK;
4184 fl->fl_pid = 0;
4185 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004186 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4187 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4188 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004189 if (likely(p))
4190 return -NFS4ERR_DENIED;
4191out_overflow:
4192 print_overflow_msg(__func__, xdr);
4193 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194}
4195
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004196static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 int status;
4199
4200 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004201 if (status == -EIO)
4202 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004204 status = decode_stateid(xdr, &res->stateid);
4205 if (unlikely(status))
4206 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004208 status = decode_lock_denied(xdr, NULL);
4209 if (res->open_seqid != NULL)
4210 nfs_increment_open_seqid(status, res->open_seqid);
4211 nfs_increment_lock_seqid(status, res->lock_seqid);
4212out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 return status;
4214}
4215
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004216static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217{
4218 int status;
4219 status = decode_op_hdr(xdr, OP_LOCKT);
4220 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004221 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 return status;
4223}
4224
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004225static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 int status;
4228
4229 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004230 if (status != -EIO)
4231 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004232 if (status == 0)
4233 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 return status;
4235}
4236
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004237static int decode_release_lockowner(struct xdr_stream *xdr)
4238{
4239 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4240}
4241
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242static int decode_lookup(struct xdr_stream *xdr)
4243{
4244 return decode_op_hdr(xdr, OP_LOOKUP);
4245}
4246
4247/* This is too sick! */
4248static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4249{
Andy Adamson05d564f2008-12-23 16:06:15 -05004250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251 uint32_t limit_type, nblocks, blocksize;
4252
Benny Halevyc0eae662009-08-14 17:20:14 +03004253 p = xdr_inline_decode(xdr, 12);
4254 if (unlikely(!p))
4255 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004256 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004258 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004259 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004260 break;
4261 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004262 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004263 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004264 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 }
4266 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004267out_overflow:
4268 print_overflow_msg(__func__, xdr);
4269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270}
4271
4272static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4273{
Andy Adamson05d564f2008-12-23 16:06:15 -05004274 __be32 *p;
4275 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004276 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
Benny Halevyc0eae662009-08-14 17:20:14 +03004278 p = xdr_inline_decode(xdr, 4);
4279 if (unlikely(!p))
4280 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004281 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4283 res->delegation_type = 0;
4284 return 0;
4285 }
Benny Halevy07d30432009-08-14 17:19:52 +03004286 status = decode_stateid(xdr, &res->delegation);
4287 if (unlikely(status))
4288 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004289 p = xdr_inline_decode(xdr, 4);
4290 if (unlikely(!p))
4291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004292 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004293
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004295 case NFS4_OPEN_DELEGATE_READ:
4296 res->delegation_type = FMODE_READ;
4297 break;
4298 case NFS4_OPEN_DELEGATE_WRITE:
4299 res->delegation_type = FMODE_WRITE|FMODE_READ;
4300 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 return -EIO;
4302 }
David Howells7539bba2006-08-22 20:06:09 -04004303 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004304out_overflow:
4305 print_overflow_msg(__func__, xdr);
4306 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307}
4308
4309static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4310{
Andy Adamson05d564f2008-12-23 16:06:15 -05004311 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004312 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004313 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314
Andy Adamson05d564f2008-12-23 16:06:15 -05004315 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004316 if (status != -EIO)
4317 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004318 if (!status)
4319 status = decode_stateid(xdr, &res->stateid);
4320 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004321 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322
Andy Adamson05d564f2008-12-23 16:06:15 -05004323 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
Benny Halevyc0eae662009-08-14 17:20:14 +03004325 p = xdr_inline_decode(xdr, 8);
4326 if (unlikely(!p))
4327 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004328 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004329 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004330 if (bmlen > 10)
4331 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332
Benny Halevyc0eae662009-08-14 17:20:14 +03004333 p = xdr_inline_decode(xdr, bmlen << 2);
4334 if (unlikely(!p))
4335 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004336 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4337 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004338 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004339 for (; i < NFS4_BITMAP_SIZE; i++)
4340 res->attrset[i] = 0;
4341
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 return decode_delegation(xdr, res);
4343xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004344 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004346out_overflow:
4347 print_overflow_msg(__func__, xdr);
4348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349}
4350
4351static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 int status;
4354
Andy Adamson05d564f2008-12-23 16:06:15 -05004355 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004356 if (status != -EIO)
4357 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004358 if (!status)
4359 status = decode_stateid(xdr, &res->stateid);
4360 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361}
4362
4363static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 int status;
4366
4367 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004368 if (status != -EIO)
4369 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004370 if (!status)
4371 status = decode_stateid(xdr, &res->stateid);
4372 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373}
4374
4375static int decode_putfh(struct xdr_stream *xdr)
4376{
4377 return decode_op_hdr(xdr, OP_PUTFH);
4378}
4379
4380static int decode_putrootfh(struct xdr_stream *xdr)
4381{
4382 return decode_op_hdr(xdr, OP_PUTROOTFH);
4383}
4384
4385static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4386{
4387 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 uint32_t count, eof, recvd, hdrlen;
4390 int status;
4391
4392 status = decode_op_hdr(xdr, OP_READ);
4393 if (status)
4394 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004395 p = xdr_inline_decode(xdr, 8);
4396 if (unlikely(!p))
4397 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004398 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004399 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004400 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 recvd = req->rq_rcv_buf.len - hdrlen;
4402 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004403 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 "count %u > recvd %u\n", count, recvd);
4405 count = recvd;
4406 eof = 0;
4407 }
4408 xdr_read_pages(xdr, count);
4409 res->eof = eof;
4410 res->count = count;
4411 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004412out_overflow:
4413 print_overflow_msg(__func__, xdr);
4414 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415}
4416
4417static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4418{
4419 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004421 size_t hdrlen;
4422 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004423 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424
4425 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004426 if (!status)
4427 status = decode_verifier(xdr, readdir->verifier.data);
4428 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004430 dprintk("%s: verifier = %08x:%08x\n",
4431 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004432 ((u32 *)readdir->verifier.data)[0],
4433 ((u32 *)readdir->verifier.data)[1]);
4434
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435
Benny Halevydb942bb2009-08-14 17:19:56 +03004436 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 recvd = rcvbuf->len - hdrlen;
4438 if (pglen > recvd)
4439 pglen = recvd;
4440 xdr_read_pages(xdr, pglen);
4441
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004442
Trond Myklebustac396122010-11-15 20:26:22 -05004443 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444}
4445
4446static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4447{
4448 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4449 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004450 size_t hdrlen;
4451 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 int status;
4454
4455 status = decode_op_hdr(xdr, OP_READLINK);
4456 if (status)
4457 return status;
4458
4459 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004460 p = xdr_inline_decode(xdr, 4);
4461 if (unlikely(!p))
4462 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004463 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004465 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 return -ENAMETOOLONG;
4467 }
4468 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4469 recvd = req->rq_rcv_buf.len - hdrlen;
4470 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004471 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 "count %u > recvd %u\n", len, recvd);
4473 return -EIO;
4474 }
4475 xdr_read_pages(xdr, len);
4476 /*
4477 * The XDR encode routine has set things up so that
4478 * the link text will be copied directly into the
4479 * buffer. We just have to do overflow-checking,
4480 * and and null-terminate the text (the VFS expects
4481 * null-termination).
4482 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004483 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004485out_overflow:
4486 print_overflow_msg(__func__, xdr);
4487 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488}
4489
4490static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4491{
4492 int status;
4493
4494 status = decode_op_hdr(xdr, OP_REMOVE);
4495 if (status)
4496 goto out;
4497 status = decode_change_info(xdr, cinfo);
4498out:
4499 return status;
4500}
4501
4502static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4503 struct nfs4_change_info *new_cinfo)
4504{
4505 int status;
4506
4507 status = decode_op_hdr(xdr, OP_RENAME);
4508 if (status)
4509 goto out;
4510 if ((status = decode_change_info(xdr, old_cinfo)))
4511 goto out;
4512 status = decode_change_info(xdr, new_cinfo);
4513out:
4514 return status;
4515}
4516
4517static int decode_renew(struct xdr_stream *xdr)
4518{
4519 return decode_op_hdr(xdr, OP_RENEW);
4520}
4521
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004522static int
4523decode_restorefh(struct xdr_stream *xdr)
4524{
4525 return decode_op_hdr(xdr, OP_RESTOREFH);
4526}
4527
J. Bruce Fields029d1052005-06-22 17:16:22 +00004528static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4529 size_t *acl_len)
4530{
Al Viro8687b632006-10-19 23:28:48 -07004531 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004532 uint32_t attrlen,
4533 bitmap[2] = {0};
4534 struct kvec *iov = req->rq_rcv_buf.head;
4535 int status;
4536
4537 *acl_len = 0;
4538 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4539 goto out;
4540 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4541 goto out;
4542 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4543 goto out;
4544
4545 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4546 return -EIO;
4547 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004548 size_t hdrlen;
4549 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004550
4551 /* We ignore &savep and don't do consistency checks on
4552 * the attr length. Let userspace figure it out.... */
4553 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4554 recvd = req->rq_rcv_buf.len - hdrlen;
4555 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004556 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004557 " acl reply: attrlen %u > recvd %u\n",
4558 attrlen, recvd);
4559 return -EINVAL;
4560 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004561 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004562 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004563 } else
4564 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004565
4566out:
4567 return status;
4568}
4569
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570static int
4571decode_savefh(struct xdr_stream *xdr)
4572{
4573 return decode_op_hdr(xdr, OP_SAVEFH);
4574}
4575
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004576static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577{
Al Viro8687b632006-10-19 23:28:48 -07004578 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 uint32_t bmlen;
4580 int status;
4581
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 status = decode_op_hdr(xdr, OP_SETATTR);
4583 if (status)
4584 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004585 p = xdr_inline_decode(xdr, 4);
4586 if (unlikely(!p))
4587 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004588 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004589 p = xdr_inline_decode(xdr, bmlen << 2);
4590 if (likely(p))
4591 return 0;
4592out_overflow:
4593 print_overflow_msg(__func__, xdr);
4594 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595}
4596
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004597static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598{
Al Viro8687b632006-10-19 23:28:48 -07004599 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 uint32_t opnum;
4601 int32_t nfserr;
4602
Benny Halevyc0eae662009-08-14 17:20:14 +03004603 p = xdr_inline_decode(xdr, 8);
4604 if (unlikely(!p))
4605 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004606 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004608 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004609 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 return -EIO;
4611 }
Benny Halevycccddf42009-08-14 17:20:19 +03004612 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004614 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4615 if (unlikely(!p))
4616 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004617 p = xdr_decode_hyper(p, &res->clientid);
4618 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 } else if (nfserr == NFSERR_CLID_INUSE) {
4620 uint32_t len;
4621
4622 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004623 p = xdr_inline_decode(xdr, 4);
4624 if (unlikely(!p))
4625 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004626 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004627 p = xdr_inline_decode(xdr, len);
4628 if (unlikely(!p))
4629 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630
4631 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004632 p = xdr_inline_decode(xdr, 4);
4633 if (unlikely(!p))
4634 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004635 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004636 p = xdr_inline_decode(xdr, len);
4637 if (unlikely(!p))
4638 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 return -NFSERR_CLID_INUSE;
4640 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004641 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642
4643 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004644out_overflow:
4645 print_overflow_msg(__func__, xdr);
4646 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647}
4648
4649static int decode_setclientid_confirm(struct xdr_stream *xdr)
4650{
4651 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4652}
4653
4654static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4655{
Al Viro8687b632006-10-19 23:28:48 -07004656 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 int status;
4658
4659 status = decode_op_hdr(xdr, OP_WRITE);
4660 if (status)
4661 return status;
4662
Benny Halevyc0eae662009-08-14 17:20:14 +03004663 p = xdr_inline_decode(xdr, 16);
4664 if (unlikely(!p))
4665 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004666 res->count = be32_to_cpup(p++);
4667 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004668 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004670out_overflow:
4671 print_overflow_msg(__func__, xdr);
4672 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673}
4674
4675static int decode_delegreturn(struct xdr_stream *xdr)
4676{
4677 return decode_op_hdr(xdr, OP_DELEGRETURN);
4678}
4679
Benny Halevy99fe60d2009-04-01 09:22:29 -04004680#if defined(CONFIG_NFS_V4_1)
4681static int decode_exchange_id(struct xdr_stream *xdr,
4682 struct nfs41_exchange_id_res *res)
4683{
4684 __be32 *p;
4685 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004686 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004687 int status;
4688 struct nfs_client *clp = res->client;
4689
4690 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4691 if (status)
4692 return status;
4693
Benny Halevyc0eae662009-08-14 17:20:14 +03004694 p = xdr_inline_decode(xdr, 8);
4695 if (unlikely(!p))
4696 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004697 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004698 p = xdr_inline_decode(xdr, 12);
4699 if (unlikely(!p))
4700 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004701 clp->cl_seqid = be32_to_cpup(p++);
4702 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004703
4704 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004705 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004706 if (dummy != SP4_NONE)
4707 return -EIO;
4708
4709 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004710 p = xdr_inline_decode(xdr, 8);
4711 if (unlikely(!p))
4712 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004713
4714 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004715 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4716 if (unlikely(status))
4717 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004718
4719 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004720 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4721 if (unlikely(status))
4722 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004723
4724 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004725 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4726 if (unlikely(status))
4727 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004728
4729 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004730out_overflow:
4731 print_overflow_msg(__func__, xdr);
4732 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004733}
Andy Adamsonfc931582009-04-01 09:22:31 -04004734
4735static int decode_chan_attrs(struct xdr_stream *xdr,
4736 struct nfs4_channel_attrs *attrs)
4737{
4738 __be32 *p;
4739 u32 nr_attrs;
4740
Benny Halevyc0eae662009-08-14 17:20:14 +03004741 p = xdr_inline_decode(xdr, 28);
4742 if (unlikely(!p))
4743 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004744 attrs->headerpadsz = be32_to_cpup(p++);
4745 attrs->max_rqst_sz = be32_to_cpup(p++);
4746 attrs->max_resp_sz = be32_to_cpup(p++);
4747 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4748 attrs->max_ops = be32_to_cpup(p++);
4749 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004750 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004751 if (unlikely(nr_attrs > 1)) {
4752 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4753 __func__, nr_attrs);
4754 return -EINVAL;
4755 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004756 if (nr_attrs == 1) {
4757 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4758 if (unlikely(!p))
4759 goto out_overflow;
4760 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004761 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004762out_overflow:
4763 print_overflow_msg(__func__, xdr);
4764 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004765}
4766
Benny Halevye78291e2009-08-14 17:20:00 +03004767static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4768{
4769 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004770}
4771
4772static int decode_create_session(struct xdr_stream *xdr,
4773 struct nfs41_create_session_res *res)
4774{
4775 __be32 *p;
4776 int status;
4777 struct nfs_client *clp = res->client;
4778 struct nfs4_session *session = clp->cl_session;
4779
4780 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004781 if (!status)
4782 status = decode_sessionid(xdr, &session->sess_id);
4783 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004784 return status;
4785
Andy Adamsonfc931582009-04-01 09:22:31 -04004786 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004787 p = xdr_inline_decode(xdr, 8);
4788 if (unlikely(!p))
4789 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004790 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004791 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004792
4793 /* Channel attributes */
4794 status = decode_chan_attrs(xdr, &session->fc_attrs);
4795 if (!status)
4796 status = decode_chan_attrs(xdr, &session->bc_attrs);
4797 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004798out_overflow:
4799 print_overflow_msg(__func__, xdr);
4800 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004801}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004802
4803static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4804{
4805 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4806}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004807
4808static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4809{
4810 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4811}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004812#endif /* CONFIG_NFS_V4_1 */
4813
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004814static int decode_sequence(struct xdr_stream *xdr,
4815 struct nfs4_sequence_res *res,
4816 struct rpc_rqst *rqstp)
4817{
4818#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004819 struct nfs4_sessionid id;
4820 u32 dummy;
4821 int status;
4822 __be32 *p;
4823
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004824 if (!res->sr_session)
4825 return 0;
4826
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004827 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004828 if (!status)
4829 status = decode_sessionid(xdr, &id);
4830 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004831 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004832
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004833 /*
4834 * If the server returns different values for sessionID, slotID or
4835 * sequence number, the server is looney tunes.
4836 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004837 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004838
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004839 if (memcmp(id.data, res->sr_session->sess_id.data,
4840 NFS4_MAX_SESSIONID_LEN)) {
4841 dprintk("%s Invalid session id\n", __func__);
4842 goto out_err;
4843 }
Benny Halevye78291e2009-08-14 17:20:00 +03004844
Benny Halevyc0eae662009-08-14 17:20:14 +03004845 p = xdr_inline_decode(xdr, 20);
4846 if (unlikely(!p))
4847 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004848
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004849 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004850 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004851 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004852 dprintk("%s Invalid sequence number\n", __func__);
4853 goto out_err;
4854 }
4855 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004856 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004857 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004858 dprintk("%s Invalid slot id\n", __func__);
4859 goto out_err;
4860 }
4861 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004862 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004863 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004864 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004865 /* result flags */
4866 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004867 status = 0;
4868out_err:
4869 res->sr_status = status;
4870 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004871out_overflow:
4872 print_overflow_msg(__func__, xdr);
4873 status = -EIO;
4874 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004875#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004876 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004877#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004878}
4879
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004880#if defined(CONFIG_NFS_V4_1)
4881
4882static int decode_getdeviceinfo(struct xdr_stream *xdr,
4883 struct pnfs_device *pdev)
4884{
4885 __be32 *p;
4886 uint32_t len, type;
4887 int status;
4888
4889 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4890 if (status) {
4891 if (status == -ETOOSMALL) {
4892 p = xdr_inline_decode(xdr, 4);
4893 if (unlikely(!p))
4894 goto out_overflow;
4895 pdev->mincount = be32_to_cpup(p);
4896 dprintk("%s: Min count too small. mincnt = %u\n",
4897 __func__, pdev->mincount);
4898 }
4899 return status;
4900 }
4901
4902 p = xdr_inline_decode(xdr, 8);
4903 if (unlikely(!p))
4904 goto out_overflow;
4905 type = be32_to_cpup(p++);
4906 if (type != pdev->layout_type) {
4907 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4908 __func__, pdev->layout_type, type);
4909 return -EINVAL;
4910 }
4911 /*
4912 * Get the length of the opaque device_addr4. xdr_read_pages places
4913 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4914 * and places the remaining xdr data in xdr_buf->tail
4915 */
4916 pdev->mincount = be32_to_cpup(p);
4917 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4918
4919 /* Parse notification bitmap, verifying that it is zero. */
4920 p = xdr_inline_decode(xdr, 4);
4921 if (unlikely(!p))
4922 goto out_overflow;
4923 len = be32_to_cpup(p);
4924 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00004925 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004926
4927 p = xdr_inline_decode(xdr, 4 * len);
4928 if (unlikely(!p))
4929 goto out_overflow;
4930 for (i = 0; i < len; i++, p++) {
4931 if (be32_to_cpup(p)) {
4932 dprintk("%s: notifications not supported\n",
4933 __func__);
4934 return -EIO;
4935 }
4936 }
4937 }
4938 return 0;
4939out_overflow:
4940 print_overflow_msg(__func__, xdr);
4941 return -EIO;
4942}
4943
4944static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
4945 struct nfs4_layoutget_res *res)
4946{
4947 __be32 *p;
4948 int status;
4949 u32 layout_count;
4950
4951 status = decode_op_hdr(xdr, OP_LAYOUTGET);
4952 if (status)
4953 return status;
4954 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
4955 if (unlikely(!p))
4956 goto out_overflow;
4957 res->return_on_close = be32_to_cpup(p++);
4958 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
4959 layout_count = be32_to_cpup(p);
4960 if (!layout_count) {
4961 dprintk("%s: server responded with empty layout array\n",
4962 __func__);
4963 return -EINVAL;
4964 }
4965
4966 p = xdr_inline_decode(xdr, 24);
4967 if (unlikely(!p))
4968 goto out_overflow;
4969 p = xdr_decode_hyper(p, &res->range.offset);
4970 p = xdr_decode_hyper(p, &res->range.length);
4971 res->range.iomode = be32_to_cpup(p++);
4972 res->type = be32_to_cpup(p++);
4973
4974 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
4975 if (unlikely(status))
4976 return status;
4977
4978 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
4979 __func__,
4980 (unsigned long)res->range.offset,
4981 (unsigned long)res->range.length,
4982 res->range.iomode,
4983 res->type,
4984 res->layout.len);
4985
4986 /* nfs4_proc_layoutget allocated a single page */
4987 if (res->layout.len > PAGE_SIZE)
4988 return -ENOMEM;
4989 memcpy(res->layout.buf, p, res->layout.len);
4990
4991 if (layout_count > 1) {
4992 /* We only handle a length one array at the moment. Any
4993 * further entries are just ignored. Note that this means
4994 * the client may see a response that is less than the
4995 * minimum it requested.
4996 */
4997 dprintk("%s: server responded with %d layouts, dropping tail\n",
4998 __func__, layout_count);
4999 }
5000
5001 return 0;
5002out_overflow:
5003 print_overflow_msg(__func__, xdr);
5004 return -EIO;
5005}
5006#endif /* CONFIG_NFS_V4_1 */
5007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008/*
Benny Halevy49c25592008-12-23 16:06:16 -05005009 * END OF "GENERIC" DECODE ROUTINES.
5010 */
5011
5012/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 * Decode OPEN_DOWNGRADE response
5014 */
Chuck Leverbf269552010-12-14 14:59:29 +00005015static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5016 struct xdr_stream *xdr,
5017 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018{
Andy Adamson05d564f2008-12-23 16:06:15 -05005019 struct compound_hdr hdr;
5020 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021
Chuck Leverbf269552010-12-14 14:59:29 +00005022 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005023 if (status)
5024 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005025 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005026 if (status)
5027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005028 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005029 if (status)
5030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005031 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005032 if (status != 0)
5033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005034 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005035 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005037 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038}
5039
5040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 * Decode ACCESS response
5042 */
Chuck Leverbf269552010-12-14 14:59:29 +00005043static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5044 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 struct compound_hdr hdr;
5047 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005048
Chuck Leverbf269552010-12-14 14:59:29 +00005049 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005050 if (status)
5051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005052 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005053 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005055 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005056 if (status != 0)
5057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005058 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005059 if (status != 0)
5060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005061 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005062 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063out:
5064 return status;
5065}
5066
5067/*
5068 * Decode LOOKUP response
5069 */
Chuck Leverbf269552010-12-14 14:59:29 +00005070static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5071 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 struct compound_hdr hdr;
5074 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005075
Chuck Leverbf269552010-12-14 14:59:29 +00005076 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005077 if (status)
5078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005079 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005080 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005082 status = decode_putfh(xdr);
5083 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005085 status = decode_lookup(xdr);
5086 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005088 status = decode_getfh(xdr, res->fh);
5089 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005091 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005092 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093out:
5094 return status;
5095}
5096
5097/*
5098 * Decode LOOKUP_ROOT response
5099 */
Chuck Leverbf269552010-12-14 14:59:29 +00005100static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5101 struct xdr_stream *xdr,
5102 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 struct compound_hdr hdr;
5105 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005106
Chuck Leverbf269552010-12-14 14:59:29 +00005107 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005108 if (status)
5109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005110 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005111 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005113 status = decode_putrootfh(xdr);
5114 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005116 status = decode_getfh(xdr, res->fh);
5117 if (status == 0)
5118 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005119 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120out:
5121 return status;
5122}
5123
5124/*
5125 * Decode REMOVE response
5126 */
Chuck Leverbf269552010-12-14 14:59:29 +00005127static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5128 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 struct compound_hdr hdr;
5131 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005132
Chuck Leverbf269552010-12-14 14:59:29 +00005133 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005134 if (status)
5135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005136 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005137 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005139 status = decode_putfh(xdr);
5140 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005142 status = decode_remove(xdr, &res->cinfo);
5143 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005145 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005146 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147out:
5148 return status;
5149}
5150
5151/*
5152 * Decode RENAME response
5153 */
Chuck Leverbf269552010-12-14 14:59:29 +00005154static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5155 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 struct compound_hdr hdr;
5158 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005159
Chuck Leverbf269552010-12-14 14:59:29 +00005160 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005161 if (status)
5162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005163 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005164 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005166 status = decode_putfh(xdr);
5167 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005169 status = decode_savefh(xdr);
5170 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005172 status = decode_putfh(xdr);
5173 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005175 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5176 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005177 goto out;
5178 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005179 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005180 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005182 status = decode_restorefh(xdr);
5183 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005185 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005186 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187out:
5188 return status;
5189}
5190
5191/*
5192 * Decode LINK response
5193 */
Chuck Leverbf269552010-12-14 14:59:29 +00005194static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5195 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 struct compound_hdr hdr;
5198 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005199
Chuck Leverbf269552010-12-14 14:59:29 +00005200 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005201 if (status)
5202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005203 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005204 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005206 status = decode_putfh(xdr);
5207 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005209 status = decode_savefh(xdr);
5210 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005212 status = decode_putfh(xdr);
5213 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005215 status = decode_link(xdr, &res->cinfo);
5216 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005217 goto out;
5218 /*
5219 * Note order: OP_LINK leaves the directory as the current
5220 * filehandle.
5221 */
Chuck Leverbf269552010-12-14 14:59:29 +00005222 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005223 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005225 status = decode_restorefh(xdr);
5226 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005228 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005229 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230out:
5231 return status;
5232}
5233
5234/*
5235 * Decode CREATE response
5236 */
Chuck Leverbf269552010-12-14 14:59:29 +00005237static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5238 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 struct compound_hdr hdr;
5241 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005242
Chuck Leverbf269552010-12-14 14:59:29 +00005243 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005244 if (status)
5245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005246 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005247 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005249 status = decode_putfh(xdr);
5250 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005252 status = decode_savefh(xdr);
5253 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005255 status = decode_create(xdr, &res->dir_cinfo);
5256 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005258 status = decode_getfh(xdr, res->fh);
5259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005261 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005262 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005264 status = decode_restorefh(xdr);
5265 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005267 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005268 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269out:
5270 return status;
5271}
5272
5273/*
5274 * Decode SYMLINK response
5275 */
Chuck Leverbf269552010-12-14 14:59:29 +00005276static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5277 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278{
Chuck Leverbf269552010-12-14 14:59:29 +00005279 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280}
5281
5282/*
5283 * Decode GETATTR response
5284 */
Chuck Leverbf269552010-12-14 14:59:29 +00005285static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5286 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 struct compound_hdr hdr;
5289 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005290
Chuck Leverbf269552010-12-14 14:59:29 +00005291 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292 if (status)
5293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005294 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005295 if (status)
5296 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005297 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 if (status)
5299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005300 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005301 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302out:
5303 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304}
5305
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005306/*
5307 * Encode an SETACL request
5308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005309static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5310 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005311{
Andy Adamson05d564f2008-12-23 16:06:15 -05005312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005314 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005315
Chuck Lever9f06c712010-12-14 14:59:18 +00005316 encode_compound_hdr(xdr, req, &hdr);
5317 encode_sequence(xdr, &args->seq_args, &hdr);
5318 encode_putfh(xdr, args->fh, &hdr);
5319 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005320 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005321}
Andy Adamson05d564f2008-12-23 16:06:15 -05005322
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005323/*
5324 * Decode SETACL response
5325 */
5326static int
Chuck Leverbf269552010-12-14 14:59:29 +00005327nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005328 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005329{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005330 struct compound_hdr hdr;
5331 int status;
5332
Chuck Leverbf269552010-12-14 14:59:29 +00005333 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005334 if (status)
5335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005336 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005337 if (status)
5338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005339 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005340 if (status)
5341 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005342 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005343out:
5344 return status;
5345}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346
5347/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005348 * Decode GETACL response
5349 */
5350static int
Chuck Leverbf269552010-12-14 14:59:29 +00005351nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005352 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005353{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005354 struct compound_hdr hdr;
5355 int status;
5356
Chuck Leverbf269552010-12-14 14:59:29 +00005357 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005358 if (status)
5359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005360 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005361 if (status)
5362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005363 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005364 if (status)
5365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005366 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005367
5368out:
5369 return status;
5370}
5371
5372/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 * Decode CLOSE response
5374 */
Chuck Leverbf269552010-12-14 14:59:29 +00005375static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5376 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377{
Andy Adamson05d564f2008-12-23 16:06:15 -05005378 struct compound_hdr hdr;
5379 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380
Chuck Leverbf269552010-12-14 14:59:29 +00005381 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005382 if (status)
5383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005384 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005385 if (status)
5386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005387 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005388 if (status)
5389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005390 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005391 if (status != 0)
5392 goto out;
5393 /*
5394 * Note: Server may do delete on close for this file
5395 * in which case the getattr call will fail with
5396 * an ESTALE error. Shouldn't be a problem,
5397 * though, since fattr->valid will remain unset.
5398 */
Chuck Leverbf269552010-12-14 14:59:29 +00005399 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005400 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005402 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403}
5404
5405/*
5406 * Decode OPEN response
5407 */
Chuck Leverbf269552010-12-14 14:59:29 +00005408static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5409 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410{
Andy Adamson05d564f2008-12-23 16:06:15 -05005411 struct compound_hdr hdr;
5412 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413
Chuck Leverbf269552010-12-14 14:59:29 +00005414 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005415 if (status)
5416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005417 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005418 if (status)
5419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005420 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005421 if (status)
5422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005423 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005424 if (status)
5425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005426 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005427 if (status)
5428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005429 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005431 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005432 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005434 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005436 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005437 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005439 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440}
5441
5442/*
5443 * Decode OPEN_CONFIRM response
5444 */
Chuck Leverbf269552010-12-14 14:59:29 +00005445static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5446 struct xdr_stream *xdr,
5447 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448{
Andy Adamson05d564f2008-12-23 16:06:15 -05005449 struct compound_hdr hdr;
5450 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451
Chuck Leverbf269552010-12-14 14:59:29 +00005452 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005453 if (status)
5454 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005455 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005456 if (status)
5457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005458 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005460 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461}
5462
5463/*
5464 * Decode OPEN response
5465 */
Chuck Leverbf269552010-12-14 14:59:29 +00005466static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5467 struct xdr_stream *xdr,
5468 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005469{
Andy Adamson05d564f2008-12-23 16:06:15 -05005470 struct compound_hdr hdr;
5471 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472
Chuck Leverbf269552010-12-14 14:59:29 +00005473 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005474 if (status)
5475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005476 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005477 if (status)
5478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005479 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005480 if (status)
5481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005482 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005483 if (status)
5484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005485 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005486 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005488 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489}
5490
5491/*
5492 * Decode SETATTR response
5493 */
Chuck Leverbf269552010-12-14 14:59:29 +00005494static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5495 struct xdr_stream *xdr,
5496 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497{
Andy Adamson05d564f2008-12-23 16:06:15 -05005498 struct compound_hdr hdr;
5499 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005500
Chuck Leverbf269552010-12-14 14:59:29 +00005501 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005502 if (status)
5503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005504 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005505 if (status)
5506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005507 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005508 if (status)
5509 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005510 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005511 if (status)
5512 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005513 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005514 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005516 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517}
5518
5519/*
5520 * Decode LOCK response
5521 */
Chuck Leverbf269552010-12-14 14:59:29 +00005522static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5523 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525 struct compound_hdr hdr;
5526 int status;
5527
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529 if (status)
5530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005531 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005532 if (status)
5533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005534 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 if (status)
5536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005537 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538out:
5539 return status;
5540}
5541
5542/*
5543 * Decode LOCKT response
5544 */
Chuck Leverbf269552010-12-14 14:59:29 +00005545static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5546 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548 struct compound_hdr hdr;
5549 int status;
5550
Chuck Leverbf269552010-12-14 14:59:29 +00005551 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552 if (status)
5553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005554 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005555 if (status)
5556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005557 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558 if (status)
5559 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005560 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561out:
5562 return status;
5563}
5564
5565/*
5566 * Decode LOCKU response
5567 */
Chuck Leverbf269552010-12-14 14:59:29 +00005568static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5569 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005570{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571 struct compound_hdr hdr;
5572 int status;
5573
Chuck Leverbf269552010-12-14 14:59:29 +00005574 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575 if (status)
5576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005577 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005578 if (status)
5579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005580 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005581 if (status)
5582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005583 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005584out:
5585 return status;
5586}
5587
Chuck Leverbf269552010-12-14 14:59:29 +00005588static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5589 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005590{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005591 struct compound_hdr hdr;
5592 int status;
5593
Chuck Leverbf269552010-12-14 14:59:29 +00005594 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005595 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005596 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005597 return status;
5598}
5599
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600/*
5601 * Decode READLINK response
5602 */
Chuck Leverbf269552010-12-14 14:59:29 +00005603static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5604 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005605 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005606{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607 struct compound_hdr hdr;
5608 int status;
5609
Chuck Leverbf269552010-12-14 14:59:29 +00005610 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611 if (status)
5612 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005613 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005614 if (status)
5615 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005616 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005617 if (status)
5618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005619 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620out:
5621 return status;
5622}
5623
5624/*
5625 * Decode READDIR response
5626 */
Chuck Leverbf269552010-12-14 14:59:29 +00005627static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5628 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005629{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 struct compound_hdr hdr;
5631 int status;
5632
Chuck Leverbf269552010-12-14 14:59:29 +00005633 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634 if (status)
5635 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005636 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005637 if (status)
5638 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005639 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640 if (status)
5641 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005642 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643out:
5644 return status;
5645}
5646
5647/*
5648 * Decode Read response
5649 */
Chuck Leverbf269552010-12-14 14:59:29 +00005650static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5651 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653 struct compound_hdr hdr;
5654 int status;
5655
Chuck Leverbf269552010-12-14 14:59:29 +00005656 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005657 if (status)
5658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005659 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005660 if (status)
5661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005662 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663 if (status)
5664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005665 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666 if (!status)
5667 status = res->count;
5668out:
5669 return status;
5670}
5671
5672/*
5673 * Decode WRITE response
5674 */
Chuck Leverbf269552010-12-14 14:59:29 +00005675static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5676 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678 struct compound_hdr hdr;
5679 int status;
5680
Chuck Leverbf269552010-12-14 14:59:29 +00005681 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682 if (status)
5683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005684 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005685 if (status)
5686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005687 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 if (status)
5689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005690 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005691 if (status)
5692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005693 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005694 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 if (!status)
5696 status = res->count;
5697out:
5698 return status;
5699}
5700
5701/*
5702 * Decode COMMIT response
5703 */
Chuck Leverbf269552010-12-14 14:59:29 +00005704static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5705 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005707 struct compound_hdr hdr;
5708 int status;
5709
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 if (status)
5712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005713 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005714 if (status)
5715 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005716 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717 if (status)
5718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005719 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005720 if (status)
5721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005722 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005723 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724out:
5725 return status;
5726}
5727
5728/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005729 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730 */
Chuck Leverbf269552010-12-14 14:59:29 +00005731static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005732 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 struct compound_hdr hdr;
5735 int status;
5736
Chuck Leverbf269552010-12-14 14:59:29 +00005737 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005738 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005739 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005740 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005741 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005743 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005744 return status;
5745}
5746
5747/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005748 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749 */
Chuck Leverbf269552010-12-14 14:59:29 +00005750static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005751 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 struct compound_hdr hdr;
5754 int status;
5755
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005758 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005759 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005760 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 return status;
5764}
5765
5766/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005767 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768 */
Chuck Leverbf269552010-12-14 14:59:29 +00005769static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04005770 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772 struct compound_hdr hdr;
5773 int status;
5774
Chuck Leverbf269552010-12-14 14:59:29 +00005775 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005777 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005778 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005781 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782 return status;
5783}
5784
5785/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005786 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787 */
Chuck Leverbf269552010-12-14 14:59:29 +00005788static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5789 struct xdr_stream *xdr,
5790 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005792 struct compound_hdr hdr;
5793 int status;
5794
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005796 if (status)
5797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005798 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005799 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005800 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005801 status = decode_putfh(xdr);
5802 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005804 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805out:
5806 return status;
5807}
5808
5809/*
5810 * Decode RENEW response
5811 */
Chuck Leverbf269552010-12-14 14:59:29 +00005812static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5813 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815 struct compound_hdr hdr;
5816 int status;
5817
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005820 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821 return status;
5822}
5823
5824/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005825 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826 */
Chuck Leverbf269552010-12-14 14:59:29 +00005827static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5828 struct xdr_stream *xdr,
5829 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 struct compound_hdr hdr;
5832 int status;
5833
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005836 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837 return status;
5838}
5839
5840/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005841 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 */
Chuck Leverbf269552010-12-14 14:59:29 +00005843static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5844 struct xdr_stream *xdr,
5845 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 struct compound_hdr hdr;
5848 int status;
5849
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005852 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 return status;
5858}
5859
5860/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005861 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 */
Chuck Leverbf269552010-12-14 14:59:29 +00005863static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5864 struct xdr_stream *xdr,
5865 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 struct compound_hdr hdr;
5868 int status;
5869
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005871 if (status)
5872 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005873 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005874 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005875 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01005877 if (status != 0)
5878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005880 if (status != 0)
5881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005882 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005883 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005884out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 return status;
5886}
5887
Trond Myklebust683b57b2006-06-09 09:34:22 -04005888/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005889 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005890 */
Chuck Leverbf269552010-12-14 14:59:29 +00005891static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
5892 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04005893 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005894{
Trond Myklebust683b57b2006-06-09 09:34:22 -04005895 struct compound_hdr hdr;
5896 int status;
5897
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005899 if (status)
5900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005902 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005903 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005904 status = decode_putfh(xdr);
5905 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005906 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005907 status = decode_lookup(xdr);
5908 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005910 xdr_enter_page(xdr, PAGE_SIZE);
5911 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005912 res->fs_locations->server,
5913 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005914out:
5915 return status;
5916}
5917
Benny Halevy99fe60d2009-04-01 09:22:29 -04005918#if defined(CONFIG_NFS_V4_1)
5919/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005920 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005921 */
Chuck Leverbf269552010-12-14 14:59:29 +00005922static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
5923 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04005924 void *res)
5925{
Benny Halevy99fe60d2009-04-01 09:22:29 -04005926 struct compound_hdr hdr;
5927 int status;
5928
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005930 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005931 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005932 return status;
5933}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005934
5935/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005936 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005937 */
Chuck Leverbf269552010-12-14 14:59:29 +00005938static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
5939 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04005940 struct nfs41_create_session_res *res)
5941{
Andy Adamsonfc931582009-04-01 09:22:31 -04005942 struct compound_hdr hdr;
5943 int status;
5944
Chuck Leverbf269552010-12-14 14:59:29 +00005945 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04005946 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04005948 return status;
5949}
5950
5951/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005952 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005953 */
Chuck Leverbf269552010-12-14 14:59:29 +00005954static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
5955 struct xdr_stream *xdr,
5956 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005957{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005958 struct compound_hdr hdr;
5959 int status;
5960
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005962 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005964 return status;
5965}
5966
5967/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005968 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005969 */
Chuck Leverbf269552010-12-14 14:59:29 +00005970static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
5971 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005972 struct nfs4_sequence_res *res)
5973{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005974 struct compound_hdr hdr;
5975 int status;
5976
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005978 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005979 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005980 return status;
5981}
5982
5983/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005984 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005985 */
Chuck Leverbf269552010-12-14 14:59:29 +00005986static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
5987 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04005988 struct nfs4_get_lease_time_res *res)
5989{
Andy Adamson2050f0c2009-04-01 09:22:30 -04005990 struct compound_hdr hdr;
5991 int status;
5992
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005994 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005996 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005998 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006000 return status;
6001}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006002
6003/*
6004 * Decode RECLAIM_COMPLETE response
6005 */
Chuck Leverbf269552010-12-14 14:59:29 +00006006static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6007 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006008 struct nfs41_reclaim_complete_res *res)
6009{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006010 struct compound_hdr hdr;
6011 int status;
6012
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006014 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006016 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006018 return status;
6019}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006020
6021/*
6022 * Decode GETDEVINFO response
6023 */
Chuck Leverbf269552010-12-14 14:59:29 +00006024static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6025 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006026 struct nfs4_getdeviceinfo_res *res)
6027{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006028 struct compound_hdr hdr;
6029 int status;
6030
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006032 if (status != 0)
6033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006035 if (status != 0)
6036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006038out:
6039 return status;
6040}
6041
6042/*
6043 * Decode LAYOUTGET response
6044 */
Chuck Leverbf269552010-12-14 14:59:29 +00006045static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6046 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006047 struct nfs4_layoutget_res *res)
6048{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006049 struct compound_hdr hdr;
6050 int status;
6051
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006053 if (status)
6054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006056 if (status)
6057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006059 if (status)
6060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006062out:
6063 return status;
6064}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006065#endif /* CONFIG_NFS_V4_1 */
6066
Chuck Lever573c4e12010-12-14 14:58:11 +00006067/**
6068 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6069 * the local page cache.
6070 * @xdr: XDR stream where entry resides
6071 * @entry: buffer to fill in with entry data
6072 * @plus: boolean indicating whether this should be a readdirplus entry
6073 *
6074 * Returns zero if successful, otherwise a negative errno value is
6075 * returned.
6076 *
6077 * This function is not invoked during READDIR reply decoding, but
6078 * rather whenever an application invokes the getdents(2) system call
6079 * on a directory already in our cache.
6080 */
6081int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6082 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083{
6084 uint32_t bitmap[2] = {0};
6085 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006086 __be32 *p = xdr_inline_decode(xdr, 4);
6087 if (unlikely(!p))
6088 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006089 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006090 p = xdr_inline_decode(xdr, 4);
6091 if (unlikely(!p))
6092 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006093 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006094 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006096 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 }
6098
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006099 p = xdr_inline_decode(xdr, 12);
6100 if (unlikely(!p))
6101 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 entry->prev_cookie = entry->cookie;
6103 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006104 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006105
Trond Myklebust9af8c222010-10-24 11:52:55 -04006106 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006107 if (unlikely(!p))
6108 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110
6111 /*
6112 * In case the server doesn't return an inode number,
6113 * we fake one here. (We don't use inode number 0,
6114 * since glibc seems to choke on it...)
6115 */
6116 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006117 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118
Trond Myklebust9af8c222010-10-24 11:52:55 -04006119 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006120 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006121
6122 if (decode_attr_length(xdr, &len, &p) < 0)
6123 goto out_overflow;
6124
Chuck Lever573c4e12010-12-14 14:58:11 +00006125 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6126 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006127 goto out_overflow;
6128 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6129 entry->ino = entry->fattr->fileid;
6130
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006131 entry->d_type = DT_UNKNOWN;
6132 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6133 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6134
Trond Myklebust9af8c222010-10-24 11:52:55 -04006135 if (verify_attr_len(xdr, p, len) < 0)
6136 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137
Chuck Lever573c4e12010-12-14 14:58:11 +00006138 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006139
6140out_overflow:
6141 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006142 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143}
6144
6145/*
6146 * We need to translate between nfs status return values and
6147 * the local errno values which may not be the same.
6148 */
6149static struct {
6150 int stat;
6151 int errno;
6152} nfs_errtbl[] = {
6153 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006154 { NFS4ERR_PERM, -EPERM },
6155 { NFS4ERR_NOENT, -ENOENT },
6156 { NFS4ERR_IO, -errno_NFSERR_IO},
6157 { NFS4ERR_NXIO, -ENXIO },
6158 { NFS4ERR_ACCESS, -EACCES },
6159 { NFS4ERR_EXIST, -EEXIST },
6160 { NFS4ERR_XDEV, -EXDEV },
6161 { NFS4ERR_NOTDIR, -ENOTDIR },
6162 { NFS4ERR_ISDIR, -EISDIR },
6163 { NFS4ERR_INVAL, -EINVAL },
6164 { NFS4ERR_FBIG, -EFBIG },
6165 { NFS4ERR_NOSPC, -ENOSPC },
6166 { NFS4ERR_ROFS, -EROFS },
6167 { NFS4ERR_MLINK, -EMLINK },
6168 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6169 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6170 { NFS4ERR_DQUOT, -EDQUOT },
6171 { NFS4ERR_STALE, -ESTALE },
6172 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6173 { NFS4ERR_BADOWNER, -EINVAL },
6174 { NFS4ERR_BADNAME, -EINVAL },
6175 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6176 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6177 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006178 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006179 { NFS4ERR_BADTYPE, -EBADTYPE },
6180 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006181 { NFS4ERR_SYMLINK, -ELOOP },
6182 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6183 { NFS4ERR_DEADLOCK, -EDEADLK },
6184 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 * to be handled by a
6186 * middle-layer.
6187 */
Benny Halevy856dff32008-03-31 17:39:06 +03006188 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189};
6190
6191/*
6192 * Convert an NFS error code to a local one.
6193 * This one is used jointly by NFSv2 and NFSv3.
6194 */
6195static int
David Howells0a8ea432006-08-22 20:06:08 -04006196nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197{
6198 int i;
6199 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6200 if (nfs_errtbl[i].stat == stat)
6201 return nfs_errtbl[i].errno;
6202 }
6203 if (stat <= 10000 || stat > 10100) {
6204 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006205 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 }
6207 /* If we cannot translate the error, the recovery routines should
6208 * handle it.
6209 * Note: remaining NFSv4 error codes have values > 10000, so should
6210 * not conflict with native Linux error codes.
6211 */
Benny Halevy856dff32008-03-31 17:39:06 +03006212 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213}
6214
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215#define PROC(proc, argtype, restype) \
6216[NFSPROC4_CLNT_##proc] = { \
6217 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006218 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006219 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006220 .p_arglen = NFS4_##argtype##_sz, \
6221 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006222 .p_statidx = NFSPROC4_CLNT_##proc, \
6223 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006224}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225
6226struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006227 PROC(READ, enc_read, dec_read),
6228 PROC(WRITE, enc_write, dec_write),
6229 PROC(COMMIT, enc_commit, dec_commit),
6230 PROC(OPEN, enc_open, dec_open),
6231 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6232 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6233 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6234 PROC(CLOSE, enc_close, dec_close),
6235 PROC(SETATTR, enc_setattr, dec_setattr),
6236 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6237 PROC(RENEW, enc_renew, dec_renew),
6238 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6239 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6240 PROC(LOCK, enc_lock, dec_lock),
6241 PROC(LOCKT, enc_lockt, dec_lockt),
6242 PROC(LOCKU, enc_locku, dec_locku),
6243 PROC(ACCESS, enc_access, dec_access),
6244 PROC(GETATTR, enc_getattr, dec_getattr),
6245 PROC(LOOKUP, enc_lookup, dec_lookup),
6246 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6247 PROC(REMOVE, enc_remove, dec_remove),
6248 PROC(RENAME, enc_rename, dec_rename),
6249 PROC(LINK, enc_link, dec_link),
6250 PROC(SYMLINK, enc_symlink, dec_symlink),
6251 PROC(CREATE, enc_create, dec_create),
6252 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6253 PROC(STATFS, enc_statfs, dec_statfs),
6254 PROC(READLINK, enc_readlink, dec_readlink),
6255 PROC(READDIR, enc_readdir, dec_readdir),
6256 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6257 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6258 PROC(GETACL, enc_getacl, dec_getacl),
6259 PROC(SETACL, enc_setacl, dec_setacl),
6260 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6261 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006262#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006263 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6264 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6265 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6266 PROC(SEQUENCE, enc_sequence, dec_sequence),
6267 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6268 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6269 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6270 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006271#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272};
6273
6274struct rpc_version nfs_version4 = {
6275 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006276 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 .procs = nfs4_procedures
6278};
6279
6280/*
6281 * Local variables:
6282 * c-basic-offset: 8
6283 * End:
6284 */