blob: 1a70097a8dc7225264b59a0dd4a04852ac9c3f29 [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>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040077#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050078#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400434 encode_open_maxsz + \
435 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400436 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400439 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400440 decode_open_maxsz + \
441 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400443#define NFS4_enc_open_confirm_sz \
444 (compound_encode_hdr_maxsz + \
445 encode_putfh_maxsz + \
446 encode_open_confirm_maxsz)
447#define NFS4_dec_open_confirm_sz \
448 (compound_decode_hdr_maxsz + \
449 decode_putfh_maxsz + \
450 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 encode_open_maxsz + \
455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 decode_open_maxsz + \
460 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_open_downgrade_sz \
462 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 encode_putfh_maxsz + \
465 encode_open_downgrade_maxsz + \
466 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_dec_open_downgrade_sz \
468 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 decode_putfh_maxsz + \
471 decode_open_downgrade_maxsz + \
472 decode_getattr_maxsz)
473#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 encode_putfh_maxsz + \
476 encode_close_maxsz + \
477 encode_getattr_maxsz)
478#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400480 decode_putfh_maxsz + \
481 decode_close_maxsz + \
482 decode_getattr_maxsz)
483#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400485 encode_putfh_maxsz + \
486 encode_setattr_maxsz + \
487 encode_getattr_maxsz)
488#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400490 decode_putfh_maxsz + \
491 decode_setattr_maxsz + \
492 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_putfh_maxsz + \
496 encode_fsinfo_maxsz)
497#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
500 decode_fsinfo_maxsz)
501#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
502 encode_renew_maxsz)
503#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
504 decode_renew_maxsz)
505#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
506 encode_setclientid_maxsz)
507#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
508 decode_setclientid_maxsz)
509#define NFS4_enc_setclientid_confirm_sz \
510 (compound_encode_hdr_maxsz + \
511 encode_setclientid_confirm_maxsz + \
512 encode_putrootfh_maxsz + \
513 encode_fsinfo_maxsz)
514#define NFS4_dec_setclientid_confirm_sz \
515 (compound_decode_hdr_maxsz + \
516 decode_setclientid_confirm_maxsz + \
517 decode_putrootfh_maxsz + \
518 decode_fsinfo_maxsz)
519#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400522 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400530 encode_lockt_maxsz)
531#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 decode_putfh_maxsz + \
534 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400538 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400542 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400543#define NFS4_enc_release_lockowner_sz \
544 (compound_encode_hdr_maxsz + \
545 encode_lockowner_maxsz)
546#define NFS4_dec_release_lockowner_sz \
547 (compound_decode_hdr_maxsz + \
548 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400552 encode_access_maxsz + \
553 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400557 decode_access_maxsz + \
558 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
562 encode_getattr_maxsz)
563#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 decode_putfh_maxsz + \
566 decode_getattr_maxsz)
567#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
570 encode_lookup_maxsz + \
571 encode_getattr_maxsz + \
572 encode_getfh_maxsz)
573#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400576 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_getattr_maxsz + \
578 decode_getfh_maxsz)
579#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putrootfh_maxsz + \
582 encode_getattr_maxsz + \
583 encode_getfh_maxsz)
584#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_putrootfh_maxsz + \
587 decode_getattr_maxsz + \
588 decode_getfh_maxsz)
589#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400592 encode_remove_maxsz + \
593 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_dec_remove_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 + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400597 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_savefh_maxsz + \
603 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400604 encode_rename_maxsz + \
605 encode_getattr_maxsz + \
606 encode_restorefh_maxsz + \
607 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_putfh_maxsz + \
611 decode_savefh_maxsz + \
612 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400613 decode_rename_maxsz + \
614 decode_getattr_maxsz + \
615 decode_restorefh_maxsz + \
616 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 encode_putfh_maxsz + \
620 encode_savefh_maxsz + \
621 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400622 encode_link_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400623 encode_getattr_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400624 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400625 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 decode_putfh_maxsz + \
629 decode_savefh_maxsz + \
630 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400631 decode_link_maxsz + \
632 decode_getattr_maxsz + \
633 decode_restorefh_maxsz + \
634 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_putfh_maxsz + \
638 encode_symlink_maxsz + \
639 encode_getattr_maxsz + \
640 encode_getfh_maxsz)
641#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 decode_putfh_maxsz + \
644 decode_symlink_maxsz + \
645 decode_getattr_maxsz + \
646 decode_getfh_maxsz)
647#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
650 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400651 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400652 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_putfh_maxsz + \
656 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400657 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
662 encode_getattr_maxsz)
663#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
666 decode_getattr_maxsz)
667#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400670 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400674 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800677 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 encode_getattr_maxsz)
679#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800681 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 decode_getattr_maxsz)
683#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100686 encode_delegreturn_maxsz + \
687 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400689 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100690 decode_delegreturn_maxsz + \
691 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000692#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400693 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000694 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400695 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000696#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400697 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000698 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400699 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000700#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000702 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400703 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000704#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000706 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400708#define NFS4_enc_fs_locations_sz \
709 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400711 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400712 encode_lookup_maxsz + \
713 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400714#define NFS4_dec_fs_locations_sz \
715 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400717 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400718 decode_lookup_maxsz + \
719 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000720#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
721 encode_sequence_maxsz + \
722 encode_putfh_maxsz + \
723 encode_secinfo_maxsz)
724#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
725 decode_sequence_maxsz + \
726 decode_putfh_maxsz + \
727 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400728#if defined(CONFIG_NFS_V4_1)
729#define NFS4_enc_exchange_id_sz \
730 (compound_encode_hdr_maxsz + \
731 encode_exchange_id_maxsz)
732#define NFS4_dec_exchange_id_sz \
733 (compound_decode_hdr_maxsz + \
734 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400735#define NFS4_enc_create_session_sz \
736 (compound_encode_hdr_maxsz + \
737 encode_create_session_maxsz)
738#define NFS4_dec_create_session_sz \
739 (compound_decode_hdr_maxsz + \
740 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400741#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
742 encode_destroy_session_maxsz)
743#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
744 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400745#define NFS4_enc_sequence_sz \
746 (compound_decode_hdr_maxsz + \
747 encode_sequence_maxsz)
748#define NFS4_dec_sequence_sz \
749 (compound_decode_hdr_maxsz + \
750 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400751#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz + \
753 encode_putrootfh_maxsz + \
754 encode_fsinfo_maxsz)
755#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
756 decode_sequence_maxsz + \
757 decode_putrootfh_maxsz + \
758 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500759#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
760 encode_sequence_maxsz + \
761 encode_reclaim_complete_maxsz)
762#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
763 decode_sequence_maxsz + \
764 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400765#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
766 encode_sequence_maxsz + \
767 encode_putfh_maxsz + \
768 encode_getdevicelist_maxsz)
769#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
770 decode_sequence_maxsz + \
771 decode_putfh_maxsz + \
772 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400773#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
774 encode_sequence_maxsz +\
775 encode_getdeviceinfo_maxsz)
776#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
777 decode_sequence_maxsz + \
778 decode_getdeviceinfo_maxsz)
779#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
780 encode_sequence_maxsz + \
781 encode_putfh_maxsz + \
782 encode_layoutget_maxsz)
783#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
784 decode_sequence_maxsz + \
785 decode_putfh_maxsz + \
786 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000787#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz +\
789 encode_putfh_maxsz + \
790 encode_layoutcommit_maxsz + \
791 encode_getattr_maxsz)
792#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
793 decode_sequence_maxsz + \
794 decode_putfh_maxsz + \
795 decode_layoutcommit_maxsz + \
796 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300797#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_layoutreturn_maxsz)
801#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400805#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_putrootfh_maxsz +\
808 encode_secinfo_no_name_maxsz)
809#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
810 decode_sequence_maxsz + \
811 decode_putrootfh_maxsz + \
812 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400813#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz + \
815 encode_test_stateid_maxsz)
816#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
817 decode_sequence_maxsz + \
818 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400819#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_free_stateid_maxsz)
822#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz + \
824 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500825
826const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
827 compound_encode_hdr_maxsz +
828 encode_sequence_maxsz +
829 encode_putfh_maxsz +
830 encode_getattr_maxsz) *
831 XDR_UNIT);
832
833const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
834 compound_decode_hdr_maxsz +
835 decode_sequence_maxsz +
836 decode_putfh_maxsz) *
837 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400838#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500840static unsigned short send_implementation_id = 1;
841
842module_param(send_implementation_id, ushort, 0644);
843MODULE_PARM_DESC(send_implementation_id,
844 "Send implementation ID with NFSv4.1 exchange_id");
845
Trond Myklebustbca79472009-03-11 14:10:26 -0400846static const umode_t nfs_type2fmt[] = {
847 [NF4BAD] = 0,
848 [NF4REG] = S_IFREG,
849 [NF4DIR] = S_IFDIR,
850 [NF4BLK] = S_IFBLK,
851 [NF4CHR] = S_IFCHR,
852 [NF4LNK] = S_IFLNK,
853 [NF4SOCK] = S_IFSOCK,
854 [NF4FIFO] = S_IFIFO,
855 [NF4ATTRDIR] = 0,
856 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857};
858
859struct compound_hdr {
860 int32_t status;
861 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500862 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 uint32_t taglen;
864 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400865 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400866 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867};
868
Benny Halevy13c65ce2009-08-14 17:19:25 +0300869static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
870{
871 __be32 *p = xdr_reserve_space(xdr, nbytes);
872 BUG_ON(!p);
873 return p;
874}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Trond Myklebustcb17e552012-03-04 18:13:56 -0500876static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
877{
878 __be32 *p;
879
880 p = xdr_reserve_space(xdr, len);
881 xdr_encode_opaque_fixed(p, buf, len);
882}
883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
885{
Al Viro8687b632006-10-19 23:28:48 -0700886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500888 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 xdr_encode_opaque(p, str, len);
890}
891
Trond Myklebust4ade9822012-03-04 18:13:57 -0500892static void encode_uint32(struct xdr_stream *xdr, u32 n)
893{
894 __be32 *p;
895
896 p = reserve_space(xdr, 4);
897 *p = cpu_to_be32(n);
898}
899
Trond Myklebustff2eb682012-03-05 11:40:12 -0500900static void encode_uint64(struct xdr_stream *xdr, u64 n)
901{
902 __be32 *p;
903
904 p = reserve_space(xdr, 8);
905 xdr_encode_hyper(p, n);
906}
907
Trond Myklebust4ade9822012-03-04 18:13:57 -0500908static void encode_nfs4_seqid(struct xdr_stream *xdr,
909 const struct nfs_seqid *seqid)
910{
911 encode_uint32(xdr, seqid->sequence->counter);
912}
913
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400914static void encode_compound_hdr(struct xdr_stream *xdr,
915 struct rpc_rqst *req,
916 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400919 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400920
921 /* initialize running count of expected bytes in reply.
922 * NOTE: the replied tag SHOULD be the same is the one sent,
923 * but this is not required as a MUST for the server to do so. */
924 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500927 encode_string(xdr, hdr->taglen, hdr->tag);
928 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300929 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500930 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300931 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500932}
933
Trond Myklebustab19b482012-03-04 18:13:57 -0500934static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
935 uint32_t replen,
936 struct compound_hdr *hdr)
937{
938 encode_uint32(xdr, op);
939 hdr->nops++;
940 hdr->replen += replen;
941}
942
Andy Adamsond0179312008-12-23 16:06:17 -0500943static void encode_nops(struct compound_hdr *hdr)
944{
Andy Adamsonfc931582009-04-01 09:22:31 -0400945 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500946 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500949static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
950{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500951 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500952}
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
955{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500956 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957}
958
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500959static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
961 char owner_name[IDMAP_NAMESZ];
962 char owner_group[IDMAP_NAMESZ];
963 int owner_namelen = 0;
964 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700965 __be32 *p;
966 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 int len;
968 uint32_t bmval0 = 0;
969 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 /*
972 * We reserve enough space to write the entire attribute buffer at once.
973 * In the worst-case, this would be
974 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
975 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000976 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 */
978 len = 16;
979
980 /* Sigh */
981 if (iap->ia_valid & ATTR_SIZE)
982 len += 8;
983 if (iap->ia_valid & ATTR_MODE)
984 len += 4;
985 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800986 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400988 dprintk("nfs: couldn't resolve uid %d to string\n",
989 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 /* XXX */
991 strcpy(owner_name, "nobody");
992 owner_namelen = sizeof("nobody") - 1;
993 /* goto out; */
994 }
995 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
996 }
997 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800998 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001000 dprintk("nfs: couldn't resolve gid %d to string\n",
1001 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 strcpy(owner_group, "nobody");
1003 owner_grouplen = sizeof("nobody") - 1;
1004 /* goto out; */
1005 }
1006 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1007 }
1008 if (iap->ia_valid & ATTR_ATIME_SET)
1009 len += 16;
1010 else if (iap->ia_valid & ATTR_ATIME)
1011 len += 4;
1012 if (iap->ia_valid & ATTR_MTIME_SET)
1013 len += 16;
1014 else if (iap->ia_valid & ATTR_MTIME)
1015 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001016 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 /*
1019 * We write the bitmap length now, but leave the bitmap and the attribute
1020 * buffer length to be backfilled at the end of this routine.
1021 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001022 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 q = p;
1024 p += 3;
1025
1026 if (iap->ia_valid & ATTR_SIZE) {
1027 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001028 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 if (iap->ia_valid & ATTR_MODE) {
1031 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001032 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 if (iap->ia_valid & ATTR_UID) {
1035 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001036 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038 if (iap->ia_valid & ATTR_GID) {
1039 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001040 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 if (iap->ia_valid & ATTR_ATIME_SET) {
1043 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001044 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1045 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001046 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1047 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 }
1049 else if (iap->ia_valid & ATTR_ATIME) {
1050 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001051 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
1053 if (iap->ia_valid & ATTR_MTIME_SET) {
1054 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1056 *p++ = cpu_to_be32(0);
1057 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1058 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
1060 else if (iap->ia_valid & ATTR_MTIME) {
1061 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001062 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 /*
1066 * Now we backfill the bitmap and the attribute buffer length.
1067 */
1068 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001069 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 len, ((char *)p - (char *)q) + 4);
1071 BUG();
1072 }
1073 len = (char *)p - (char *)q - 12;
1074 *q++ = htonl(bmval0);
1075 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001076 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079}
1080
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001081static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001083 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1084 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001087static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
Trond Myklebustab19b482012-03-04 18:13:57 -05001089 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001090 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001091 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092}
1093
Fred Isaman0b7c0152012-04-20 14:47:39 -04001094static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
Al Viro8687b632006-10-19 23:28:48 -07001096 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001097
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001098 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1099 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001100 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001101 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001104static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
Al Viro8687b632006-10-19 23:28:48 -07001106 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001107
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001108 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1109 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 switch (create->ftype) {
1112 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001113 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001114 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001115 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
1117
1118 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001119 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001120 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001121 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 break;
1123
1124 default:
1125 break;
1126 }
1127
Benny Halevy811652b2009-08-14 17:19:34 +03001128 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001129 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001132static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Andy Adamson05d564f2008-12-23 16:06:15 -05001134 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001136 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1137 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001138 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001139 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140}
1141
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001142static 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 -07001143{
Andy Adamson05d564f2008-12-23 16:06:15 -05001144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001146 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1147 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001148 *p++ = cpu_to_be32(2);
1149 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001150 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Fred Isamandae100c2011-07-30 20:52:37 -04001153static void
1154encode_getattr_three(struct xdr_stream *xdr,
1155 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1156 struct compound_hdr *hdr)
1157{
1158 __be32 *p;
1159
Trond Myklebustab19b482012-03-04 18:13:57 -05001160 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001161 if (bm2) {
1162 p = reserve_space(xdr, 16);
1163 *p++ = cpu_to_be32(3);
1164 *p++ = cpu_to_be32(bm0);
1165 *p++ = cpu_to_be32(bm1);
1166 *p = cpu_to_be32(bm2);
1167 } else if (bm1) {
1168 p = reserve_space(xdr, 12);
1169 *p++ = cpu_to_be32(2);
1170 *p++ = cpu_to_be32(bm0);
1171 *p = cpu_to_be32(bm1);
1172 } else {
1173 p = reserve_space(xdr, 8);
1174 *p++ = cpu_to_be32(1);
1175 *p = cpu_to_be32(bm0);
1176 }
Fred Isamandae100c2011-07-30 20:52:37 -04001177}
1178
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001179static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001181 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1182 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Fred Isamandae100c2011-07-30 20:52:37 -04001187 encode_getattr_three(xdr,
1188 bitmask[0] & nfs4_fsinfo_bitmap[0],
1189 bitmask[1] & nfs4_fsinfo_bitmap[1],
1190 bitmask[2] & nfs4_fsinfo_bitmap[2],
1191 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001194static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001195{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001196 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1197 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001198}
1199
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001200static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Trond Myklebustab19b482012-03-04 18:13:57 -05001202 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001205static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Trond Myklebustab19b482012-03-04 18:13:57 -05001207 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001208 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001211static inline int nfs4_lock_type(struct file_lock *fl, int block)
1212{
1213 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1214 return block ? NFS4_READW_LT : NFS4_READ_LT;
1215 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1216}
1217
1218static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1219{
1220 if (fl->fl_end == OFFSET_MAX)
1221 return ~(uint64_t)0;
1222 return fl->fl_end - fl->fl_start + 1;
1223}
1224
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001225static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1226{
1227 __be32 *p;
1228
Trond Myklebustd035c362010-12-21 10:45:27 -05001229 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001230 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001231 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001232 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001233 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001234 xdr_encode_hyper(p, lowner->id);
1235}
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237/*
1238 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1239 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1240 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001241static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
Al Viro8687b632006-10-19 23:28:48 -07001243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001245 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1246 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001247 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1248 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001249 p = xdr_encode_hyper(p, args->fl->fl_start);
1250 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001251 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001252 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001253 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001254 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001255 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001256 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 }
1258 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001259 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001260 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262}
1263
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001264static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
Al Viro8687b632006-10-19 23:28:48 -07001266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001268 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1269 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001270 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001271 p = xdr_encode_hyper(p, args->fl->fl_start);
1272 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001273 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001276static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Al Viro8687b632006-10-19 23:28:48 -07001278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001280 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1281 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001282 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001283 encode_nfs4_stateid(xdr, args->stateid);
1284 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001285 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001286 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001289static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1290{
Trond Myklebustab19b482012-03-04 18:13:57 -05001291 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001292 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001293}
1294
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001295static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
Trond Myklebustab19b482012-03-04 18:13:57 -05001297 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001298 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299}
1300
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001301static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
Al Viro8687b632006-10-19 23:28:48 -07001303 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Benny Halevy13c65ce2009-08-14 17:19:25 +03001305 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001306 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001307 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001308 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001309 break;
1310 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001311 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001312 break;
1313 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001315 break;
1316 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001317 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
Benny Halevy34558512009-08-14 17:19:30 +03001319 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320}
1321
1322static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1323{
Al Viro8687b632006-10-19 23:28:48 -07001324 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 /*
1326 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1327 * owner 4 = 32
1328 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001329 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001330 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001331 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001332 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001333 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001334 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001335 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001336 *p++ = cpu_to_be32(arg->id.uniquifier);
1337 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
1340static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1341{
Al Viro8687b632006-10-19 23:28:48 -07001342 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001343 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Benny Halevy13c65ce2009-08-14 17:19:25 +03001345 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001347 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001348 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001349 encode_attrs(xdr, arg->u.attrs, arg->server);
1350 break;
1351 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001352 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001353 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001354 if (nfs4_has_persistent_session(clp)) {
1355 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1356 encode_attrs(xdr, arg->u.attrs, arg->server);
1357 } else {
1358 struct iattr dummy;
1359
1360 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1361 encode_nfs4_verifier(xdr, &arg->u.verifier);
1362 dummy.ia_valid = 0;
1363 encode_attrs(xdr, &dummy, arg->server);
1364 }
1365 } else {
1366 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1367 encode_nfs4_verifier(xdr, &arg->u.verifier);
1368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 }
1370}
1371
1372static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Benny Halevy13c65ce2009-08-14 17:19:25 +03001376 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001378 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001379 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001380 break;
1381 default:
1382 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001383 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 }
1386}
1387
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001388static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389{
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, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001394 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001395 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001396 break;
1397 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001399 break;
1400 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001402 break;
1403 default:
1404 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 }
1406}
1407
1408static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1409{
Al Viro8687b632006-10-19 23:28:48 -07001410 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Benny Halevy13c65ce2009-08-14 17:19:25 +03001412 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001413 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 encode_string(xdr, name->len, name->name);
1415}
1416
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001417static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418{
Al Viro8687b632006-10-19 23:28:48 -07001419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Benny Halevy13c65ce2009-08-14 17:19:25 +03001421 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 encode_delegation_type(xdr, type);
1424}
1425
1426static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1427{
Al Viro8687b632006-10-19 23:28:48 -07001428 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001430 p = reserve_space(xdr, 4);
1431 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1432 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 encode_string(xdr, name->len, name->name);
1434}
1435
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001436static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
Trond Myklebustab19b482012-03-04 18:13:57 -05001438 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 encode_openhdr(xdr, arg);
1440 encode_opentype(xdr, arg);
1441 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001442 case NFS4_OPEN_CLAIM_NULL:
1443 encode_claim_null(xdr, arg->name);
1444 break;
1445 case NFS4_OPEN_CLAIM_PREVIOUS:
1446 encode_claim_previous(xdr, arg->u.delegation_type);
1447 break;
1448 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1449 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1450 break;
1451 default:
1452 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001456static 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 -07001457{
Trond Myklebustab19b482012-03-04 18:13:57 -05001458 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001459 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001460 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Trond Myklebustab19b482012-03-04 18:13:57 -05001465 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001466 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001467 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001468 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469}
1470
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001471static void
Andy Adamsond0179312008-12-23 16:06:17 -05001472encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
Trond Myklebustab19b482012-03-04 18:13:57 -05001474 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001475 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476}
1477
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001478static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Trond Myklebustab19b482012-03-04 18:13:57 -05001480 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
Trond Myklebust4fc87962012-03-08 17:42:01 -05001483static void encode_open_stateid(struct xdr_stream *xdr,
1484 const struct nfs_open_context *ctx,
1485 const struct nfs_lock_context *l_ctx,
1486 fmode_t fmode,
1487 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001492 nfs4_select_rw_stateid(&stateid, ctx->state,
1493 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001494 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001495 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001496 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001498 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
1500
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001501static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
Al Viro8687b632006-10-19 23:28:48 -07001503 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Trond Myklebustab19b482012-03-04 18:13:57 -05001505 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001506 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001507 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Benny Halevy13c65ce2009-08-14 17:19:25 +03001509 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001510 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001511 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512}
1513
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001514static 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 -07001515{
Trond Myklebust28331a42011-04-27 13:47:52 -04001516 uint32_t attrs[2] = {
1517 FATTR4_WORD0_RDATTR_ERROR,
1518 FATTR4_WORD1_MOUNTED_ON_FILEID,
1519 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001520 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001521 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001523 if (readdir->plus) {
1524 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001525 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001526 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1527 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1528 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1529 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001530 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001531 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001532 /* Use mounted_on_fileid only if the server supports it */
1533 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1534 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001535
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001536 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001537 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001538 encode_nfs4_verifier(xdr, &readdir->verifier);
1539 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001540 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001541 *p++ = cpu_to_be32(readdir->count);
1542 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001543
Benny Halevye75bc1c2009-08-14 17:18:54 +03001544 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001545 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001546 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001547 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1548 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001549 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001550 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001551 attrs[0] & readdir->bitmask[0],
1552 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001555static 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 -07001556{
Trond Myklebustab19b482012-03-04 18:13:57 -05001557 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Trond Myklebustab19b482012-03-04 18:13:57 -05001562 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001563 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566static 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 -07001567{
Trond Myklebustab19b482012-03-04 18:13:57 -05001568 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001569 encode_string(xdr, oldname->len, oldname->name);
1570 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
Chuck Leverbb4dae52012-03-01 17:01:48 -05001573static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1574 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001576 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001577 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580static void
Andy Adamsond0179312008-12-23 16:06:17 -05001581encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001582{
Trond Myklebustab19b482012-03-04 18:13:57 -05001583 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001584}
1585
Chuck Lever9f06c712010-12-14 14:59:18 +00001586static void
Andy Adamsond0179312008-12-23 16:06:17 -05001587encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001588{
Al Viro8687b632006-10-19 23:28:48 -07001589 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001590
Trond Myklebustab19b482012-03-04 18:13:57 -05001591 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001592 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001593 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001595 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001596 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001597 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001598 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001599 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001600}
1601
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602static void
Andy Adamsond0179312008-12-23 16:06:17 -05001603encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
Trond Myklebustab19b482012-03-04 18:13:57 -05001605 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static 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 -07001609{
Trond Myklebustab19b482012-03-04 18:13:57 -05001610 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001611 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001612 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613}
1614
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001615static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616{
Al Viro8687b632006-10-19 23:28:48 -07001617 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Trond Myklebust70019512012-03-04 20:49:32 -05001619 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001620 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
1622 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001623 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001624 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1626 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001628 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001631static 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 -07001632{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001633 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1634 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001635 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001636 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001639static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640{
Al Viro8687b632006-10-19 23:28:48 -07001641 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
Trond Myklebustab19b482012-03-04 18:13:57 -05001643 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001644 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001645 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Benny Halevy13c65ce2009-08-14 17:19:25 +03001647 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001648 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001649 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001650 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Trond Myklebustab19b482012-03-04 18:13:57 -05001657 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001658 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001660
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001661static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1662{
Trond Myklebustab19b482012-03-04 18:13:57 -05001663 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001664 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001665}
1666
Benny Halevy99fe60d2009-04-01 09:22:29 -04001667#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001668/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001669static void encode_exchange_id(struct xdr_stream *xdr,
1670 struct nfs41_exchange_id_args *args,
1671 struct compound_hdr *hdr)
1672{
1673 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001674 char impl_name[NFS4_OPAQUE_LIMIT];
1675 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001676
Trond Myklebust70019512012-03-04 20:49:32 -05001677 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001678 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001679
1680 encode_string(xdr, args->id_len, args->id);
1681
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001683 *p++ = cpu_to_be32(args->flags);
1684 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001685
1686 if (send_implementation_id &&
1687 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1688 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1689 <= NFS4_OPAQUE_LIMIT + 1)
1690 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1691 utsname()->sysname, utsname()->release,
1692 utsname()->version, utsname()->machine);
1693
1694 if (len > 0) {
1695 *p = cpu_to_be32(1); /* implementation id array length=1 */
1696
1697 encode_string(xdr,
1698 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1699 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1700 encode_string(xdr, len, impl_name);
1701 /* just send zeros for nii_date - the date is in nii_name */
1702 p = reserve_space(xdr, 12);
1703 p = xdr_encode_hyper(p, 0);
1704 *p = cpu_to_be32(0);
1705 } else
1706 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001707}
Andy Adamsonfc931582009-04-01 09:22:31 -04001708
1709static void encode_create_session(struct xdr_stream *xdr,
1710 struct nfs41_create_session_args *args,
1711 struct compound_hdr *hdr)
1712{
1713 __be32 *p;
1714 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1715 uint32_t len;
1716 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001717 u32 max_resp_sz_cached;
1718
1719 /*
1720 * Assumes OPEN is the biggest non-idempotent compound.
1721 * 2 is the verifier.
1722 */
1723 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1724 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001725
Andy Adamsonfc931582009-04-01 09:22:31 -04001726 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1727 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001728
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001729 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1730 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001731 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1733 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001734
Andy Adamsonfc931582009-04-01 09:22:31 -04001735 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001736 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1738 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001739 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001740 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1741 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1742 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001743
1744 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001745 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1747 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1748 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1749 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1750 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1751 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001752
Benny Halevye75bc1c2009-08-14 17:18:54 +03001753 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001754 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001755 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001756
1757 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001758 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001759 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32(0); /* UID */
1761 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001762 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001763}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001764
1765static void encode_destroy_session(struct xdr_stream *xdr,
1766 struct nfs4_session *session,
1767 struct compound_hdr *hdr)
1768{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001769 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1770 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001771}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001772
1773static void encode_reclaim_complete(struct xdr_stream *xdr,
1774 struct nfs41_reclaim_complete_args *args,
1775 struct compound_hdr *hdr)
1776{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001777 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1778 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001779}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780#endif /* CONFIG_NFS_V4_1 */
1781
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001782static void encode_sequence(struct xdr_stream *xdr,
1783 const struct nfs4_sequence_args *args,
1784 struct compound_hdr *hdr)
1785{
1786#if defined(CONFIG_NFS_V4_1)
1787 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001788 struct nfs4_slot_table *tp;
1789 struct nfs4_slot *slot;
1790 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001791
1792 if (!session)
1793 return;
1794
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001795 tp = &session->fc_slot_table;
1796
1797 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1798 slot = tp->slots + args->sa_slotid;
1799
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001800 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001801
1802 /*
1803 * Sessionid + seqid + slotid + max slotid + cache_this
1804 */
1805 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1806 "max_slotid=%d cache_this=%d\n",
1807 __func__,
1808 ((u32 *)session->sess_id.data)[0],
1809 ((u32 *)session->sess_id.data)[1],
1810 ((u32 *)session->sess_id.data)[2],
1811 ((u32 *)session->sess_id.data)[3],
1812 slot->seq_nr, args->sa_slotid,
1813 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001814 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001815 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001816 *p++ = cpu_to_be32(slot->seq_nr);
1817 *p++ = cpu_to_be32(args->sa_slotid);
1818 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001819 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001820#endif /* CONFIG_NFS_V4_1 */
1821}
1822
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001823#ifdef CONFIG_NFS_V4_1
1824static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001825encode_getdevicelist(struct xdr_stream *xdr,
1826 const struct nfs4_getdevicelist_args *args,
1827 struct compound_hdr *hdr)
1828{
1829 __be32 *p;
1830 nfs4_verifier dummy = {
1831 .data = "dummmmmy",
1832 };
1833
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001834 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1835 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001836 *p++ = cpu_to_be32(args->layoutclass);
1837 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1838 xdr_encode_hyper(p, 0ULL); /* cookie */
1839 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001840}
1841
1842static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001843encode_getdeviceinfo(struct xdr_stream *xdr,
1844 const struct nfs4_getdeviceinfo_args *args,
1845 struct compound_hdr *hdr)
1846{
1847 __be32 *p;
1848
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001849 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1850 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001851 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1852 NFS4_DEVICEID4_SIZE);
1853 *p++ = cpu_to_be32(args->pdev->layout_type);
1854 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1855 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001856}
1857
1858static void
1859encode_layoutget(struct xdr_stream *xdr,
1860 const struct nfs4_layoutget_args *args,
1861 struct compound_hdr *hdr)
1862{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001863 __be32 *p;
1864
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001865 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1866 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001867 *p++ = cpu_to_be32(0); /* Signal layout available */
1868 *p++ = cpu_to_be32(args->type);
1869 *p++ = cpu_to_be32(args->range.iomode);
1870 p = xdr_encode_hyper(p, args->range.offset);
1871 p = xdr_encode_hyper(p, args->range.length);
1872 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001873 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001874 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001875
1876 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1877 __func__,
1878 args->type,
1879 args->range.iomode,
1880 (unsigned long)args->range.offset,
1881 (unsigned long)args->range.length,
1882 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001883}
Andy Adamson863a3c62011-03-23 13:27:54 +00001884
1885static int
1886encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001887 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001888 const struct nfs4_layoutcommit_args *args,
1889 struct compound_hdr *hdr)
1890{
1891 __be32 *p;
1892
1893 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1894 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1895
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001896 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1897 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001898 /* Only whole file layouts */
1899 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001900 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001901 *p = cpu_to_be32(0); /* reclaim */
1902 encode_nfs4_stateid(xdr, &args->stateid);
1903 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001904 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1905 p = xdr_encode_hyper(p, args->lastbytewritten);
1906 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1907 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001908
1909 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1910 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1911 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001912 else
1913 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001914
Andy Adamson863a3c62011-03-23 13:27:54 +00001915 return 0;
1916}
Benny Halevycbe82602011-05-22 19:52:37 +03001917
1918static void
1919encode_layoutreturn(struct xdr_stream *xdr,
1920 const struct nfs4_layoutreturn_args *args,
1921 struct compound_hdr *hdr)
1922{
1923 __be32 *p;
1924
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001925 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1926 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001927 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1928 *p++ = cpu_to_be32(args->layout_type);
1929 *p++ = cpu_to_be32(IOMODE_ANY);
1930 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001931 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001932 p = xdr_encode_hyper(p, 0);
1933 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1934 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001935 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001936 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001937 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1938 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1939 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001940 } else
1941 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001942}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001943
1944static int
1945encode_secinfo_no_name(struct xdr_stream *xdr,
1946 const struct nfs41_secinfo_no_name_args *args,
1947 struct compound_hdr *hdr)
1948{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001949 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1950 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001951 return 0;
1952}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001953
1954static void encode_test_stateid(struct xdr_stream *xdr,
1955 struct nfs41_test_stateid_args *args,
1956 struct compound_hdr *hdr)
1957{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001958 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1959 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001960 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001961}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001962
1963static void encode_free_stateid(struct xdr_stream *xdr,
1964 struct nfs41_free_stateid_args *args,
1965 struct compound_hdr *hdr)
1966{
Trond Myklebustab19b482012-03-04 18:13:57 -05001967 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001968 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001969}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001970#endif /* CONFIG_NFS_V4_1 */
1971
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972/*
1973 * END OF "GENERIC" ENCODE ROUTINES.
1974 */
1975
Benny Halevy66cc0422009-04-01 09:22:10 -04001976static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1977{
1978#if defined(CONFIG_NFS_V4_1)
1979 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001980 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001981#endif /* CONFIG_NFS_V4_1 */
1982 return 0;
1983}
1984
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985/*
1986 * Encode an ACCESS request
1987 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001988static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1989 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001992 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Chuck Lever9f06c712010-12-14 14:59:18 +00001995 encode_compound_hdr(xdr, req, &hdr);
1996 encode_sequence(xdr, &args->seq_args, &hdr);
1997 encode_putfh(xdr, args->fh, &hdr);
1998 encode_access(xdr, args->access, &hdr);
1999 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002000 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
2003/*
2004 * Encode LOOKUP request
2005 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002006static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2007 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Chuck Lever9f06c712010-12-14 14:59:18 +00002013 encode_compound_hdr(xdr, req, &hdr);
2014 encode_sequence(xdr, &args->seq_args, &hdr);
2015 encode_putfh(xdr, args->dir_fh, &hdr);
2016 encode_lookup(xdr, args->name, &hdr);
2017 encode_getfh(xdr, &hdr);
2018 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002019 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
2022/*
2023 * Encode LOOKUP_ROOT request
2024 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002025static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2026 struct xdr_stream *xdr,
2027 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
Chuck Lever9f06c712010-12-14 14:59:18 +00002033 encode_compound_hdr(xdr, req, &hdr);
2034 encode_sequence(xdr, &args->seq_args, &hdr);
2035 encode_putrootfh(xdr, &hdr);
2036 encode_getfh(xdr, &hdr);
2037 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002038 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039}
2040
2041/*
2042 * Encode REMOVE request
2043 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002044static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2045 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002048 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Chuck Lever9f06c712010-12-14 14:59:18 +00002051 encode_compound_hdr(xdr, req, &hdr);
2052 encode_sequence(xdr, &args->seq_args, &hdr);
2053 encode_putfh(xdr, args->fh, &hdr);
2054 encode_remove(xdr, &args->name, &hdr);
2055 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002056 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
2059/*
2060 * Encode RENAME request
2061 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002062static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2063 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002066 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Chuck Lever9f06c712010-12-14 14:59:18 +00002069 encode_compound_hdr(xdr, req, &hdr);
2070 encode_sequence(xdr, &args->seq_args, &hdr);
2071 encode_putfh(xdr, args->old_dir, &hdr);
2072 encode_savefh(xdr, &hdr);
2073 encode_putfh(xdr, args->new_dir, &hdr);
2074 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2075 encode_getfattr(xdr, args->bitmask, &hdr);
2076 encode_restorefh(xdr, &hdr);
2077 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002078 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
2081/*
2082 * Encode LINK request
2083 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002084static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Chuck Lever9f06c712010-12-14 14:59:18 +00002091 encode_compound_hdr(xdr, req, &hdr);
2092 encode_sequence(xdr, &args->seq_args, &hdr);
2093 encode_putfh(xdr, args->fh, &hdr);
2094 encode_savefh(xdr, &hdr);
2095 encode_putfh(xdr, args->dir_fh, &hdr);
2096 encode_link(xdr, args->name, &hdr);
2097 encode_getfattr(xdr, args->bitmask, &hdr);
2098 encode_restorefh(xdr, &hdr);
2099 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002100 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101}
2102
2103/*
2104 * Encode CREATE request
2105 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002106static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2107 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Chuck Lever9f06c712010-12-14 14:59:18 +00002113 encode_compound_hdr(xdr, req, &hdr);
2114 encode_sequence(xdr, &args->seq_args, &hdr);
2115 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002116 encode_create(xdr, args, &hdr);
2117 encode_getfh(xdr, &hdr);
2118 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002119 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
2122/*
2123 * Encode SYMLINK request
2124 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002125static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2126 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
Chuck Lever9f06c712010-12-14 14:59:18 +00002128 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode GETATTR request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putfh(xdr, args->fh, &hdr);
2144 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
2149 * Encode a CLOSE request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Andy Adamson05d564f2008-12-23 16:06:15 -05002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->fh, &hdr);
2161 encode_close(xdr, args, &hdr);
2162 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002163 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
2166/*
2167 * Encode an OPEN request
2168 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002169static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2170 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002173 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Chuck Lever9f06c712010-12-14 14:59:18 +00002176 encode_compound_hdr(xdr, req, &hdr);
2177 encode_sequence(xdr, &args->seq_args, &hdr);
2178 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_open(xdr, args, &hdr);
2180 encode_getfh(xdr, &hdr);
2181 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode an OPEN_CONFIRM request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2189 struct xdr_stream *xdr,
2190 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002193 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_compound_hdr(xdr, req, &hdr);
2197 encode_putfh(xdr, args->fh, &hdr);
2198 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002199 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode an OPEN request with no attributes.
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2206 struct xdr_stream *xdr,
2207 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->fh, &hdr);
2216 encode_open(xdr, args, &hdr);
2217 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002218 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221/*
2222 * Encode an OPEN_DOWNGRADE request
2223 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002224static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2225 struct xdr_stream *xdr,
2226 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002229 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Chuck Lever9f06c712010-12-14 14:59:18 +00002232 encode_compound_hdr(xdr, req, &hdr);
2233 encode_sequence(xdr, &args->seq_args, &hdr);
2234 encode_putfh(xdr, args->fh, &hdr);
2235 encode_open_downgrade(xdr, args, &hdr);
2236 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002237 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
2240/*
2241 * Encode a LOCK request
2242 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002243static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2244 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_compound_hdr(xdr, req, &hdr);
2251 encode_sequence(xdr, &args->seq_args, &hdr);
2252 encode_putfh(xdr, args->fh, &hdr);
2253 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002254 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255}
2256
2257/*
2258 * Encode a LOCKT request
2259 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002260static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2261 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002264 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_sequence(xdr, &args->seq_args, &hdr);
2269 encode_putfh(xdr, args->fh, &hdr);
2270 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*
2275 * Encode a LOCKU request
2276 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002277static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2278 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002281 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Chuck Lever9f06c712010-12-14 14:59:18 +00002284 encode_compound_hdr(xdr, req, &hdr);
2285 encode_sequence(xdr, &args->seq_args, &hdr);
2286 encode_putfh(xdr, args->fh, &hdr);
2287 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002288 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
Chuck Lever9f06c712010-12-14 14:59:18 +00002291static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2292 struct xdr_stream *xdr,
2293 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002294{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002295 struct compound_hdr hdr = {
2296 .minorversion = 0,
2297 };
2298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002301 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002302}
2303
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304/*
2305 * Encode a READLINK request
2306 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002307static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2308 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002311 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
Chuck Lever9f06c712010-12-14 14:59:18 +00002314 encode_compound_hdr(xdr, req, &hdr);
2315 encode_sequence(xdr, &args->seq_args, &hdr);
2316 encode_putfh(xdr, args->fh, &hdr);
2317 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002318
Benny Halevy28f56692009-04-01 09:22:09 -04002319 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002320 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode a READDIR request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002338
Benny Halevy28f56692009-04-01 09:22:09 -04002339 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002340 args->pgbase, args->count);
2341 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002342 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002343 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * Encode a READ request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2351 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002354 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Chuck Lever9f06c712010-12-14 14:59:18 +00002357 encode_compound_hdr(xdr, req, &hdr);
2358 encode_sequence(xdr, &args->seq_args, &hdr);
2359 encode_putfh(xdr, args->fh, &hdr);
2360 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Benny Halevy28f56692009-04-01 09:22:09 -04002362 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002364 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002365 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
2368/*
2369 * Encode an SETATTR request
2370 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002371static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2372 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373{
Andy Adamson05d564f2008-12-23 16:06:15 -05002374 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002375 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002376 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_sequence(xdr, &args->seq_args, &hdr);
2380 encode_putfh(xdr, args->fh, &hdr);
2381 encode_setattr(xdr, args, args->server, &hdr);
2382 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002383 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384}
2385
2386/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002387 * Encode a GETACL request
2388 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002389static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2390 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002391{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002392 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002393 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002394 };
Benny Halevy28f56692009-04-01 09:22:09 -04002395 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002396
Chuck Lever9f06c712010-12-14 14:59:18 +00002397 encode_compound_hdr(xdr, req, &hdr);
2398 encode_sequence(xdr, &args->seq_args, &hdr);
2399 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002400 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002401 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002402
Benny Halevy28f56692009-04-01 09:22:09 -04002403 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002404 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002405
Andy Adamsond0179312008-12-23 16:06:17 -05002406 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002407}
2408
2409/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 * Encode a WRITE request
2411 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002412static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2413 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002416 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Chuck Lever9f06c712010-12-14 14:59:18 +00002419 encode_compound_hdr(xdr, req, &hdr);
2420 encode_sequence(xdr, &args->seq_args, &hdr);
2421 encode_putfh(xdr, args->fh, &hdr);
2422 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002423 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002424 if (args->bitmask)
2425 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002426 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429/*
2430 * a COMMIT request
2431 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002432static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002433 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002436 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
Chuck Lever9f06c712010-12-14 14:59:18 +00002439 encode_compound_hdr(xdr, req, &hdr);
2440 encode_sequence(xdr, &args->seq_args, &hdr);
2441 encode_putfh(xdr, args->fh, &hdr);
2442 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002443 if (args->bitmask)
2444 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002445 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
2448/*
2449 * FSINFO request
2450 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002451static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2452 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002455 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Chuck Lever9f06c712010-12-14 14:59:18 +00002458 encode_compound_hdr(xdr, req, &hdr);
2459 encode_sequence(xdr, &args->seq_args, &hdr);
2460 encode_putfh(xdr, args->fh, &hdr);
2461 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
2466 * a PATHCONF request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Chuck Lever9f06c712010-12-14 14:59:18 +00002475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_sequence(xdr, &args->seq_args, &hdr);
2477 encode_putfh(xdr, args->fh, &hdr);
2478 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002479 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002480 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
2483/*
2484 * a STATFS request
2485 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002486static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2487 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002490 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_sequence(xdr, &args->seq_args, &hdr);
2495 encode_putfh(xdr, args->fh, &hdr);
2496 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002497 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002498 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499}
2500
2501/*
2502 * GETATTR_BITMAP request
2503 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002504static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2505 struct xdr_stream *xdr,
2506 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002509 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Chuck Lever9f06c712010-12-14 14:59:18 +00002512 encode_compound_hdr(xdr, req, &hdr);
2513 encode_sequence(xdr, &args->seq_args, &hdr);
2514 encode_putfh(xdr, args->fhandle, &hdr);
2515 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002516 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002517 FATTR4_WORD0_LINK_SUPPORT|
2518 FATTR4_WORD0_SYMLINK_SUPPORT|
2519 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002520 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
2523/*
2524 * a RENEW request
2525 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002526static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2527 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002530 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 };
2532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002534 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002535 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
2538/*
2539 * a SETCLIENTID request
2540 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002541static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2542 struct xdr_stream *xdr,
2543 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002546 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 };
2548
Chuck Lever9f06c712010-12-14 14:59:18 +00002549 encode_compound_hdr(xdr, req, &hdr);
2550 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002551 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/*
2555 * a SETCLIENTID_CONFIRM request
2556 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002557static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2558 struct xdr_stream *xdr,
2559 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002562 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 };
Fred Isamandae100c2011-07-30 20:52:37 -04002564 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
Chuck Lever9f06c712010-12-14 14:59:18 +00002566 encode_compound_hdr(xdr, req, &hdr);
2567 encode_setclientid_confirm(xdr, arg, &hdr);
2568 encode_putrootfh(xdr, &hdr);
2569 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002570 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
2573/*
2574 * DELEGRETURN request
2575 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002576static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2577 struct xdr_stream *xdr,
2578 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002581 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_compound_hdr(xdr, req, &hdr);
2585 encode_sequence(xdr, &args->seq_args, &hdr);
2586 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002587 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002588 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002589 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590}
2591
2592/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002593 * Encode FS_LOCATIONS request
2594 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002595static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2596 struct xdr_stream *xdr,
2597 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002598{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002599 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002600 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002601 };
Benny Halevy28f56692009-04-01 09:22:09 -04002602 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002603
Chuck Lever9f06c712010-12-14 14:59:18 +00002604 encode_compound_hdr(xdr, req, &hdr);
2605 encode_sequence(xdr, &args->seq_args, &hdr);
2606 encode_putfh(xdr, args->dir_fh, &hdr);
2607 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002608 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002609 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002610
Benny Halevy28f56692009-04-01 09:22:09 -04002611 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002612 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002613 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002614}
2615
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002616/*
2617 * Encode SECINFO request
2618 */
2619static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2620 struct xdr_stream *xdr,
2621 struct nfs4_secinfo_arg *args)
2622{
2623 struct compound_hdr hdr = {
2624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2625 };
2626
2627 encode_compound_hdr(xdr, req, &hdr);
2628 encode_sequence(xdr, &args->seq_args, &hdr);
2629 encode_putfh(xdr, args->dir_fh, &hdr);
2630 encode_secinfo(xdr, args->name, &hdr);
2631 encode_nops(&hdr);
2632}
2633
Benny Halevy99fe60d2009-04-01 09:22:29 -04002634#if defined(CONFIG_NFS_V4_1)
2635/*
2636 * EXCHANGE_ID request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2639 struct xdr_stream *xdr,
2640 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002641{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002642 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002643 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002644 };
2645
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002648 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002649}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002650
2651/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002652 * a CREATE_SESSION request
2653 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002654static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2655 struct xdr_stream *xdr,
2656 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002657{
Andy Adamsonfc931582009-04-01 09:22:31 -04002658 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002659 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002660 };
2661
Chuck Lever9f06c712010-12-14 14:59:18 +00002662 encode_compound_hdr(xdr, req, &hdr);
2663 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002664 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002665}
2666
2667/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002668 * a DESTROY_SESSION request
2669 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002670static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2671 struct xdr_stream *xdr,
2672 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002673{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002674 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002675 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002676 };
2677
Chuck Lever9f06c712010-12-14 14:59:18 +00002678 encode_compound_hdr(xdr, req, &hdr);
2679 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002680 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002681}
2682
2683/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002684 * a SEQUENCE request
2685 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002686static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2687 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002688{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002689 struct compound_hdr hdr = {
2690 .minorversion = nfs4_xdr_minorversion(args),
2691 };
2692
Chuck Lever9f06c712010-12-14 14:59:18 +00002693 encode_compound_hdr(xdr, req, &hdr);
2694 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002695 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002696}
2697
2698/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002699 * a GET_LEASE_TIME request
2700 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002701static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2702 struct xdr_stream *xdr,
2703 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002704{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002705 struct compound_hdr hdr = {
2706 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2707 };
Fred Isamandae100c2011-07-30 20:52:37 -04002708 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002709
Chuck Lever9f06c712010-12-14 14:59:18 +00002710 encode_compound_hdr(xdr, req, &hdr);
2711 encode_sequence(xdr, &args->la_seq_args, &hdr);
2712 encode_putrootfh(xdr, &hdr);
2713 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002714 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002715}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002716
2717/*
2718 * a RECLAIM_COMPLETE request
2719 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002720static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2721 struct xdr_stream *xdr,
2722 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002723{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002724 struct compound_hdr hdr = {
2725 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2726 };
2727
Chuck Lever9f06c712010-12-14 14:59:18 +00002728 encode_compound_hdr(xdr, req, &hdr);
2729 encode_sequence(xdr, &args->seq_args, &hdr);
2730 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002731 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002732}
2733
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002734/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002735 * Encode GETDEVICELIST request
2736 */
2737static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2738 struct xdr_stream *xdr,
2739 struct nfs4_getdevicelist_args *args)
2740{
2741 struct compound_hdr hdr = {
2742 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2743 };
2744
2745 encode_compound_hdr(xdr, req, &hdr);
2746 encode_sequence(xdr, &args->seq_args, &hdr);
2747 encode_putfh(xdr, args->fh, &hdr);
2748 encode_getdevicelist(xdr, args, &hdr);
2749 encode_nops(&hdr);
2750}
2751
2752/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002753 * Encode GETDEVICEINFO request
2754 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002755static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2756 struct xdr_stream *xdr,
2757 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002758{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002759 struct compound_hdr hdr = {
2760 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2761 };
2762
Chuck Lever9f06c712010-12-14 14:59:18 +00002763 encode_compound_hdr(xdr, req, &hdr);
2764 encode_sequence(xdr, &args->seq_args, &hdr);
2765 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002766
2767 /* set up reply kvec. Subtract notification bitmap max size (2)
2768 * so that notification bitmap is put in xdr_buf tail */
2769 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2770 args->pdev->pages, args->pdev->pgbase,
2771 args->pdev->pglen);
2772
2773 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002774}
2775
2776/*
2777 * Encode LAYOUTGET request
2778 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002779static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2780 struct xdr_stream *xdr,
2781 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002782{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002783 struct compound_hdr hdr = {
2784 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2785 };
2786
Chuck Lever9f06c712010-12-14 14:59:18 +00002787 encode_compound_hdr(xdr, req, &hdr);
2788 encode_sequence(xdr, &args->seq_args, &hdr);
2789 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2790 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002791
2792 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2793 args->layout.pages, 0, args->layout.pglen);
2794
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002795 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002796}
Andy Adamson863a3c62011-03-23 13:27:54 +00002797
2798/*
2799 * Encode LAYOUTCOMMIT request
2800 */
Benny Halevycbe82602011-05-22 19:52:37 +03002801static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
2803 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002804{
Benny Halevyac7db722011-05-22 19:53:48 +03002805 struct nfs4_layoutcommit_data *data =
2806 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002807 struct compound_hdr hdr = {
2808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2809 };
2810
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_sequence(xdr, &args->seq_args, &hdr);
2813 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002814 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002815 encode_getfattr(xdr, args->bitmask, &hdr);
2816 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002817}
2818
2819/*
2820 * Encode LAYOUTRETURN request
2821 */
2822static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
2824 struct nfs4_layoutreturn_args *args)
2825{
2826 struct compound_hdr hdr = {
2827 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2828 };
2829
2830 encode_compound_hdr(xdr, req, &hdr);
2831 encode_sequence(xdr, &args->seq_args, &hdr);
2832 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2833 encode_layoutreturn(xdr, args, &hdr);
2834 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002835}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002836
2837/*
2838 * Encode SECINFO_NO_NAME request
2839 */
2840static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2841 struct xdr_stream *xdr,
2842 struct nfs41_secinfo_no_name_args *args)
2843{
2844 struct compound_hdr hdr = {
2845 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2846 };
2847
2848 encode_compound_hdr(xdr, req, &hdr);
2849 encode_sequence(xdr, &args->seq_args, &hdr);
2850 encode_putrootfh(xdr, &hdr);
2851 encode_secinfo_no_name(xdr, args, &hdr);
2852 encode_nops(&hdr);
2853 return 0;
2854}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002855
2856/*
2857 * Encode TEST_STATEID request
2858 */
2859static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2860 struct xdr_stream *xdr,
2861 struct nfs41_test_stateid_args *args)
2862{
2863 struct compound_hdr hdr = {
2864 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2865 };
2866
2867 encode_compound_hdr(xdr, req, &hdr);
2868 encode_sequence(xdr, &args->seq_args, &hdr);
2869 encode_test_stateid(xdr, args, &hdr);
2870 encode_nops(&hdr);
2871}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002872
2873/*
2874 * Encode FREE_STATEID request
2875 */
2876static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2877 struct xdr_stream *xdr,
2878 struct nfs41_free_stateid_args *args)
2879{
2880 struct compound_hdr hdr = {
2881 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2882 };
2883
2884 encode_compound_hdr(xdr, req, &hdr);
2885 encode_sequence(xdr, &args->seq_args, &hdr);
2886 encode_free_stateid(xdr, args, &hdr);
2887 encode_nops(&hdr);
2888}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002889#endif /* CONFIG_NFS_V4_1 */
2890
Benny Halevy686841b2009-08-14 17:19:48 +03002891static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2892{
2893 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2894 "Remaining buffer length is %tu words.\n",
2895 func, xdr->end - xdr->p);
2896}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
Trond Myklebust683b57b2006-06-09 09:34:22 -04002898static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899{
Al Viro8687b632006-10-19 23:28:48 -07002900 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
Benny Halevyc0eae662009-08-14 17:20:14 +03002902 p = xdr_inline_decode(xdr, 4);
2903 if (unlikely(!p))
2904 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002905 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002906 p = xdr_inline_decode(xdr, *len);
2907 if (unlikely(!p))
2908 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 *string = (char *)p;
2910 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002911out_overflow:
2912 print_overflow_msg(__func__, xdr);
2913 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914}
2915
2916static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2917{
Al Viro8687b632006-10-19 23:28:48 -07002918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Benny Halevyc0eae662009-08-14 17:20:14 +03002920 p = xdr_inline_decode(xdr, 8);
2921 if (unlikely(!p))
2922 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002923 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002924 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002925
Benny Halevyc0eae662009-08-14 17:20:14 +03002926 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2927 if (unlikely(!p))
2928 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 hdr->tag = (char *)p;
2930 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002931 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002932 if (unlikely(hdr->nops < 1))
2933 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002935out_overflow:
2936 print_overflow_msg(__func__, xdr);
2937 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938}
2939
2940static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2941{
Al Viro8687b632006-10-19 23:28:48 -07002942 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 uint32_t opnum;
2944 int32_t nfserr;
2945
Benny Halevyc0eae662009-08-14 17:20:14 +03002946 p = xdr_inline_decode(xdr, 8);
2947 if (unlikely(!p))
2948 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002949 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002951 dprintk("nfs: Server returned operation"
2952 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 opnum, expected);
2954 return -EIO;
2955 }
Benny Halevycccddf42009-08-14 17:20:19 +03002956 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002958 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002960out_overflow:
2961 print_overflow_msg(__func__, xdr);
2962 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963}
2964
2965/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002966static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967{
Al Viro8687b632006-10-19 23:28:48 -07002968 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002969 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 char *str;
2971
Benny Halevyc0eae662009-08-14 17:20:14 +03002972 p = xdr_inline_decode(xdr, 12);
2973 if (likely(p))
2974 return decode_opaque_inline(xdr, &strlen, &str);
2975 print_overflow_msg(__func__, xdr);
2976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977}
2978
2979static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2980{
Al Viro8687b632006-10-19 23:28:48 -07002981 uint32_t bmlen;
2982 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
Benny Halevyc0eae662009-08-14 17:20:14 +03002984 p = xdr_inline_decode(xdr, 4);
2985 if (unlikely(!p))
2986 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002987 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Fred Isamandae100c2011-07-30 20:52:37 -04002989 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002990 p = xdr_inline_decode(xdr, (bmlen << 2));
2991 if (unlikely(!p))
2992 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002994 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04002995 if (bmlen > 1) {
2996 bitmap[1] = be32_to_cpup(p++);
2997 if (bmlen > 2)
2998 bitmap[2] = be32_to_cpup(p);
2999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 }
3001 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003002out_overflow:
3003 print_overflow_msg(__func__, xdr);
3004 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005}
3006
Al Viro8687b632006-10-19 23:28:48 -07003007static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008{
Al Viro8687b632006-10-19 23:28:48 -07003009 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Benny Halevyc0eae662009-08-14 17:20:14 +03003011 p = xdr_inline_decode(xdr, 4);
3012 if (unlikely(!p))
3013 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003014 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 *savep = xdr->p;
3016 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003017out_overflow:
3018 print_overflow_msg(__func__, xdr);
3019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020}
3021
3022static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3023{
3024 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003025 int ret;
3026 ret = decode_attr_bitmap(xdr, bitmask);
3027 if (unlikely(ret < 0))
3028 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3030 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003031 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3032 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3033 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 return 0;
3035}
3036
3037static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3038{
Al Viro8687b632006-10-19 23:28:48 -07003039 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003040 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
3042 *type = 0;
3043 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3044 return -EIO;
3045 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003046 p = xdr_inline_decode(xdr, 4);
3047 if (unlikely(!p))
3048 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003049 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003051 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 return -EIO;
3053 }
3054 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003055 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003057 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003058 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003059out_overflow:
3060 print_overflow_msg(__func__, xdr);
3061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
Chuck Lever264e6352012-03-01 17:02:05 -05003064static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3065 uint32_t *bitmap, uint32_t *type)
3066{
3067 __be32 *p;
3068
3069 *type = 0;
3070 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3071 return -EIO;
3072 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3073 p = xdr_inline_decode(xdr, 4);
3074 if (unlikely(!p))
3075 goto out_overflow;
3076 *type = be32_to_cpup(p);
3077 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3078 }
3079 dprintk("%s: expire type=0x%x\n", __func__, *type);
3080 return 0;
3081out_overflow:
3082 print_overflow_msg(__func__, xdr);
3083 return -EIO;
3084}
3085
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3087{
Al Viro8687b632006-10-19 23:28:48 -07003088 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003089 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090
3091 *change = 0;
3092 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3093 return -EIO;
3094 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003095 p = xdr_inline_decode(xdr, 8);
3096 if (unlikely(!p))
3097 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003098 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003100 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003102 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003104 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003105out_overflow:
3106 print_overflow_msg(__func__, xdr);
3107 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108}
3109
3110static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3111{
Al Viro8687b632006-10-19 23:28:48 -07003112 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003113 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115 *size = 0;
3116 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3117 return -EIO;
3118 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003119 p = xdr_inline_decode(xdr, 8);
3120 if (unlikely(!p))
3121 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003122 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003124 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003126 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003127 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003128out_overflow:
3129 print_overflow_msg(__func__, xdr);
3130 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131}
3132
3133static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3134{
Al Viro8687b632006-10-19 23:28:48 -07003135 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136
3137 *res = 0;
3138 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3139 return -EIO;
3140 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003141 p = xdr_inline_decode(xdr, 4);
3142 if (unlikely(!p))
3143 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003144 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3146 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003147 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003149out_overflow:
3150 print_overflow_msg(__func__, xdr);
3151 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152}
3153
3154static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3155{
Al Viro8687b632006-10-19 23:28:48 -07003156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
3158 *res = 0;
3159 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3160 return -EIO;
3161 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003162 p = xdr_inline_decode(xdr, 4);
3163 if (unlikely(!p))
3164 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003165 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3167 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003168 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003170out_overflow:
3171 print_overflow_msg(__func__, xdr);
3172 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173}
3174
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003175static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176{
Al Viro8687b632006-10-19 23:28:48 -07003177 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003178 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
3180 fsid->major = 0;
3181 fsid->minor = 0;
3182 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3183 return -EIO;
3184 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003185 p = xdr_inline_decode(xdr, 16);
3186 if (unlikely(!p))
3187 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003188 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003189 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003191 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003193 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 (unsigned long long)fsid->major,
3195 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003196 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003197out_overflow:
3198 print_overflow_msg(__func__, xdr);
3199 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200}
3201
3202static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3203{
Al Viro8687b632006-10-19 23:28:48 -07003204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
3206 *res = 60;
3207 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3208 return -EIO;
3209 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003210 p = xdr_inline_decode(xdr, 4);
3211 if (unlikely(!p))
3212 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003213 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3215 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003216 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003218out_overflow:
3219 print_overflow_msg(__func__, xdr);
3220 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221}
3222
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003223static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003224{
3225 __be32 *p;
3226
3227 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3228 return -EIO;
3229 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3230 p = xdr_inline_decode(xdr, 4);
3231 if (unlikely(!p))
3232 goto out_overflow;
3233 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003234 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003235 }
3236 return 0;
3237out_overflow:
3238 print_overflow_msg(__func__, xdr);
3239 return -EIO;
3240}
3241
3242static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3243{
3244 __be32 *p;
3245 int len;
3246
Trond Myklebust7ad07352010-10-23 15:34:20 -04003247 if (fh != NULL)
3248 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003249
3250 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3251 return -EIO;
3252 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3253 p = xdr_inline_decode(xdr, 4);
3254 if (unlikely(!p))
3255 goto out_overflow;
3256 len = be32_to_cpup(p);
3257 if (len > NFS4_FHSIZE)
3258 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003259 p = xdr_inline_decode(xdr, len);
3260 if (unlikely(!p))
3261 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003262 if (fh != NULL) {
3263 memcpy(fh->data, p, len);
3264 fh->size = len;
3265 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003266 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3267 }
3268 return 0;
3269out_overflow:
3270 print_overflow_msg(__func__, xdr);
3271 return -EIO;
3272}
3273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3275{
Al Viro8687b632006-10-19 23:28:48 -07003276 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
3278 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3279 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3280 return -EIO;
3281 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003282 p = xdr_inline_decode(xdr, 4);
3283 if (unlikely(!p))
3284 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003285 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3287 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003288 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003290out_overflow:
3291 print_overflow_msg(__func__, xdr);
3292 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293}
3294
3295static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003298 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
3300 *fileid = 0;
3301 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3302 return -EIO;
3303 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003304 p = xdr_inline_decode(xdr, 8);
3305 if (unlikely(!p))
3306 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003307 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003309 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003311 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003312 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003313out_overflow:
3314 print_overflow_msg(__func__, xdr);
3315 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316}
3317
Manoj Naik99baf622006-06-09 09:34:24 -04003318static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3319{
Al Viro8687b632006-10-19 23:28:48 -07003320 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003321 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003322
3323 *fileid = 0;
3324 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3325 return -EIO;
3326 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003327 p = xdr_inline_decode(xdr, 8);
3328 if (unlikely(!p))
3329 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003330 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003331 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003332 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003333 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003334 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003335 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003336out_overflow:
3337 print_overflow_msg(__func__, xdr);
3338 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003339}
3340
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3342{
Al Viro8687b632006-10-19 23:28:48 -07003343 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 int status = 0;
3345
3346 *res = 0;
3347 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3348 return -EIO;
3349 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003350 p = xdr_inline_decode(xdr, 8);
3351 if (unlikely(!p))
3352 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003353 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3355 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003356 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003358out_overflow:
3359 print_overflow_msg(__func__, xdr);
3360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361}
3362
3363static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3364{
Al Viro8687b632006-10-19 23:28:48 -07003365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 int status = 0;
3367
3368 *res = 0;
3369 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3370 return -EIO;
3371 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003372 p = xdr_inline_decode(xdr, 8);
3373 if (unlikely(!p))
3374 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003375 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3377 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003378 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003380out_overflow:
3381 print_overflow_msg(__func__, xdr);
3382 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383}
3384
3385static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3386{
Al Viro8687b632006-10-19 23:28:48 -07003387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 int status = 0;
3389
3390 *res = 0;
3391 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3392 return -EIO;
3393 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003394 p = xdr_inline_decode(xdr, 8);
3395 if (unlikely(!p))
3396 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003397 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3399 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003400 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003402out_overflow:
3403 print_overflow_msg(__func__, xdr);
3404 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405}
3406
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003407static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3408{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003409 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003410 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003411 int status = 0;
3412
Benny Halevyc0eae662009-08-14 17:20:14 +03003413 p = xdr_inline_decode(xdr, 4);
3414 if (unlikely(!p))
3415 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003416 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003417 if (n == 0)
3418 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003419 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003420 path->ncomponents = 0;
3421 while (path->ncomponents < n) {
3422 struct nfs4_string *component = &path->components[path->ncomponents];
3423 status = decode_opaque_inline(xdr, &component->len, &component->data);
3424 if (unlikely(status != 0))
3425 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003426 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003427 pr_cont("%s%.*s ",
3428 (path->ncomponents != n ? "/ " : ""),
3429 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003430 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3431 path->ncomponents++;
3432 else {
3433 dprintk("cannot parse %d components in path\n", n);
3434 goto out_eio;
3435 }
3436 }
3437out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003438 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003439root_path:
3440/* a root pathname is sent as a zero component4 */
3441 path->ncomponents = 1;
3442 path->components[0].len=0;
3443 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003444 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003445 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003446out_eio:
3447 dprintk(" status %d", status);
3448 status = -EIO;
3449 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003450out_overflow:
3451 print_overflow_msg(__func__, xdr);
3452 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003453}
3454
3455static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003456{
3457 int n;
Al Viro8687b632006-10-19 23:28:48 -07003458 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003459 int status = -EIO;
3460
3461 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3462 goto out;
3463 status = 0;
3464 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3465 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003466 status = -EIO;
3467 /* Ignore borken servers that return unrequested attrs */
3468 if (unlikely(res == NULL))
3469 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003470 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003471 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003472 if (unlikely(status != 0))
3473 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003474 p = xdr_inline_decode(xdr, 4);
3475 if (unlikely(!p))
3476 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003477 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003478 if (n <= 0)
3479 goto out_eio;
3480 res->nlocations = 0;
3481 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003482 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003483 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003484
Benny Halevyc0eae662009-08-14 17:20:14 +03003485 p = xdr_inline_decode(xdr, 4);
3486 if (unlikely(!p))
3487 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003488 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003489
3490 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003491 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003492 while (loc->nservers < m) {
3493 struct nfs4_string *server = &loc->servers[loc->nservers];
3494 status = decode_opaque_inline(xdr, &server->len, &server->data);
3495 if (unlikely(status != 0))
3496 goto out_eio;
3497 dprintk("%s ", server->data);
3498 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3499 loc->nservers++;
3500 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003501 unsigned int i;
3502 dprintk("%s: using first %u of %u servers "
3503 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003504 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003505 NFS4_FS_LOCATION_MAXSERVERS,
3506 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003507 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003508 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003509 char *data;
3510 status = decode_opaque_inline(xdr, &len, &data);
3511 if (unlikely(status != 0))
3512 goto out_eio;
3513 }
3514 }
3515 }
3516 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003517 if (unlikely(status != 0))
3518 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003519 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003520 res->nlocations++;
3521 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003522 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003523 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003524out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003525 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003526 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003527out_overflow:
3528 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003529out_eio:
3530 status = -EIO;
3531 goto out;
3532}
3533
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534static int decode_attr_maxfilesize(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[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3541 return -EIO;
3542 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
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[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3548 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003549 dprintk("%s: maxfilesize=%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_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3557{
Al Viro8687b632006-10-19 23:28:48 -07003558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 int status = 0;
3560
3561 *maxlink = 1;
3562 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3563 return -EIO;
3564 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, 4);
3566 if (unlikely(!p))
3567 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003568 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3570 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003571 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003573out_overflow:
3574 print_overflow_msg(__func__, xdr);
3575 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576}
3577
3578static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3579{
Al Viro8687b632006-10-19 23:28:48 -07003580 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 int status = 0;
3582
3583 *maxname = 1024;
3584 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3585 return -EIO;
3586 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003587 p = xdr_inline_decode(xdr, 4);
3588 if (unlikely(!p))
3589 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003590 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3592 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003593 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003595out_overflow:
3596 print_overflow_msg(__func__, xdr);
3597 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598}
3599
3600static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3601{
Al Viro8687b632006-10-19 23:28:48 -07003602 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 int status = 0;
3604
3605 *res = 1024;
3606 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3607 return -EIO;
3608 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3609 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003610 p = xdr_inline_decode(xdr, 8);
3611 if (unlikely(!p))
3612 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003613 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 if (maxread > 0x7FFFFFFF)
3615 maxread = 0x7FFFFFFF;
3616 *res = (uint32_t)maxread;
3617 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3618 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003619 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003621out_overflow:
3622 print_overflow_msg(__func__, xdr);
3623 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624}
3625
3626static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3627{
Al Viro8687b632006-10-19 23:28:48 -07003628 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 int status = 0;
3630
3631 *res = 1024;
3632 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3633 return -EIO;
3634 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3635 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003636 p = xdr_inline_decode(xdr, 8);
3637 if (unlikely(!p))
3638 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003639 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 if (maxwrite > 0x7FFFFFFF)
3641 maxwrite = 0x7FFFFFFF;
3642 *res = (uint32_t)maxwrite;
3643 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3644 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003645 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003647out_overflow:
3648 print_overflow_msg(__func__, xdr);
3649 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650}
3651
Trond Myklebustbca79472009-03-11 14:10:26 -04003652static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653{
Trond Myklebustbca79472009-03-11 14:10:26 -04003654 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003655 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003656 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657
3658 *mode = 0;
3659 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3660 return -EIO;
3661 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003662 p = xdr_inline_decode(xdr, 4);
3663 if (unlikely(!p))
3664 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003665 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003666 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003668 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003670 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003671 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003672out_overflow:
3673 print_overflow_msg(__func__, xdr);
3674 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675}
3676
3677static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3678{
Al Viro8687b632006-10-19 23:28:48 -07003679 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003680 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
3682 *nlink = 1;
3683 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3684 return -EIO;
3685 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003686 p = xdr_inline_decode(xdr, 4);
3687 if (unlikely(!p))
3688 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003689 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003693 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003694 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003695out_overflow:
3696 print_overflow_msg(__func__, xdr);
3697 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698}
3699
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003700static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003701 const struct nfs_server *server, uint32_t *uid,
3702 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703{
Al Viro8687b632006-10-19 23:28:48 -07003704 uint32_t len;
3705 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003706 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707
3708 *uid = -2;
3709 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3710 return -EIO;
3711 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003712 p = xdr_inline_decode(xdr, 4);
3713 if (unlikely(!p))
3714 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003715 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003716 p = xdr_inline_decode(xdr, len);
3717 if (unlikely(!p))
3718 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003719 if (owner_name != NULL) {
3720 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3721 if (owner_name->data != NULL) {
3722 owner_name->len = len;
3723 ret = NFS_ATTR_FATTR_OWNER_NAME;
3724 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003725 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003726 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003727 ret = NFS_ATTR_FATTR_OWNER;
3728 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003730 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003732 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003733 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003736 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003737 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003738out_overflow:
3739 print_overflow_msg(__func__, xdr);
3740 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741}
3742
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003743static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003744 const struct nfs_server *server, uint32_t *gid,
3745 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746{
Al Viro8687b632006-10-19 23:28:48 -07003747 uint32_t len;
3748 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
3751 *gid = -2;
3752 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3753 return -EIO;
3754 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003755 p = xdr_inline_decode(xdr, 4);
3756 if (unlikely(!p))
3757 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003758 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003759 p = xdr_inline_decode(xdr, len);
3760 if (unlikely(!p))
3761 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003762 if (group_name != NULL) {
3763 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3764 if (group_name->data != NULL) {
3765 group_name->len = len;
3766 ret = NFS_ATTR_FATTR_GROUP_NAME;
3767 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003768 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003769 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003770 ret = NFS_ATTR_FATTR_GROUP;
3771 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003773 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003775 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003776 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3778 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003779 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003780 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003781out_overflow:
3782 print_overflow_msg(__func__, xdr);
3783 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784}
3785
3786static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3787{
Al Viro8687b632006-10-19 23:28:48 -07003788 uint32_t major = 0, minor = 0;
3789 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003790 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
3792 *rdev = MKDEV(0,0);
3793 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3794 return -EIO;
3795 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3796 dev_t tmp;
3797
Benny Halevyc0eae662009-08-14 17:20:14 +03003798 p = xdr_inline_decode(xdr, 8);
3799 if (unlikely(!p))
3800 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003801 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003802 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 tmp = MKDEV(major, minor);
3804 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3805 *rdev = tmp;
3806 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003807 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003809 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003810 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003811out_overflow:
3812 print_overflow_msg(__func__, xdr);
3813 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814}
3815
3816static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3817{
Al Viro8687b632006-10-19 23:28:48 -07003818 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 int status = 0;
3820
3821 *res = 0;
3822 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3823 return -EIO;
3824 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003825 p = xdr_inline_decode(xdr, 8);
3826 if (unlikely(!p))
3827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003828 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3830 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003831 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003833out_overflow:
3834 print_overflow_msg(__func__, xdr);
3835 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836}
3837
3838static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3839{
Al Viro8687b632006-10-19 23:28:48 -07003840 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 int status = 0;
3842
3843 *res = 0;
3844 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3845 return -EIO;
3846 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003847 p = xdr_inline_decode(xdr, 8);
3848 if (unlikely(!p))
3849 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003850 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3852 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003853 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003855out_overflow:
3856 print_overflow_msg(__func__, xdr);
3857 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858}
3859
3860static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3861{
Al Viro8687b632006-10-19 23:28:48 -07003862 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 int status = 0;
3864
3865 *res = 0;
3866 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3867 return -EIO;
3868 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003869 p = xdr_inline_decode(xdr, 8);
3870 if (unlikely(!p))
3871 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003872 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3874 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003875 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003877out_overflow:
3878 print_overflow_msg(__func__, xdr);
3879 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880}
3881
3882static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3883{
Al Viro8687b632006-10-19 23:28:48 -07003884 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003885 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886
3887 *used = 0;
3888 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3889 return -EIO;
3890 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003891 p = xdr_inline_decode(xdr, 8);
3892 if (unlikely(!p))
3893 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003894 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003896 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003898 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
3906static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3907{
Al Viro8687b632006-10-19 23:28:48 -07003908 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 uint64_t sec;
3910 uint32_t nsec;
3911
Benny Halevyc0eae662009-08-14 17:20:14 +03003912 p = xdr_inline_decode(xdr, 12);
3913 if (unlikely(!p))
3914 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003915 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003916 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 time->tv_sec = (time_t)sec;
3918 time->tv_nsec = (long)nsec;
3919 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003920out_overflow:
3921 print_overflow_msg(__func__, xdr);
3922 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923}
3924
3925static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3926{
3927 int status = 0;
3928
3929 time->tv_sec = 0;
3930 time->tv_nsec = 0;
3931 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3932 return -EIO;
3933 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3934 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 if (status == 0)
3936 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3938 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003939 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 return status;
3941}
3942
3943static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3944{
3945 int status = 0;
3946
3947 time->tv_sec = 0;
3948 time->tv_nsec = 0;
3949 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3950 return -EIO;
3951 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3952 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003953 if (status == 0)
3954 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3956 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003957 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 return status;
3959}
3960
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003961static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3962 struct timespec *time)
3963{
3964 int status = 0;
3965
3966 time->tv_sec = 0;
3967 time->tv_nsec = 0;
3968 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3969 return -EIO;
3970 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3971 status = decode_attr_time(xdr, time);
3972 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3973 }
3974 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3975 (long)time->tv_nsec);
3976 return status;
3977}
3978
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3980{
3981 int status = 0;
3982
3983 time->tv_sec = 0;
3984 time->tv_nsec = 0;
3985 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3986 return -EIO;
3987 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3988 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003989 if (status == 0)
3990 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3992 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003993 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 return status;
3995}
3996
Al Viro8687b632006-10-19 23:28:48 -07003997static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998{
3999 unsigned int attrwords = XDR_QUADLEN(attrlen);
4000 unsigned int nwords = xdr->p - savep;
4001
4002 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004003 dprintk("%s: server returned incorrect attribute length: "
4004 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004005 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 attrwords << 2,
4007 (attrwords < nwords) ? '<' : '>',
4008 nwords << 2);
4009 return -EIO;
4010 }
4011 return 0;
4012}
4013
4014static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4015{
Al Viro8687b632006-10-19 23:28:48 -07004016 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017
Benny Halevyc0eae662009-08-14 17:20:14 +03004018 p = xdr_inline_decode(xdr, 20);
4019 if (unlikely(!p))
4020 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004021 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004022 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004023 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004025out_overflow:
4026 print_overflow_msg(__func__, xdr);
4027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028}
4029
4030static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4031{
Al Viro8687b632006-10-19 23:28:48 -07004032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 uint32_t supp, acc;
4034 int status;
4035
4036 status = decode_op_hdr(xdr, OP_ACCESS);
4037 if (status)
4038 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004039 p = xdr_inline_decode(xdr, 8);
4040 if (unlikely(!p))
4041 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004042 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004043 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 access->supported = supp;
4045 access->access = acc;
4046 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004047out_overflow:
4048 print_overflow_msg(__func__, xdr);
4049 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050}
4051
Benny Halevy07d30432009-08-14 17:19:52 +03004052static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053{
Al Viro8687b632006-10-19 23:28:48 -07004054 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004055
4056 p = xdr_inline_decode(xdr, len);
4057 if (likely(p)) {
4058 memcpy(buf, p, len);
4059 return 0;
4060 }
4061 print_overflow_msg(__func__, xdr);
4062 return -EIO;
4063}
4064
4065static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4066{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004067 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068}
4069
4070static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 int status;
4073
4074 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004075 if (status != -EIO)
4076 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004077 if (!status)
4078 status = decode_stateid(xdr, &res->stateid);
4079 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
Benny Halevydb942bb2009-08-14 17:19:56 +03004082static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4083{
Chuck Levercd937102012-03-02 17:14:31 -05004084 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085}
4086
Fred Isaman0b7c0152012-04-20 14:47:39 -04004087static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 int status;
4090
4091 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004092 if (!status)
4093 status = decode_verifier(xdr, res->verf->verifier);
4094 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095}
4096
4097static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4098{
Al Viro8687b632006-10-19 23:28:48 -07004099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 uint32_t bmlen;
4101 int status;
4102
4103 status = decode_op_hdr(xdr, OP_CREATE);
4104 if (status)
4105 return status;
4106 if ((status = decode_change_info(xdr, cinfo)))
4107 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004108 p = xdr_inline_decode(xdr, 4);
4109 if (unlikely(!p))
4110 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004111 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004112 p = xdr_inline_decode(xdr, bmlen << 2);
4113 if (likely(p))
4114 return 0;
4115out_overflow:
4116 print_overflow_msg(__func__, xdr);
4117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118}
4119
4120static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4121{
Al Viro8687b632006-10-19 23:28:48 -07004122 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004123 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 int status;
4125
4126 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4127 goto xdr_error;
4128 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4129 goto xdr_error;
4130 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4131 goto xdr_error;
4132 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4133 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004134 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4135 &res->fh_expire_type)) != 0)
4136 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4138 goto xdr_error;
4139 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4140 goto xdr_error;
4141 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4142 goto xdr_error;
4143 status = verify_attr_len(xdr, savep, attrlen);
4144xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004145 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 return status;
4147}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004148
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4150{
Al Viro8687b632006-10-19 23:28:48 -07004151 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004152 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4156 goto xdr_error;
4157 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4158 goto xdr_error;
4159 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4160 goto xdr_error;
4161
4162 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4163 goto xdr_error;
4164 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4165 goto xdr_error;
4166 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4167 goto xdr_error;
4168 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4169 goto xdr_error;
4170 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4171 goto xdr_error;
4172 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4173 goto xdr_error;
4174
4175 status = verify_attr_len(xdr, savep, attrlen);
4176xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004177 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 return status;
4179}
4180
4181static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4182{
Al Viro8687b632006-10-19 23:28:48 -07004183 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004184 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004186
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4188 goto xdr_error;
4189 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4190 goto xdr_error;
4191 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4192 goto xdr_error;
4193
4194 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4195 goto xdr_error;
4196 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4197 goto xdr_error;
4198
4199 status = verify_attr_len(xdr, savep, attrlen);
4200xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004201 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 return status;
4203}
4204
Bryan Schumakerae42c702010-10-21 16:33:17 -04004205static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4206 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004207 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004208 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209{
Trond Myklebustbca79472009-03-11 14:10:26 -04004210 int status;
4211 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004212 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004213 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004215 status = decode_attr_type(xdr, bitmap, &type);
4216 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004218 fattr->mode = 0;
4219 if (status != 0) {
4220 fattr->mode |= nfs_type2fmt[type];
4221 fattr->valid |= status;
4222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004224 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4225 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004227 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004228
4229 status = decode_attr_size(xdr, bitmap, &fattr->size);
4230 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004232 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004233
4234 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4235 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004237 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004238
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004239 err = 0;
4240 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004241 if (status < 0)
4242 goto xdr_error;
4243
4244 status = decode_attr_filehandle(xdr, bitmap, fh);
4245 if (status < 0)
4246 goto xdr_error;
4247
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004248 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4249 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004251 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004252
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004253 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004254 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004255 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004256 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004257
4258 status = decode_attr_mode(xdr, bitmap, &fmode);
4259 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004261 if (status != 0) {
4262 fattr->mode |= fmode;
4263 fattr->valid |= status;
4264 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004265
4266 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4267 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004269 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004270
Trond Myklebust6926afd12012-01-07 13:22:46 -05004271 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004272 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004274 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004275
Trond Myklebust6926afd12012-01-07 13:22:46 -05004276 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004277 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004279 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004280
4281 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4282 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004284 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004285
4286 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4287 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004289 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004290
4291 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4292 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004294 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004295
4296 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4297 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004299 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004300
4301 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4302 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004304 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004305
Trond Myklebust28331a42011-04-27 13:47:52 -04004306 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004307 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004308 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004309 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004310
Bryan Schumakerae42c702010-10-21 16:33:17 -04004311xdr_error:
4312 dprintk("%s: xdr returned %d\n", __func__, -status);
4313 return status;
4314}
4315
4316static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004317 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4318 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004319{
4320 __be32 *savep;
4321 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004322 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004323 int status;
4324
4325 status = decode_op_hdr(xdr, OP_GETATTR);
4326 if (status < 0)
4327 goto xdr_error;
4328
4329 status = decode_attr_bitmap(xdr, bitmap);
4330 if (status < 0)
4331 goto xdr_error;
4332
4333 status = decode_attr_length(xdr, &attrlen, &savep);
4334 if (status < 0)
4335 goto xdr_error;
4336
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004337 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004338 if (status < 0)
4339 goto xdr_error;
4340
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004341 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004343 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 return status;
4345}
4346
Bryan Schumakerae42c702010-10-21 16:33:17 -04004347static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004348 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004349{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004350 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004351}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352
Andy Adamson504913f2010-10-20 00:17:57 -04004353/*
4354 * Decode potentially multiple layout types. Currently we only support
4355 * one layout driver per file system.
4356 */
4357static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4358 uint32_t *layouttype)
4359{
4360 uint32_t *p;
4361 int num;
4362
4363 p = xdr_inline_decode(xdr, 4);
4364 if (unlikely(!p))
4365 goto out_overflow;
4366 num = be32_to_cpup(p);
4367
4368 /* pNFS is not supported by the underlying file system */
4369 if (num == 0) {
4370 *layouttype = 0;
4371 return 0;
4372 }
4373 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004374 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4375 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004376
4377 /* Decode and set first layout type, move xdr->p past unused types */
4378 p = xdr_inline_decode(xdr, num * 4);
4379 if (unlikely(!p))
4380 goto out_overflow;
4381 *layouttype = be32_to_cpup(p);
4382 return 0;
4383out_overflow:
4384 print_overflow_msg(__func__, xdr);
4385 return -EIO;
4386}
4387
4388/*
4389 * The type of file system exported.
4390 * Note we must ensure that layouttype is set in any non-error case.
4391 */
4392static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4393 uint32_t *layouttype)
4394{
4395 int status = 0;
4396
4397 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4398 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4399 return -EIO;
4400 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4401 status = decode_first_pnfs_layout_type(xdr, layouttype);
4402 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4403 } else
4404 *layouttype = 0;
4405 return status;
4406}
4407
Fred Isamandae100c2011-07-30 20:52:37 -04004408/*
4409 * The prefered block size for layout directed io
4410 */
4411static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4412 uint32_t *res)
4413{
4414 __be32 *p;
4415
4416 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4417 *res = 0;
4418 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4419 p = xdr_inline_decode(xdr, 4);
4420 if (unlikely(!p)) {
4421 print_overflow_msg(__func__, xdr);
4422 return -EIO;
4423 }
4424 *res = be32_to_cpup(p);
4425 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4426 }
4427 return 0;
4428}
4429
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4431{
Al Viro8687b632006-10-19 23:28:48 -07004432 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004433 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 int status;
4435
4436 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4437 goto xdr_error;
4438 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4439 goto xdr_error;
4440 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4441 goto xdr_error;
4442
4443 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4444
4445 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4446 goto xdr_error;
4447 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4448 goto xdr_error;
4449 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4450 goto xdr_error;
4451 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4452 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4453 goto xdr_error;
4454 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004455 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4456 if (status != 0)
4457 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004458 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4459 if (status != 0)
4460 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004461 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4462 if (status)
4463 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464
4465 status = verify_attr_len(xdr, savep, attrlen);
4466xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004467 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 return status;
4469}
4470
4471static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4472{
Al Viro8687b632006-10-19 23:28:48 -07004473 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 uint32_t len;
4475 int status;
4476
Trond Myklebust99367812007-07-17 21:52:41 -04004477 /* Zero handle first to allow comparisons */
4478 memset(fh, 0, sizeof(*fh));
4479
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 status = decode_op_hdr(xdr, OP_GETFH);
4481 if (status)
4482 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483
Benny Halevyc0eae662009-08-14 17:20:14 +03004484 p = xdr_inline_decode(xdr, 4);
4485 if (unlikely(!p))
4486 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004487 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 if (len > NFS4_FHSIZE)
4489 return -EIO;
4490 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004491 p = xdr_inline_decode(xdr, len);
4492 if (unlikely(!p))
4493 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004494 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004496out_overflow:
4497 print_overflow_msg(__func__, xdr);
4498 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499}
4500
4501static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4502{
4503 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004504
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 status = decode_op_hdr(xdr, OP_LINK);
4506 if (status)
4507 return status;
4508 return decode_change_info(xdr, cinfo);
4509}
4510
4511/*
4512 * We create the owner, so we know a proper owner.id length is 4.
4513 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004514static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004516 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004517 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004518 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004520 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004521 if (unlikely(!p))
4522 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004523 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004524 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004525 type = be32_to_cpup(p++); /* 4 byte read */
4526 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004527 fl->fl_start = (loff_t)offset;
4528 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4529 if (length == ~(uint64_t)0)
4530 fl->fl_end = OFFSET_MAX;
4531 fl->fl_type = F_WRLCK;
4532 if (type & 1)
4533 fl->fl_type = F_RDLCK;
4534 fl->fl_pid = 0;
4535 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004536 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4537 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4538 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004539 if (likely(p))
4540 return -NFS4ERR_DENIED;
4541out_overflow:
4542 print_overflow_msg(__func__, xdr);
4543 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544}
4545
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004546static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 int status;
4549
4550 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004551 if (status == -EIO)
4552 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004554 status = decode_stateid(xdr, &res->stateid);
4555 if (unlikely(status))
4556 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004558 status = decode_lock_denied(xdr, NULL);
4559 if (res->open_seqid != NULL)
4560 nfs_increment_open_seqid(status, res->open_seqid);
4561 nfs_increment_lock_seqid(status, res->lock_seqid);
4562out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 return status;
4564}
4565
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004566static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567{
4568 int status;
4569 status = decode_op_hdr(xdr, OP_LOCKT);
4570 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004571 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 return status;
4573}
4574
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004575static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 int status;
4578
4579 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004580 if (status != -EIO)
4581 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004582 if (status == 0)
4583 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 return status;
4585}
4586
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004587static int decode_release_lockowner(struct xdr_stream *xdr)
4588{
4589 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4590}
4591
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592static int decode_lookup(struct xdr_stream *xdr)
4593{
4594 return decode_op_hdr(xdr, OP_LOOKUP);
4595}
4596
4597/* This is too sick! */
4598static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4599{
Andy Adamson05d564f2008-12-23 16:06:15 -05004600 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 uint32_t limit_type, nblocks, blocksize;
4602
Benny Halevyc0eae662009-08-14 17:20:14 +03004603 p = xdr_inline_decode(xdr, 12);
4604 if (unlikely(!p))
4605 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004606 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004608 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004609 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004610 break;
4611 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004612 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004613 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004614 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615 }
4616 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004617out_overflow:
4618 print_overflow_msg(__func__, xdr);
4619 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620}
4621
4622static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4623{
Andy Adamson05d564f2008-12-23 16:06:15 -05004624 __be32 *p;
4625 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004626 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627
Benny Halevyc0eae662009-08-14 17:20:14 +03004628 p = xdr_inline_decode(xdr, 4);
4629 if (unlikely(!p))
4630 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004631 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4633 res->delegation_type = 0;
4634 return 0;
4635 }
Benny Halevy07d30432009-08-14 17:19:52 +03004636 status = decode_stateid(xdr, &res->delegation);
4637 if (unlikely(status))
4638 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004639 p = xdr_inline_decode(xdr, 4);
4640 if (unlikely(!p))
4641 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004642 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004643
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004645 case NFS4_OPEN_DELEGATE_READ:
4646 res->delegation_type = FMODE_READ;
4647 break;
4648 case NFS4_OPEN_DELEGATE_WRITE:
4649 res->delegation_type = FMODE_WRITE|FMODE_READ;
4650 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 return -EIO;
4652 }
David Howells7539bba2006-08-22 20:06:09 -04004653 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004654out_overflow:
4655 print_overflow_msg(__func__, xdr);
4656 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657}
4658
4659static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4660{
Andy Adamson05d564f2008-12-23 16:06:15 -05004661 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004662 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004663 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664
Andy Adamson05d564f2008-12-23 16:06:15 -05004665 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004666 if (status != -EIO)
4667 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004668 if (!status)
4669 status = decode_stateid(xdr, &res->stateid);
4670 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004671 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672
Andy Adamson05d564f2008-12-23 16:06:15 -05004673 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674
Benny Halevyc0eae662009-08-14 17:20:14 +03004675 p = xdr_inline_decode(xdr, 8);
4676 if (unlikely(!p))
4677 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004678 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004679 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004680 if (bmlen > 10)
4681 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682
Benny Halevyc0eae662009-08-14 17:20:14 +03004683 p = xdr_inline_decode(xdr, bmlen << 2);
4684 if (unlikely(!p))
4685 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004686 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4687 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004688 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004689 for (; i < NFS4_BITMAP_SIZE; i++)
4690 res->attrset[i] = 0;
4691
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 return decode_delegation(xdr, res);
4693xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004694 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004696out_overflow:
4697 print_overflow_msg(__func__, xdr);
4698 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699}
4700
4701static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4702{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 int status;
4704
Andy Adamson05d564f2008-12-23 16:06:15 -05004705 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004706 if (status != -EIO)
4707 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004708 if (!status)
4709 status = decode_stateid(xdr, &res->stateid);
4710 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711}
4712
4713static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4714{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 int status;
4716
4717 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004718 if (status != -EIO)
4719 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004720 if (!status)
4721 status = decode_stateid(xdr, &res->stateid);
4722 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723}
4724
4725static int decode_putfh(struct xdr_stream *xdr)
4726{
4727 return decode_op_hdr(xdr, OP_PUTFH);
4728}
4729
4730static int decode_putrootfh(struct xdr_stream *xdr)
4731{
4732 return decode_op_hdr(xdr, OP_PUTROOTFH);
4733}
4734
4735static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4736{
4737 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 uint32_t count, eof, recvd, hdrlen;
4740 int status;
4741
4742 status = decode_op_hdr(xdr, OP_READ);
4743 if (status)
4744 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004745 p = xdr_inline_decode(xdr, 8);
4746 if (unlikely(!p))
4747 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004748 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004749 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004750 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 recvd = req->rq_rcv_buf.len - hdrlen;
4752 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004753 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 "count %u > recvd %u\n", count, recvd);
4755 count = recvd;
4756 eof = 0;
4757 }
4758 xdr_read_pages(xdr, count);
4759 res->eof = eof;
4760 res->count = count;
4761 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004762out_overflow:
4763 print_overflow_msg(__func__, xdr);
4764 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765}
4766
4767static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4768{
4769 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004771 size_t hdrlen;
4772 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004773 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004774 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775
4776 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004777 if (!status)
4778 status = decode_verifier(xdr, readdir->verifier.data);
4779 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004781 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004782 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004783 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784
Benny Halevydb942bb2009-08-14 17:19:56 +03004785 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 recvd = rcvbuf->len - hdrlen;
4787 if (pglen > recvd)
4788 pglen = recvd;
4789 xdr_read_pages(xdr, pglen);
4790
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004791
Trond Myklebustac396122010-11-15 20:26:22 -05004792 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793}
4794
4795static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4796{
4797 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4798 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004799 size_t hdrlen;
4800 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004801 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 int status;
4803
4804 status = decode_op_hdr(xdr, OP_READLINK);
4805 if (status)
4806 return status;
4807
4808 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004809 p = xdr_inline_decode(xdr, 4);
4810 if (unlikely(!p))
4811 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004812 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004814 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 return -ENAMETOOLONG;
4816 }
4817 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4818 recvd = req->rq_rcv_buf.len - hdrlen;
4819 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004820 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 "count %u > recvd %u\n", len, recvd);
4822 return -EIO;
4823 }
4824 xdr_read_pages(xdr, len);
4825 /*
4826 * The XDR encode routine has set things up so that
4827 * the link text will be copied directly into the
4828 * buffer. We just have to do overflow-checking,
4829 * and and null-terminate the text (the VFS expects
4830 * null-termination).
4831 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004832 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004834out_overflow:
4835 print_overflow_msg(__func__, xdr);
4836 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837}
4838
4839static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4840{
4841 int status;
4842
4843 status = decode_op_hdr(xdr, OP_REMOVE);
4844 if (status)
4845 goto out;
4846 status = decode_change_info(xdr, cinfo);
4847out:
4848 return status;
4849}
4850
4851static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4852 struct nfs4_change_info *new_cinfo)
4853{
4854 int status;
4855
4856 status = decode_op_hdr(xdr, OP_RENAME);
4857 if (status)
4858 goto out;
4859 if ((status = decode_change_info(xdr, old_cinfo)))
4860 goto out;
4861 status = decode_change_info(xdr, new_cinfo);
4862out:
4863 return status;
4864}
4865
4866static int decode_renew(struct xdr_stream *xdr)
4867{
4868 return decode_op_hdr(xdr, OP_RENEW);
4869}
4870
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004871static int
4872decode_restorefh(struct xdr_stream *xdr)
4873{
4874 return decode_op_hdr(xdr, OP_RESTOREFH);
4875}
4876
J. Bruce Fields029d1052005-06-22 17:16:22 +00004877static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004878 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004879{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004880 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004881 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004882 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004883 struct kvec *iov = req->rq_rcv_buf.head;
4884 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004885 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004886
Andy Adamsonbf118a32011-12-07 11:55:27 -05004887 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004888 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4889 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004890
Andy Adamsonbf118a32011-12-07 11:55:27 -05004891 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004892 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4893 res->acl_data_offset <<= 2;
4894 /* Check if the acl data starts beyond the allocated buffer */
4895 if (res->acl_data_offset > page_len)
4896 return -ERANGE;
4897
J. Bruce Fields029d1052005-06-22 17:16:22 +00004898 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4899 goto out;
4900 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4901 goto out;
4902
4903 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4904 return -EIO;
4905 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004906 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004907
Andy Adamsonbf118a32011-12-07 11:55:27 -05004908 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4909 * are stored with the acl data to handle the problem of
4910 * variable length bitmaps.*/
4911 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004912
J. Bruce Fields029d1052005-06-22 17:16:22 +00004913 /* We ignore &savep and don't do consistency checks on
4914 * the attr length. Let userspace figure it out.... */
4915 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004916 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004917 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004918 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4919 /* getxattr interface called with a NULL buf */
4920 res->acl_len = attrlen;
4921 goto out;
4922 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01004923 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01004924 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004925 return -EINVAL;
4926 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004927 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004928 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004929 } else
4930 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004931
4932out:
4933 return status;
4934}
4935
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936static int
4937decode_savefh(struct xdr_stream *xdr)
4938{
4939 return decode_op_hdr(xdr, OP_SAVEFH);
4940}
4941
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004942static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943{
Al Viro8687b632006-10-19 23:28:48 -07004944 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 uint32_t bmlen;
4946 int status;
4947
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 status = decode_op_hdr(xdr, OP_SETATTR);
4949 if (status)
4950 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004951 p = xdr_inline_decode(xdr, 4);
4952 if (unlikely(!p))
4953 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004954 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004955 p = xdr_inline_decode(xdr, bmlen << 2);
4956 if (likely(p))
4957 return 0;
4958out_overflow:
4959 print_overflow_msg(__func__, xdr);
4960 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961}
4962
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004963static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964{
Al Viro8687b632006-10-19 23:28:48 -07004965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 uint32_t opnum;
4967 int32_t nfserr;
4968
Benny Halevyc0eae662009-08-14 17:20:14 +03004969 p = xdr_inline_decode(xdr, 8);
4970 if (unlikely(!p))
4971 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004972 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004974 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004975 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 return -EIO;
4977 }
Benny Halevycccddf42009-08-14 17:20:19 +03004978 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004980 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4981 if (unlikely(!p))
4982 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004983 p = xdr_decode_hyper(p, &res->clientid);
4984 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 } else if (nfserr == NFSERR_CLID_INUSE) {
4986 uint32_t len;
4987
4988 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004989 p = xdr_inline_decode(xdr, 4);
4990 if (unlikely(!p))
4991 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004992 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004993 p = xdr_inline_decode(xdr, len);
4994 if (unlikely(!p))
4995 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996
4997 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004998 p = xdr_inline_decode(xdr, 4);
4999 if (unlikely(!p))
5000 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005001 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, len);
5003 if (unlikely(!p))
5004 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 return -NFSERR_CLID_INUSE;
5006 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005007 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008
5009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005010out_overflow:
5011 print_overflow_msg(__func__, xdr);
5012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013}
5014
5015static int decode_setclientid_confirm(struct xdr_stream *xdr)
5016{
5017 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5018}
5019
5020static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5021{
Al Viro8687b632006-10-19 23:28:48 -07005022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 int status;
5024
5025 status = decode_op_hdr(xdr, OP_WRITE);
5026 if (status)
5027 return status;
5028
Benny Halevyc0eae662009-08-14 17:20:14 +03005029 p = xdr_inline_decode(xdr, 16);
5030 if (unlikely(!p))
5031 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005032 res->count = be32_to_cpup(p++);
5033 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005034 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005036out_overflow:
5037 print_overflow_msg(__func__, xdr);
5038 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039}
5040
5041static int decode_delegreturn(struct xdr_stream *xdr)
5042{
5043 return decode_op_hdr(xdr, OP_DELEGRETURN);
5044}
5045
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005046static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5047{
5048 __be32 *p;
5049
5050 p = xdr_inline_decode(xdr, 4);
5051 if (unlikely(!p))
5052 goto out_overflow;
5053 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5054 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5055 goto out_err;
5056
5057 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5058 if (unlikely(!p))
5059 goto out_overflow;
5060 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5061
5062 p = xdr_inline_decode(xdr, 8);
5063 if (unlikely(!p))
5064 goto out_overflow;
5065 flavor->gss.qop4 = be32_to_cpup(p++);
5066 flavor->gss.service = be32_to_cpup(p);
5067
5068 return 0;
5069
5070out_overflow:
5071 print_overflow_msg(__func__, xdr);
5072 return -EIO;
5073out_err:
5074 return -EINVAL;
5075}
5076
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005077static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005078{
5079 struct nfs4_secinfo_flavor *sec_flavor;
5080 int status;
5081 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005082 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005083
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005084 p = xdr_inline_decode(xdr, 4);
5085 if (unlikely(!p))
5086 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005087
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005088 res->flavors->num_flavors = 0;
5089 num_flavors = be32_to_cpup(p);
5090
5091 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005092 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005093 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005094 break;
5095
5096 p = xdr_inline_decode(xdr, 4);
5097 if (unlikely(!p))
5098 goto out_overflow;
5099 sec_flavor->flavor = be32_to_cpup(p);
5100
5101 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005102 status = decode_secinfo_gss(xdr, sec_flavor);
5103 if (status)
5104 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005105 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005106 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005107 }
5108
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005109 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005110out:
5111 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005112out_overflow:
5113 print_overflow_msg(__func__, xdr);
5114 return -EIO;
5115}
5116
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005117static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5118{
5119 int status = decode_op_hdr(xdr, OP_SECINFO);
5120 if (status)
5121 return status;
5122 return decode_secinfo_common(xdr, res);
5123}
5124
Benny Halevy99fe60d2009-04-01 09:22:29 -04005125#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005126static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5127{
5128 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5129 if (status)
5130 return status;
5131 return decode_secinfo_common(xdr, res);
5132}
5133
Benny Halevy99fe60d2009-04-01 09:22:29 -04005134static int decode_exchange_id(struct xdr_stream *xdr,
5135 struct nfs41_exchange_id_res *res)
5136{
5137 __be32 *p;
5138 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005139 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005140 int status;
5141 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005142 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005143
5144 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5145 if (status)
5146 return status;
5147
Benny Halevyc0eae662009-08-14 17:20:14 +03005148 p = xdr_inline_decode(xdr, 8);
5149 if (unlikely(!p))
5150 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005151 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005152 p = xdr_inline_decode(xdr, 12);
5153 if (unlikely(!p))
5154 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005155 clp->cl_seqid = be32_to_cpup(p++);
5156 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005157
5158 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005159 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005160 if (dummy != SP4_NONE)
5161 return -EIO;
5162
5163 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005164 p = xdr_inline_decode(xdr, 8);
5165 if (unlikely(!p))
5166 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005167
5168 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005169 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5170 if (unlikely(status))
5171 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005172
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005173 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005174 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5175 if (unlikely(status))
5176 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005177
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005178 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5179 return -EIO;
5180
5181 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5182 res->server_scope->server_scope_sz = dummy;
5183
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005184 /* Implementation Id */
5185 p = xdr_inline_decode(xdr, 4);
5186 if (unlikely(!p))
5187 goto out_overflow;
5188 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005189
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005190 if (impl_id_count) {
5191 /* nii_domain */
5192 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5193 if (unlikely(status))
5194 return status;
5195 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5196 return -EIO;
5197 memcpy(res->impl_id->domain, dummy_str, dummy);
5198
5199 /* nii_name */
5200 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5201 if (unlikely(status))
5202 return status;
5203 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5204 return -EIO;
5205 memcpy(res->impl_id->name, dummy_str, dummy);
5206
5207 /* nii_date */
5208 p = xdr_inline_decode(xdr, 12);
5209 if (unlikely(!p))
5210 goto out_overflow;
5211 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5212 res->impl_id->date.nseconds = be32_to_cpup(p);
5213
5214 /* if there's more than one entry, ignore the rest */
5215 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005216 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005217out_overflow:
5218 print_overflow_msg(__func__, xdr);
5219 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005220}
Andy Adamsonfc931582009-04-01 09:22:31 -04005221
5222static int decode_chan_attrs(struct xdr_stream *xdr,
5223 struct nfs4_channel_attrs *attrs)
5224{
5225 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005226 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005227
Benny Halevyc0eae662009-08-14 17:20:14 +03005228 p = xdr_inline_decode(xdr, 28);
5229 if (unlikely(!p))
5230 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005231 val = be32_to_cpup(p++); /* headerpadsz */
5232 if (val)
5233 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005234 attrs->max_rqst_sz = be32_to_cpup(p++);
5235 attrs->max_resp_sz = be32_to_cpup(p++);
5236 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5237 attrs->max_ops = be32_to_cpup(p++);
5238 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005239 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005240 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005241 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5242 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005243 return -EINVAL;
5244 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005245 if (nr_attrs == 1) {
5246 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5247 if (unlikely(!p))
5248 goto out_overflow;
5249 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005250 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005251out_overflow:
5252 print_overflow_msg(__func__, xdr);
5253 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005254}
5255
Benny Halevye78291e2009-08-14 17:20:00 +03005256static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5257{
5258 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005259}
5260
5261static int decode_create_session(struct xdr_stream *xdr,
5262 struct nfs41_create_session_res *res)
5263{
5264 __be32 *p;
5265 int status;
5266 struct nfs_client *clp = res->client;
5267 struct nfs4_session *session = clp->cl_session;
5268
5269 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005270 if (!status)
5271 status = decode_sessionid(xdr, &session->sess_id);
5272 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005273 return status;
5274
Andy Adamsonfc931582009-04-01 09:22:31 -04005275 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005276 p = xdr_inline_decode(xdr, 8);
5277 if (unlikely(!p))
5278 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005279 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005280 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005281
5282 /* Channel attributes */
5283 status = decode_chan_attrs(xdr, &session->fc_attrs);
5284 if (!status)
5285 status = decode_chan_attrs(xdr, &session->bc_attrs);
5286 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005287out_overflow:
5288 print_overflow_msg(__func__, xdr);
5289 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005290}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005291
5292static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5293{
5294 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5295}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005296
5297static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5298{
5299 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5300}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005301#endif /* CONFIG_NFS_V4_1 */
5302
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005303static int decode_sequence(struct xdr_stream *xdr,
5304 struct nfs4_sequence_res *res,
5305 struct rpc_rqst *rqstp)
5306{
5307#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005308 struct nfs4_sessionid id;
5309 u32 dummy;
5310 int status;
5311 __be32 *p;
5312
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005313 if (!res->sr_session)
5314 return 0;
5315
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005316 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005317 if (!status)
5318 status = decode_sessionid(xdr, &id);
5319 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005320 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005321
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005322 /*
5323 * If the server returns different values for sessionID, slotID or
5324 * sequence number, the server is looney tunes.
5325 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005326 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005327
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005328 if (memcmp(id.data, res->sr_session->sess_id.data,
5329 NFS4_MAX_SESSIONID_LEN)) {
5330 dprintk("%s Invalid session id\n", __func__);
5331 goto out_err;
5332 }
Benny Halevye78291e2009-08-14 17:20:00 +03005333
Benny Halevyc0eae662009-08-14 17:20:14 +03005334 p = xdr_inline_decode(xdr, 20);
5335 if (unlikely(!p))
5336 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005337
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005338 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005339 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005340 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005341 dprintk("%s Invalid sequence number\n", __func__);
5342 goto out_err;
5343 }
5344 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005345 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005346 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005347 dprintk("%s Invalid slot id\n", __func__);
5348 goto out_err;
5349 }
5350 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005351 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005352 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005353 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005354 /* result flags */
5355 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005356 status = 0;
5357out_err:
5358 res->sr_status = status;
5359 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005360out_overflow:
5361 print_overflow_msg(__func__, xdr);
5362 status = -EIO;
5363 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005364#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005365 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005366#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005367}
5368
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005369#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005370/*
5371 * TODO: Need to handle case when EOF != true;
5372 */
5373static int decode_getdevicelist(struct xdr_stream *xdr,
5374 struct pnfs_devicelist *res)
5375{
5376 __be32 *p;
5377 int status, i;
5378 struct nfs_writeverf verftemp;
5379
5380 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5381 if (status)
5382 return status;
5383
5384 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5385 if (unlikely(!p))
5386 goto out_overflow;
5387
5388 /* TODO: Skip cookie for now */
5389 p += 2;
5390
5391 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005392 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005393
5394 res->num_devs = be32_to_cpup(p);
5395
5396 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5397
5398 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005399 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005400 __func__, res->num_devs);
5401 return -EIO;
5402 }
5403
5404 p = xdr_inline_decode(xdr,
5405 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5406 if (unlikely(!p))
5407 goto out_overflow;
5408 for (i = 0; i < res->num_devs; i++)
5409 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5410 NFS4_DEVICEID4_SIZE);
5411 res->eof = be32_to_cpup(p);
5412 return 0;
5413out_overflow:
5414 print_overflow_msg(__func__, xdr);
5415 return -EIO;
5416}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005417
5418static int decode_getdeviceinfo(struct xdr_stream *xdr,
5419 struct pnfs_device *pdev)
5420{
5421 __be32 *p;
5422 uint32_t len, type;
5423 int status;
5424
5425 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5426 if (status) {
5427 if (status == -ETOOSMALL) {
5428 p = xdr_inline_decode(xdr, 4);
5429 if (unlikely(!p))
5430 goto out_overflow;
5431 pdev->mincount = be32_to_cpup(p);
5432 dprintk("%s: Min count too small. mincnt = %u\n",
5433 __func__, pdev->mincount);
5434 }
5435 return status;
5436 }
5437
5438 p = xdr_inline_decode(xdr, 8);
5439 if (unlikely(!p))
5440 goto out_overflow;
5441 type = be32_to_cpup(p++);
5442 if (type != pdev->layout_type) {
5443 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5444 __func__, pdev->layout_type, type);
5445 return -EINVAL;
5446 }
5447 /*
5448 * Get the length of the opaque device_addr4. xdr_read_pages places
5449 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5450 * and places the remaining xdr data in xdr_buf->tail
5451 */
5452 pdev->mincount = be32_to_cpup(p);
5453 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5454
5455 /* Parse notification bitmap, verifying that it is zero. */
5456 p = xdr_inline_decode(xdr, 4);
5457 if (unlikely(!p))
5458 goto out_overflow;
5459 len = be32_to_cpup(p);
5460 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005461 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005462
5463 p = xdr_inline_decode(xdr, 4 * len);
5464 if (unlikely(!p))
5465 goto out_overflow;
5466 for (i = 0; i < len; i++, p++) {
5467 if (be32_to_cpup(p)) {
5468 dprintk("%s: notifications not supported\n",
5469 __func__);
5470 return -EIO;
5471 }
5472 }
5473 }
5474 return 0;
5475out_overflow:
5476 print_overflow_msg(__func__, xdr);
5477 return -EIO;
5478}
5479
5480static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5481 struct nfs4_layoutget_res *res)
5482{
5483 __be32 *p;
5484 int status;
5485 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005486 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5487 struct kvec *iov = rcvbuf->head;
5488 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005489
5490 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5491 if (status)
5492 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005493 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005494 if (unlikely(!p))
5495 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005496 res->return_on_close = be32_to_cpup(p);
5497 decode_stateid(xdr, &res->stateid);
5498 p = xdr_inline_decode(xdr, 4);
5499 if (unlikely(!p))
5500 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005501 layout_count = be32_to_cpup(p);
5502 if (!layout_count) {
5503 dprintk("%s: server responded with empty layout array\n",
5504 __func__);
5505 return -EINVAL;
5506 }
5507
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005508 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005509 if (unlikely(!p))
5510 goto out_overflow;
5511 p = xdr_decode_hyper(p, &res->range.offset);
5512 p = xdr_decode_hyper(p, &res->range.length);
5513 res->range.iomode = be32_to_cpup(p++);
5514 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005515 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005516
5517 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5518 __func__,
5519 (unsigned long)res->range.offset,
5520 (unsigned long)res->range.length,
5521 res->range.iomode,
5522 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005523 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005524
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005525 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5526 recvd = req->rq_rcv_buf.len - hdrlen;
5527 if (res->layoutp->len > recvd) {
5528 dprintk("NFS: server cheating in layoutget reply: "
5529 "layout len %u > recvd %u\n",
5530 res->layoutp->len, recvd);
5531 return -EINVAL;
5532 }
5533
5534 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005535
5536 if (layout_count > 1) {
5537 /* We only handle a length one array at the moment. Any
5538 * further entries are just ignored. Note that this means
5539 * the client may see a response that is less than the
5540 * minimum it requested.
5541 */
5542 dprintk("%s: server responded with %d layouts, dropping tail\n",
5543 __func__, layout_count);
5544 }
5545
5546 return 0;
5547out_overflow:
5548 print_overflow_msg(__func__, xdr);
5549 return -EIO;
5550}
Andy Adamson863a3c62011-03-23 13:27:54 +00005551
Benny Halevycbe82602011-05-22 19:52:37 +03005552static int decode_layoutreturn(struct xdr_stream *xdr,
5553 struct nfs4_layoutreturn_res *res)
5554{
5555 __be32 *p;
5556 int status;
5557
5558 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5559 if (status)
5560 return status;
5561 p = xdr_inline_decode(xdr, 4);
5562 if (unlikely(!p))
5563 goto out_overflow;
5564 res->lrs_present = be32_to_cpup(p);
5565 if (res->lrs_present)
5566 status = decode_stateid(xdr, &res->stateid);
5567 return status;
5568out_overflow:
5569 print_overflow_msg(__func__, xdr);
5570 return -EIO;
5571}
5572
Andy Adamson863a3c62011-03-23 13:27:54 +00005573static int decode_layoutcommit(struct xdr_stream *xdr,
5574 struct rpc_rqst *req,
5575 struct nfs4_layoutcommit_res *res)
5576{
5577 __be32 *p;
5578 __u32 sizechanged;
5579 int status;
5580
5581 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005582 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005583 if (status)
5584 return status;
5585
5586 p = xdr_inline_decode(xdr, 4);
5587 if (unlikely(!p))
5588 goto out_overflow;
5589 sizechanged = be32_to_cpup(p);
5590
5591 if (sizechanged) {
5592 /* throw away new size */
5593 p = xdr_inline_decode(xdr, 8);
5594 if (unlikely(!p))
5595 goto out_overflow;
5596 }
5597 return 0;
5598out_overflow:
5599 print_overflow_msg(__func__, xdr);
5600 return -EIO;
5601}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005602
5603static int decode_test_stateid(struct xdr_stream *xdr,
5604 struct nfs41_test_stateid_res *res)
5605{
5606 __be32 *p;
5607 int status;
5608 int num_res;
5609
5610 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5611 if (status)
5612 return status;
5613
5614 p = xdr_inline_decode(xdr, 4);
5615 if (unlikely(!p))
5616 goto out_overflow;
5617 num_res = be32_to_cpup(p++);
5618 if (num_res != 1)
5619 goto out;
5620
5621 p = xdr_inline_decode(xdr, 4);
5622 if (unlikely(!p))
5623 goto out_overflow;
5624 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005625
5626 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005627out_overflow:
5628 print_overflow_msg(__func__, xdr);
5629out:
5630 return -EIO;
5631}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005632
5633static int decode_free_stateid(struct xdr_stream *xdr,
5634 struct nfs41_free_stateid_res *res)
5635{
5636 __be32 *p;
5637 int status;
5638
5639 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5640 if (status)
5641 return status;
5642
5643 p = xdr_inline_decode(xdr, 4);
5644 if (unlikely(!p))
5645 goto out_overflow;
5646 res->status = be32_to_cpup(p++);
5647 return res->status;
5648out_overflow:
5649 print_overflow_msg(__func__, xdr);
5650 return -EIO;
5651}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005652#endif /* CONFIG_NFS_V4_1 */
5653
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654/*
Benny Halevy49c25592008-12-23 16:06:16 -05005655 * END OF "GENERIC" DECODE ROUTINES.
5656 */
5657
5658/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659 * Decode OPEN_DOWNGRADE response
5660 */
Chuck Leverbf269552010-12-14 14:59:29 +00005661static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5662 struct xdr_stream *xdr,
5663 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005664{
Andy Adamson05d564f2008-12-23 16:06:15 -05005665 struct compound_hdr hdr;
5666 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667
Chuck Leverbf269552010-12-14 14:59:29 +00005668 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005669 if (status)
5670 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005671 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005672 if (status)
5673 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005674 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005675 if (status)
5676 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005677 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005678 if (status != 0)
5679 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005680 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005682 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005683}
5684
5685/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 * Decode ACCESS response
5687 */
Chuck Leverbf269552010-12-14 14:59:29 +00005688static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5689 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005690{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691 struct compound_hdr hdr;
5692 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005693
Chuck Leverbf269552010-12-14 14:59:29 +00005694 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005695 if (status)
5696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005697 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005698 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005700 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005701 if (status != 0)
5702 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005703 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005704 if (status != 0)
5705 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005706 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005707out:
5708 return status;
5709}
5710
5711/*
5712 * Decode LOOKUP response
5713 */
Chuck Leverbf269552010-12-14 14:59:29 +00005714static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5715 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717 struct compound_hdr hdr;
5718 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005719
Chuck Leverbf269552010-12-14 14:59:29 +00005720 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005721 if (status)
5722 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005723 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005724 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005726 status = decode_putfh(xdr);
5727 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005729 status = decode_lookup(xdr);
5730 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005732 status = decode_getfh(xdr, res->fh);
5733 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005735 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736out:
5737 return status;
5738}
5739
5740/*
5741 * Decode LOOKUP_ROOT response
5742 */
Chuck Leverbf269552010-12-14 14:59:29 +00005743static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5744 struct xdr_stream *xdr,
5745 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 struct compound_hdr hdr;
5748 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005749
Chuck Leverbf269552010-12-14 14:59:29 +00005750 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005751 if (status)
5752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005753 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005754 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_putrootfh(xdr);
5757 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_getfh(xdr, res->fh);
5760 if (status == 0)
Trond Myklebust6926afd12012-01-07 13:22:46 -05005761 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762out:
5763 return status;
5764}
5765
5766/*
5767 * Decode REMOVE response
5768 */
Chuck Leverbf269552010-12-14 14:59:29 +00005769static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5770 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772 struct compound_hdr hdr;
5773 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005774
Chuck Leverbf269552010-12-14 14:59:29 +00005775 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005776 if (status)
5777 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005778 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005779 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005781 status = decode_putfh(xdr);
5782 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005784 status = decode_remove(xdr, &res->cinfo);
5785 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005786 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005787 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788out:
5789 return status;
5790}
5791
5792/*
5793 * Decode RENAME response
5794 */
Chuck Leverbf269552010-12-14 14:59:29 +00005795static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5796 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798 struct compound_hdr hdr;
5799 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005800
Chuck Leverbf269552010-12-14 14:59:29 +00005801 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005802 if (status)
5803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005804 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005805 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005807 status = decode_putfh(xdr);
5808 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005810 status = decode_savefh(xdr);
5811 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005813 status = decode_putfh(xdr);
5814 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005816 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5817 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005818 goto out;
5819 /* Current FH is target directory */
Trond Myklebust6926afd12012-01-07 13:22:46 -05005820 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_restorefh(xdr);
5823 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005824 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005825 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826out:
5827 return status;
5828}
5829
5830/*
5831 * Decode LINK response
5832 */
Chuck Leverbf269552010-12-14 14:59:29 +00005833static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5834 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 struct compound_hdr hdr;
5837 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005838
Chuck Leverbf269552010-12-14 14:59:29 +00005839 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005840 if (status)
5841 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005842 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005843 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005845 status = decode_putfh(xdr);
5846 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_savefh(xdr);
5849 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_putfh(xdr);
5852 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_link(xdr, &res->cinfo);
5855 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005856 goto out;
5857 /*
5858 * Note order: OP_LINK leaves the directory as the current
5859 * filehandle.
5860 */
Trond Myklebust6926afd12012-01-07 13:22:46 -05005861 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_restorefh(xdr);
5864 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005865 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005866 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867out:
5868 return status;
5869}
5870
5871/*
5872 * Decode CREATE response
5873 */
Chuck Leverbf269552010-12-14 14:59:29 +00005874static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5875 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 struct compound_hdr hdr;
5878 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005879
Chuck Leverbf269552010-12-14 14:59:29 +00005880 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005881 if (status)
5882 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005883 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005884 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005886 status = decode_putfh(xdr);
5887 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_create(xdr, &res->dir_cinfo);
5890 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_getfh(xdr, res->fh);
5893 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04005895 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896out:
5897 return status;
5898}
5899
5900/*
5901 * Decode SYMLINK response
5902 */
Chuck Leverbf269552010-12-14 14:59:29 +00005903static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5904 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905{
Chuck Leverbf269552010-12-14 14:59:29 +00005906 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907}
5908
5909/*
5910 * Decode GETATTR response
5911 */
Chuck Leverbf269552010-12-14 14:59:29 +00005912static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5913 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915 struct compound_hdr hdr;
5916 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005917
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 if (status)
5920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005922 if (status)
5923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005924 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 if (status)
5926 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005927 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928out:
5929 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930}
5931
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005932/*
5933 * Encode an SETACL request
5934 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005935static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5936 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005937{
Andy Adamson05d564f2008-12-23 16:06:15 -05005938 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005940 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005941
Chuck Lever9f06c712010-12-14 14:59:18 +00005942 encode_compound_hdr(xdr, req, &hdr);
5943 encode_sequence(xdr, &args->seq_args, &hdr);
5944 encode_putfh(xdr, args->fh, &hdr);
5945 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005946 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005947}
Andy Adamson05d564f2008-12-23 16:06:15 -05005948
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005949/*
5950 * Decode SETACL response
5951 */
5952static int
Chuck Leverbf269552010-12-14 14:59:29 +00005953nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005954 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005955{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005956 struct compound_hdr hdr;
5957 int status;
5958
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005960 if (status)
5961 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005963 if (status)
5964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005966 if (status)
5967 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005969out:
5970 return status;
5971}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972
5973/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005974 * Decode GETACL response
5975 */
5976static int
Chuck Leverbf269552010-12-14 14:59:29 +00005977nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005978 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005979{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005980 struct compound_hdr hdr;
5981 int status;
5982
Trond Myklebust331818f2012-02-03 18:30:53 -05005983 if (res->acl_scratch != NULL) {
5984 void *p = page_address(res->acl_scratch);
5985 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5986 }
Chuck Leverbf269552010-12-14 14:59:29 +00005987 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005988 if (status)
5989 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005991 if (status)
5992 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005994 if (status)
5995 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005996 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005997
5998out:
5999 return status;
6000}
6001
6002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 * Decode CLOSE response
6004 */
Chuck Leverbf269552010-12-14 14:59:29 +00006005static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6006 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007{
Andy Adamson05d564f2008-12-23 16:06:15 -05006008 struct compound_hdr hdr;
6009 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006012 if (status)
6013 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006015 if (status)
6016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006018 if (status)
6019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006021 if (status != 0)
6022 goto out;
6023 /*
6024 * Note: Server may do delete on close for this file
6025 * in which case the getattr call will fail with
6026 * an ESTALE error. Shouldn't be a problem,
6027 * though, since fattr->valid will remain unset.
6028 */
Trond Myklebust6926afd12012-01-07 13:22:46 -05006029 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006031 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032}
6033
6034/*
6035 * Decode OPEN response
6036 */
Chuck Leverbf269552010-12-14 14:59:29 +00006037static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6038 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039{
Andy Adamson05d564f2008-12-23 16:06:15 -05006040 struct compound_hdr hdr;
6041 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006044 if (status)
6045 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006047 if (status)
6048 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006053 if (status)
6054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006057 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006059 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060}
6061
6062/*
6063 * Decode OPEN_CONFIRM response
6064 */
Chuck Leverbf269552010-12-14 14:59:29 +00006065static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6066 struct xdr_stream *xdr,
6067 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006068{
Andy Adamson05d564f2008-12-23 16:06:15 -05006069 struct compound_hdr hdr;
6070 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071
Chuck Leverbf269552010-12-14 14:59:29 +00006072 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006073 if (status)
6074 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006076 if (status)
6077 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006080 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081}
6082
6083/*
6084 * Decode OPEN response
6085 */
Chuck Leverbf269552010-12-14 14:59:29 +00006086static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6087 struct xdr_stream *xdr,
6088 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089{
Andy Adamson05d564f2008-12-23 16:06:15 -05006090 struct compound_hdr hdr;
6091 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006094 if (status)
6095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006097 if (status)
6098 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006100 if (status)
6101 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006103 if (status)
6104 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006105 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006107 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108}
6109
6110/*
6111 * Decode SETATTR response
6112 */
Chuck Leverbf269552010-12-14 14:59:29 +00006113static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6114 struct xdr_stream *xdr,
6115 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116{
Andy Adamson05d564f2008-12-23 16:06:15 -05006117 struct compound_hdr hdr;
6118 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006121 if (status)
6122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006124 if (status)
6125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006127 if (status)
6128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006130 if (status)
6131 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006132 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006134 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135}
6136
6137/*
6138 * Decode LOCK response
6139 */
Chuck Leverbf269552010-12-14 14:59:29 +00006140static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6141 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 struct compound_hdr hdr;
6144 int status;
6145
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 if (status)
6148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006150 if (status)
6151 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006152 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153 if (status)
6154 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156out:
6157 return status;
6158}
6159
6160/*
6161 * Decode LOCKT response
6162 */
Chuck Leverbf269552010-12-14 14:59:29 +00006163static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6164 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 struct compound_hdr hdr;
6167 int status;
6168
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006173 if (status)
6174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176 if (status)
6177 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179out:
6180 return status;
6181}
6182
6183/*
6184 * Decode LOCKU response
6185 */
Chuck Leverbf269552010-12-14 14:59:29 +00006186static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6187 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 struct compound_hdr hdr;
6190 int status;
6191
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 if (status)
6194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202out:
6203 return status;
6204}
6205
Chuck Leverbf269552010-12-14 14:59:29 +00006206static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6207 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006208{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006209 struct compound_hdr hdr;
6210 int status;
6211
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006213 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006215 return status;
6216}
6217
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218/*
6219 * Decode READLINK response
6220 */
Chuck Leverbf269552010-12-14 14:59:29 +00006221static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6222 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006223 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 struct compound_hdr hdr;
6226 int status;
6227
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 if (status)
6230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006232 if (status)
6233 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 if (status)
6236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238out:
6239 return status;
6240}
6241
6242/*
6243 * Decode READDIR response
6244 */
Chuck Leverbf269552010-12-14 14:59:29 +00006245static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6246 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248 struct compound_hdr hdr;
6249 int status;
6250
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 if (status)
6253 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006255 if (status)
6256 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 if (status)
6259 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261out:
6262 return status;
6263}
6264
6265/*
6266 * Decode Read response
6267 */
Chuck Leverbf269552010-12-14 14:59:29 +00006268static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6269 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 struct compound_hdr hdr;
6272 int status;
6273
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275 if (status)
6276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006278 if (status)
6279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 if (!status)
6285 status = res->count;
6286out:
6287 return status;
6288}
6289
6290/*
6291 * Decode WRITE response
6292 */
Chuck Leverbf269552010-12-14 14:59:29 +00006293static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6294 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 struct compound_hdr hdr;
6297 int status;
6298
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300 if (status)
6301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006309 if (status)
6310 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006311 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006312 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313 if (!status)
6314 status = res->count;
6315out:
6316 return status;
6317}
6318
6319/*
6320 * Decode COMMIT response
6321 */
Chuck Leverbf269552010-12-14 14:59:29 +00006322static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006323 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 struct compound_hdr hdr;
6326 int status;
6327
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 if (status)
6336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006338 if (status)
6339 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006340 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006341 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342out:
6343 return status;
6344}
6345
6346/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006347 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 */
Chuck Leverbf269552010-12-14 14:59:29 +00006349static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006350 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352 struct compound_hdr hdr;
6353 int status;
6354
Chuck Leverbf269552010-12-14 14:59:29 +00006355 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006358 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 return status;
6363}
6364
6365/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006366 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 */
Chuck Leverbf269552010-12-14 14:59:29 +00006368static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006369 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371 struct compound_hdr hdr;
6372 int status;
6373
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006377 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 return status;
6382}
6383
6384/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006385 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386 */
Chuck Leverbf269552010-12-14 14:59:29 +00006387static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006388 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390 struct compound_hdr hdr;
6391 int status;
6392
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006396 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 return status;
6401}
6402
6403/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006404 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 */
Chuck Leverbf269552010-12-14 14:59:29 +00006406static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6407 struct xdr_stream *xdr,
6408 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 struct compound_hdr hdr;
6411 int status;
6412
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006417 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_putfh(xdr);
6420 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423out:
6424 return status;
6425}
6426
6427/*
6428 * Decode RENEW response
6429 */
Chuck Leverbf269552010-12-14 14:59:29 +00006430static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6431 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433 struct compound_hdr hdr;
6434 int status;
6435
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 return status;
6440}
6441
6442/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006443 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 */
Chuck Leverbf269552010-12-14 14:59:29 +00006445static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6446 struct xdr_stream *xdr,
6447 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 struct compound_hdr hdr;
6450 int status;
6451
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 return status;
6456}
6457
6458/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006459 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 */
Chuck Leverbf269552010-12-14 14:59:29 +00006461static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6462 struct xdr_stream *xdr,
6463 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 struct compound_hdr hdr;
6466 int status;
6467
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 return status;
6476}
6477
6478/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006479 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 */
Chuck Leverbf269552010-12-14 14:59:29 +00006481static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6482 struct xdr_stream *xdr,
6483 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 struct compound_hdr hdr;
6486 int status;
6487
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006489 if (status)
6490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006492 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006495 if (status != 0)
6496 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006497 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006498 if (status != 0)
6499 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006500 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006501out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 return status;
6503}
6504
Trond Myklebust683b57b2006-06-09 09:34:22 -04006505/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006506 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006507 */
Chuck Leverbf269552010-12-14 14:59:29 +00006508static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6509 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006510 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006511{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006512 struct compound_hdr hdr;
6513 int status;
6514
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006516 if (status)
6517 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006519 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006520 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_putfh(xdr);
6522 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006523 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_lookup(xdr);
6525 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006527 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006528 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6529 NULL, res->fs_locations,
6530 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006531out:
6532 return status;
6533}
6534
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006535/*
6536 * Decode SECINFO response
6537 */
6538static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6539 struct xdr_stream *xdr,
6540 struct nfs4_secinfo_res *res)
6541{
6542 struct compound_hdr hdr;
6543 int status;
6544
6545 status = decode_compound_hdr(xdr, &hdr);
6546 if (status)
6547 goto out;
6548 status = decode_sequence(xdr, &res->seq_res, rqstp);
6549 if (status)
6550 goto out;
6551 status = decode_putfh(xdr);
6552 if (status)
6553 goto out;
6554 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006555out:
6556 return status;
6557}
6558
Benny Halevy99fe60d2009-04-01 09:22:29 -04006559#if defined(CONFIG_NFS_V4_1)
6560/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006561 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006562 */
Chuck Leverbf269552010-12-14 14:59:29 +00006563static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6564 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006565 void *res)
6566{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006567 struct compound_hdr hdr;
6568 int status;
6569
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006571 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006573 return status;
6574}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006575
6576/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006577 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006578 */
Chuck Leverbf269552010-12-14 14:59:29 +00006579static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6580 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006581 struct nfs41_create_session_res *res)
6582{
Andy Adamsonfc931582009-04-01 09:22:31 -04006583 struct compound_hdr hdr;
6584 int status;
6585
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006587 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006589 return status;
6590}
6591
6592/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006593 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006594 */
Chuck Leverbf269552010-12-14 14:59:29 +00006595static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6596 struct xdr_stream *xdr,
6597 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006598{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006599 struct compound_hdr hdr;
6600 int status;
6601
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006603 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006605 return status;
6606}
6607
6608/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006609 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006610 */
Chuck Leverbf269552010-12-14 14:59:29 +00006611static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6612 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006613 struct nfs4_sequence_res *res)
6614{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006615 struct compound_hdr hdr;
6616 int status;
6617
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006619 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006621 return status;
6622}
6623
6624/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006625 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006626 */
Chuck Leverbf269552010-12-14 14:59:29 +00006627static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6628 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006629 struct nfs4_get_lease_time_res *res)
6630{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006631 struct compound_hdr hdr;
6632 int status;
6633
Chuck Leverbf269552010-12-14 14:59:29 +00006634 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006635 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006637 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006638 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006639 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006640 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006641 return status;
6642}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006643
6644/*
6645 * Decode RECLAIM_COMPLETE response
6646 */
Chuck Leverbf269552010-12-14 14:59:29 +00006647static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6648 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006649 struct nfs41_reclaim_complete_res *res)
6650{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006651 struct compound_hdr hdr;
6652 int status;
6653
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006655 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006657 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006658 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006659 return status;
6660}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006661
6662/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006663 * Decode GETDEVICELIST response
6664 */
6665static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6666 struct xdr_stream *xdr,
6667 struct nfs4_getdevicelist_res *res)
6668{
6669 struct compound_hdr hdr;
6670 int status;
6671
6672 dprintk("encoding getdevicelist!\n");
6673
6674 status = decode_compound_hdr(xdr, &hdr);
6675 if (status != 0)
6676 goto out;
6677 status = decode_sequence(xdr, &res->seq_res, rqstp);
6678 if (status != 0)
6679 goto out;
6680 status = decode_putfh(xdr);
6681 if (status != 0)
6682 goto out;
6683 status = decode_getdevicelist(xdr, res->devlist);
6684out:
6685 return status;
6686}
6687
6688/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006689 * Decode GETDEVINFO response
6690 */
Chuck Leverbf269552010-12-14 14:59:29 +00006691static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6692 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006693 struct nfs4_getdeviceinfo_res *res)
6694{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006695 struct compound_hdr hdr;
6696 int status;
6697
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006699 if (status != 0)
6700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006702 if (status != 0)
6703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006705out:
6706 return status;
6707}
6708
6709/*
6710 * Decode LAYOUTGET response
6711 */
Chuck Leverbf269552010-12-14 14:59:29 +00006712static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6713 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006714 struct nfs4_layoutget_res *res)
6715{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006716 struct compound_hdr hdr;
6717 int status;
6718
Chuck Leverbf269552010-12-14 14:59:29 +00006719 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006720 if (status)
6721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006723 if (status)
6724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006726 if (status)
6727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006729out:
6730 return status;
6731}
Andy Adamson863a3c62011-03-23 13:27:54 +00006732
6733/*
Benny Halevycbe82602011-05-22 19:52:37 +03006734 * Decode LAYOUTRETURN response
6735 */
6736static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6737 struct xdr_stream *xdr,
6738 struct nfs4_layoutreturn_res *res)
6739{
6740 struct compound_hdr hdr;
6741 int status;
6742
6743 status = decode_compound_hdr(xdr, &hdr);
6744 if (status)
6745 goto out;
6746 status = decode_sequence(xdr, &res->seq_res, rqstp);
6747 if (status)
6748 goto out;
6749 status = decode_putfh(xdr);
6750 if (status)
6751 goto out;
6752 status = decode_layoutreturn(xdr, res);
6753out:
6754 return status;
6755}
6756
6757/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006758 * Decode LAYOUTCOMMIT response
6759 */
6760static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6761 struct xdr_stream *xdr,
6762 struct nfs4_layoutcommit_res *res)
6763{
6764 struct compound_hdr hdr;
6765 int status;
6766
6767 status = decode_compound_hdr(xdr, &hdr);
6768 if (status)
6769 goto out;
6770 status = decode_sequence(xdr, &res->seq_res, rqstp);
6771 if (status)
6772 goto out;
6773 status = decode_putfh(xdr);
6774 if (status)
6775 goto out;
6776 status = decode_layoutcommit(xdr, rqstp, res);
6777 if (status)
6778 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006779 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006780out:
6781 return status;
6782}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006783
6784/*
6785 * Decode SECINFO_NO_NAME response
6786 */
6787static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6788 struct xdr_stream *xdr,
6789 struct nfs4_secinfo_res *res)
6790{
6791 struct compound_hdr hdr;
6792 int status;
6793
6794 status = decode_compound_hdr(xdr, &hdr);
6795 if (status)
6796 goto out;
6797 status = decode_sequence(xdr, &res->seq_res, rqstp);
6798 if (status)
6799 goto out;
6800 status = decode_putrootfh(xdr);
6801 if (status)
6802 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006803 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006804out:
6805 return status;
6806}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006807
6808/*
6809 * Decode TEST_STATEID response
6810 */
6811static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6812 struct xdr_stream *xdr,
6813 struct nfs41_test_stateid_res *res)
6814{
6815 struct compound_hdr hdr;
6816 int status;
6817
6818 status = decode_compound_hdr(xdr, &hdr);
6819 if (status)
6820 goto out;
6821 status = decode_sequence(xdr, &res->seq_res, rqstp);
6822 if (status)
6823 goto out;
6824 status = decode_test_stateid(xdr, res);
6825out:
6826 return status;
6827}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006828
6829/*
6830 * Decode FREE_STATEID response
6831 */
6832static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6833 struct xdr_stream *xdr,
6834 struct nfs41_free_stateid_res *res)
6835{
6836 struct compound_hdr hdr;
6837 int status;
6838
6839 status = decode_compound_hdr(xdr, &hdr);
6840 if (status)
6841 goto out;
6842 status = decode_sequence(xdr, &res->seq_res, rqstp);
6843 if (status)
6844 goto out;
6845 status = decode_free_stateid(xdr, res);
6846out:
6847 return status;
6848}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006849#endif /* CONFIG_NFS_V4_1 */
6850
Chuck Lever573c4e12010-12-14 14:58:11 +00006851/**
6852 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6853 * the local page cache.
6854 * @xdr: XDR stream where entry resides
6855 * @entry: buffer to fill in with entry data
6856 * @plus: boolean indicating whether this should be a readdirplus entry
6857 *
6858 * Returns zero if successful, otherwise a negative errno value is
6859 * returned.
6860 *
6861 * This function is not invoked during READDIR reply decoding, but
6862 * rather whenever an application invokes the getdents(2) system call
6863 * on a directory already in our cache.
6864 */
6865int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6866 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867{
Fred Isamandae100c2011-07-30 20:52:37 -04006868 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006870 __be32 *p = xdr_inline_decode(xdr, 4);
6871 if (unlikely(!p))
6872 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006873 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006874 p = xdr_inline_decode(xdr, 4);
6875 if (unlikely(!p))
6876 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006877 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006878 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006880 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881 }
6882
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006883 p = xdr_inline_decode(xdr, 12);
6884 if (unlikely(!p))
6885 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 entry->prev_cookie = entry->cookie;
6887 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006888 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006889
Trond Myklebust9af8c222010-10-24 11:52:55 -04006890 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006891 if (unlikely(!p))
6892 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894
6895 /*
6896 * In case the server doesn't return an inode number,
6897 * we fake one here. (We don't use inode number 0,
6898 * since glibc seems to choke on it...)
6899 */
6900 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006901 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902
Trond Myklebust9af8c222010-10-24 11:52:55 -04006903 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006904 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006905
6906 if (decode_attr_length(xdr, &len, &p) < 0)
6907 goto out_overflow;
6908
Chuck Lever573c4e12010-12-14 14:58:11 +00006909 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006910 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006911 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006912 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6913 entry->ino = entry->fattr->mounted_on_fileid;
6914 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006915 entry->ino = entry->fattr->fileid;
6916
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006917 entry->d_type = DT_UNKNOWN;
6918 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6919 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6920
Chuck Lever573c4e12010-12-14 14:58:11 +00006921 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006922
6923out_overflow:
6924 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006925 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006926}
6927
6928/*
6929 * We need to translate between nfs status return values and
6930 * the local errno values which may not be the same.
6931 */
6932static struct {
6933 int stat;
6934 int errno;
6935} nfs_errtbl[] = {
6936 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006937 { NFS4ERR_PERM, -EPERM },
6938 { NFS4ERR_NOENT, -ENOENT },
6939 { NFS4ERR_IO, -errno_NFSERR_IO},
6940 { NFS4ERR_NXIO, -ENXIO },
6941 { NFS4ERR_ACCESS, -EACCES },
6942 { NFS4ERR_EXIST, -EEXIST },
6943 { NFS4ERR_XDEV, -EXDEV },
6944 { NFS4ERR_NOTDIR, -ENOTDIR },
6945 { NFS4ERR_ISDIR, -EISDIR },
6946 { NFS4ERR_INVAL, -EINVAL },
6947 { NFS4ERR_FBIG, -EFBIG },
6948 { NFS4ERR_NOSPC, -ENOSPC },
6949 { NFS4ERR_ROFS, -EROFS },
6950 { NFS4ERR_MLINK, -EMLINK },
6951 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6952 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6953 { NFS4ERR_DQUOT, -EDQUOT },
6954 { NFS4ERR_STALE, -ESTALE },
6955 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006956 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6957 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6958 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006959 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006960 { NFS4ERR_BADTYPE, -EBADTYPE },
6961 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006962 { NFS4ERR_SYMLINK, -ELOOP },
6963 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6964 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006965 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966};
6967
6968/*
6969 * Convert an NFS error code to a local one.
6970 * This one is used jointly by NFSv2 and NFSv3.
6971 */
6972static int
David Howells0a8ea432006-08-22 20:06:08 -04006973nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006974{
6975 int i;
6976 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6977 if (nfs_errtbl[i].stat == stat)
6978 return nfs_errtbl[i].errno;
6979 }
6980 if (stat <= 10000 || stat > 10100) {
6981 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006982 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006983 }
6984 /* If we cannot translate the error, the recovery routines should
6985 * handle it.
6986 * Note: remaining NFSv4 error codes have values > 10000, so should
6987 * not conflict with native Linux error codes.
6988 */
Benny Halevy856dff32008-03-31 17:39:06 +03006989 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990}
6991
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992#define PROC(proc, argtype, restype) \
6993[NFSPROC4_CLNT_##proc] = { \
6994 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006995 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006996 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006997 .p_arglen = NFS4_##argtype##_sz, \
6998 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006999 .p_statidx = NFSPROC4_CLNT_##proc, \
7000 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007001}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002
7003struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007004 PROC(READ, enc_read, dec_read),
7005 PROC(WRITE, enc_write, dec_write),
7006 PROC(COMMIT, enc_commit, dec_commit),
7007 PROC(OPEN, enc_open, dec_open),
7008 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7009 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7010 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7011 PROC(CLOSE, enc_close, dec_close),
7012 PROC(SETATTR, enc_setattr, dec_setattr),
7013 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7014 PROC(RENEW, enc_renew, dec_renew),
7015 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7016 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7017 PROC(LOCK, enc_lock, dec_lock),
7018 PROC(LOCKT, enc_lockt, dec_lockt),
7019 PROC(LOCKU, enc_locku, dec_locku),
7020 PROC(ACCESS, enc_access, dec_access),
7021 PROC(GETATTR, enc_getattr, dec_getattr),
7022 PROC(LOOKUP, enc_lookup, dec_lookup),
7023 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7024 PROC(REMOVE, enc_remove, dec_remove),
7025 PROC(RENAME, enc_rename, dec_rename),
7026 PROC(LINK, enc_link, dec_link),
7027 PROC(SYMLINK, enc_symlink, dec_symlink),
7028 PROC(CREATE, enc_create, dec_create),
7029 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7030 PROC(STATFS, enc_statfs, dec_statfs),
7031 PROC(READLINK, enc_readlink, dec_readlink),
7032 PROC(READDIR, enc_readdir, dec_readdir),
7033 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7034 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7035 PROC(GETACL, enc_getacl, dec_getacl),
7036 PROC(SETACL, enc_setacl, dec_setacl),
7037 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7038 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007039 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007040#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007041 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7042 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7043 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7044 PROC(SEQUENCE, enc_sequence, dec_sequence),
7045 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7046 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7047 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7048 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007049 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007050 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007051 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007052 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007053 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007054 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007055#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056};
7057
Trond Myklebusta613fa12012-01-20 13:53:56 -05007058const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007060 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007061 .procs = nfs4_procedures
7062};
7063
7064/*
7065 * Local variables:
7066 * c-basic-offset: 8
7067 * End:
7068 */