blob: 49483f19c5d38ee69f0f06247b501bb672ebee84 [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 Myklebust778d2812012-04-27 13:48:19 -0400592 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400596 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
600 encode_savefh_maxsz + \
601 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400602 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400608 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 encode_putfh_maxsz + \
612 encode_savefh_maxsz + \
613 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400614 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400615 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400616 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 decode_putfh_maxsz + \
620 decode_savefh_maxsz + \
621 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400622 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400623 decode_restorefh_maxsz + \
624 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 encode_putfh_maxsz + \
628 encode_symlink_maxsz + \
629 encode_getattr_maxsz + \
630 encode_getfh_maxsz)
631#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 decode_putfh_maxsz + \
634 decode_symlink_maxsz + \
635 decode_getattr_maxsz + \
636 decode_getfh_maxsz)
637#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putfh_maxsz + \
640 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400641 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400642 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 decode_putfh_maxsz + \
646 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400647 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400648 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 encode_putfh_maxsz + \
652 encode_getattr_maxsz)
653#define NFS4_dec_pathconf_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_getattr_maxsz)
657#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400660 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400664 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800667 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 encode_getattr_maxsz)
669#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800671 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 decode_getattr_maxsz)
673#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100676 encode_delegreturn_maxsz + \
677 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100680 decode_delegreturn_maxsz + \
681 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000682#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000684 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400685 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000686#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000688 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400689 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000690#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400691 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000692 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400693 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000694#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400695 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000696 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400697 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400698#define NFS4_enc_fs_locations_sz \
699 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400701 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400702 encode_lookup_maxsz + \
703 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400704#define NFS4_dec_fs_locations_sz \
705 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400707 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400708 decode_lookup_maxsz + \
709 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000710#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_putfh_maxsz + \
713 encode_secinfo_maxsz)
714#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
715 decode_sequence_maxsz + \
716 decode_putfh_maxsz + \
717 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400718#if defined(CONFIG_NFS_V4_1)
719#define NFS4_enc_exchange_id_sz \
720 (compound_encode_hdr_maxsz + \
721 encode_exchange_id_maxsz)
722#define NFS4_dec_exchange_id_sz \
723 (compound_decode_hdr_maxsz + \
724 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400725#define NFS4_enc_create_session_sz \
726 (compound_encode_hdr_maxsz + \
727 encode_create_session_maxsz)
728#define NFS4_dec_create_session_sz \
729 (compound_decode_hdr_maxsz + \
730 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400731#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
732 encode_destroy_session_maxsz)
733#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
734 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400735#define NFS4_enc_sequence_sz \
736 (compound_decode_hdr_maxsz + \
737 encode_sequence_maxsz)
738#define NFS4_dec_sequence_sz \
739 (compound_decode_hdr_maxsz + \
740 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400741#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
742 encode_sequence_maxsz + \
743 encode_putrootfh_maxsz + \
744 encode_fsinfo_maxsz)
745#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
746 decode_sequence_maxsz + \
747 decode_putrootfh_maxsz + \
748 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500749#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_reclaim_complete_maxsz)
752#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400755#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getdevicelist_maxsz)
759#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400763#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz +\
765 encode_getdeviceinfo_maxsz)
766#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
767 decode_sequence_maxsz + \
768 decode_getdeviceinfo_maxsz)
769#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putfh_maxsz + \
772 encode_layoutget_maxsz)
773#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putfh_maxsz + \
776 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000777#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz +\
779 encode_putfh_maxsz + \
780 encode_layoutcommit_maxsz + \
781 encode_getattr_maxsz)
782#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
783 decode_sequence_maxsz + \
784 decode_putfh_maxsz + \
785 decode_layoutcommit_maxsz + \
786 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300787#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_layoutreturn_maxsz)
791#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400795#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz + \
797 encode_putrootfh_maxsz +\
798 encode_secinfo_no_name_maxsz)
799#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
800 decode_sequence_maxsz + \
801 decode_putrootfh_maxsz + \
802 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400803#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_test_stateid_maxsz)
806#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400809#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_free_stateid_maxsz)
812#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500815
816const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
817 compound_encode_hdr_maxsz +
818 encode_sequence_maxsz +
819 encode_putfh_maxsz +
820 encode_getattr_maxsz) *
821 XDR_UNIT);
822
823const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
824 compound_decode_hdr_maxsz +
825 decode_sequence_maxsz +
826 decode_putfh_maxsz) *
827 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400828#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500830static unsigned short send_implementation_id = 1;
831
832module_param(send_implementation_id, ushort, 0644);
833MODULE_PARM_DESC(send_implementation_id,
834 "Send implementation ID with NFSv4.1 exchange_id");
835
Trond Myklebustbca79472009-03-11 14:10:26 -0400836static const umode_t nfs_type2fmt[] = {
837 [NF4BAD] = 0,
838 [NF4REG] = S_IFREG,
839 [NF4DIR] = S_IFDIR,
840 [NF4BLK] = S_IFBLK,
841 [NF4CHR] = S_IFCHR,
842 [NF4LNK] = S_IFLNK,
843 [NF4SOCK] = S_IFSOCK,
844 [NF4FIFO] = S_IFIFO,
845 [NF4ATTRDIR] = 0,
846 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847};
848
849struct compound_hdr {
850 int32_t status;
851 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500852 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 uint32_t taglen;
854 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400855 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400856 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857};
858
Benny Halevy13c65ce2009-08-14 17:19:25 +0300859static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
860{
861 __be32 *p = xdr_reserve_space(xdr, nbytes);
862 BUG_ON(!p);
863 return p;
864}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Trond Myklebustcb17e552012-03-04 18:13:56 -0500866static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
867{
868 __be32 *p;
869
870 p = xdr_reserve_space(xdr, len);
871 xdr_encode_opaque_fixed(p, buf, len);
872}
873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
875{
Al Viro8687b632006-10-19 23:28:48 -0700876 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500878 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 xdr_encode_opaque(p, str, len);
880}
881
Trond Myklebust4ade9822012-03-04 18:13:57 -0500882static void encode_uint32(struct xdr_stream *xdr, u32 n)
883{
884 __be32 *p;
885
886 p = reserve_space(xdr, 4);
887 *p = cpu_to_be32(n);
888}
889
Trond Myklebustff2eb682012-03-05 11:40:12 -0500890static void encode_uint64(struct xdr_stream *xdr, u64 n)
891{
892 __be32 *p;
893
894 p = reserve_space(xdr, 8);
895 xdr_encode_hyper(p, n);
896}
897
Trond Myklebust4ade9822012-03-04 18:13:57 -0500898static void encode_nfs4_seqid(struct xdr_stream *xdr,
899 const struct nfs_seqid *seqid)
900{
901 encode_uint32(xdr, seqid->sequence->counter);
902}
903
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400904static void encode_compound_hdr(struct xdr_stream *xdr,
905 struct rpc_rqst *req,
906 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Al Viro8687b632006-10-19 23:28:48 -0700908 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400909 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400910
911 /* initialize running count of expected bytes in reply.
912 * NOTE: the replied tag SHOULD be the same is the one sent,
913 * but this is not required as a MUST for the server to do so. */
914 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500917 encode_string(xdr, hdr->taglen, hdr->tag);
918 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500920 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300921 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500922}
923
Trond Myklebustab19b482012-03-04 18:13:57 -0500924static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
925 uint32_t replen,
926 struct compound_hdr *hdr)
927{
928 encode_uint32(xdr, op);
929 hdr->nops++;
930 hdr->replen += replen;
931}
932
Andy Adamsond0179312008-12-23 16:06:17 -0500933static void encode_nops(struct compound_hdr *hdr)
934{
Andy Adamsonfc931582009-04-01 09:22:31 -0400935 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500936 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500939static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
940{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500941 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500942}
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
945{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500946 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500949static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
951 char owner_name[IDMAP_NAMESZ];
952 char owner_group[IDMAP_NAMESZ];
953 int owner_namelen = 0;
954 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700955 __be32 *p;
956 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 int len;
958 uint32_t bmval0 = 0;
959 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 /*
962 * We reserve enough space to write the entire attribute buffer at once.
963 * In the worst-case, this would be
964 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
965 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000966 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 */
968 len = 16;
969
970 /* Sigh */
971 if (iap->ia_valid & ATTR_SIZE)
972 len += 8;
973 if (iap->ia_valid & ATTR_MODE)
974 len += 4;
975 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800976 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400978 dprintk("nfs: couldn't resolve uid %d to string\n",
979 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 /* XXX */
981 strcpy(owner_name, "nobody");
982 owner_namelen = sizeof("nobody") - 1;
983 /* goto out; */
984 }
985 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
986 }
987 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800988 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400990 dprintk("nfs: couldn't resolve gid %d to string\n",
991 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 strcpy(owner_group, "nobody");
993 owner_grouplen = sizeof("nobody") - 1;
994 /* goto out; */
995 }
996 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
997 }
998 if (iap->ia_valid & ATTR_ATIME_SET)
999 len += 16;
1000 else if (iap->ia_valid & ATTR_ATIME)
1001 len += 4;
1002 if (iap->ia_valid & ATTR_MTIME_SET)
1003 len += 16;
1004 else if (iap->ia_valid & ATTR_MTIME)
1005 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001006 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 /*
1009 * We write the bitmap length now, but leave the bitmap and the attribute
1010 * buffer length to be backfilled at the end of this routine.
1011 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001012 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 q = p;
1014 p += 3;
1015
1016 if (iap->ia_valid & ATTR_SIZE) {
1017 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001018 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020 if (iap->ia_valid & ATTR_MODE) {
1021 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001022 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 if (iap->ia_valid & ATTR_UID) {
1025 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001026 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028 if (iap->ia_valid & ATTR_GID) {
1029 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001030 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 }
1032 if (iap->ia_valid & ATTR_ATIME_SET) {
1033 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001034 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1035 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001036 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1037 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039 else if (iap->ia_valid & ATTR_ATIME) {
1040 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001041 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043 if (iap->ia_valid & ATTR_MTIME_SET) {
1044 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001045 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1046 *p++ = cpu_to_be32(0);
1047 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1048 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 else if (iap->ia_valid & ATTR_MTIME) {
1051 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001052 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 /*
1056 * Now we backfill the bitmap and the attribute buffer length.
1057 */
1058 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001059 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 len, ((char *)p - (char *)q) + 4);
1061 BUG();
1062 }
1063 len = (char *)p - (char *)q - 12;
1064 *q++ = htonl(bmval0);
1065 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001066 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069}
1070
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001071static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001073 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1074 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001077static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Trond Myklebustab19b482012-03-04 18:13:57 -05001079 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001080 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001081 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
Fred Isaman0b7c0152012-04-20 14:47:39 -04001084static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Al Viro8687b632006-10-19 23:28:48 -07001086 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001087
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001088 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1089 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001090 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001091 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092}
1093
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001094static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, 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_CREATE, decode_create_maxsz, hdr);
1099 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 switch (create->ftype) {
1102 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001103 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001104 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001105 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 break;
1107
1108 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001109 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001110 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001111 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 break;
1113
1114 default:
1115 break;
1116 }
1117
Benny Halevy811652b2009-08-14 17:19:34 +03001118 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001126 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1127 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001128 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001129 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001132static 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 -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, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001138 *p++ = cpu_to_be32(2);
1139 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001140 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Fred Isamandae100c2011-07-30 20:52:37 -04001143static void
1144encode_getattr_three(struct xdr_stream *xdr,
1145 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1146 struct compound_hdr *hdr)
1147{
1148 __be32 *p;
1149
Trond Myklebustab19b482012-03-04 18:13:57 -05001150 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001151 if (bm2) {
1152 p = reserve_space(xdr, 16);
1153 *p++ = cpu_to_be32(3);
1154 *p++ = cpu_to_be32(bm0);
1155 *p++ = cpu_to_be32(bm1);
1156 *p = cpu_to_be32(bm2);
1157 } else if (bm1) {
1158 p = reserve_space(xdr, 12);
1159 *p++ = cpu_to_be32(2);
1160 *p++ = cpu_to_be32(bm0);
1161 *p = cpu_to_be32(bm1);
1162 } else {
1163 p = reserve_space(xdr, 8);
1164 *p++ = cpu_to_be32(1);
1165 *p = cpu_to_be32(bm0);
1166 }
Fred Isamandae100c2011-07-30 20:52:37 -04001167}
1168
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001171 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1172 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001175static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Fred Isamandae100c2011-07-30 20:52:37 -04001177 encode_getattr_three(xdr,
1178 bitmask[0] & nfs4_fsinfo_bitmap[0],
1179 bitmask[1] & nfs4_fsinfo_bitmap[1],
1180 bitmask[2] & nfs4_fsinfo_bitmap[2],
1181 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001184static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001185{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001186 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1187 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Trond Myklebustab19b482012-03-04 18:13:57 -05001192 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Trond Myklebustab19b482012-03-04 18:13:57 -05001197 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001198 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001201static inline int nfs4_lock_type(struct file_lock *fl, int block)
1202{
1203 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1204 return block ? NFS4_READW_LT : NFS4_READ_LT;
1205 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1206}
1207
1208static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1209{
1210 if (fl->fl_end == OFFSET_MAX)
1211 return ~(uint64_t)0;
1212 return fl->fl_end - fl->fl_start + 1;
1213}
1214
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001215static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1216{
1217 __be32 *p;
1218
Trond Myklebustd035c362010-12-21 10:45:27 -05001219 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001220 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001221 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001222 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001223 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001224 xdr_encode_hyper(p, lowner->id);
1225}
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227/*
1228 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1229 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1230 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001231static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
Al Viro8687b632006-10-19 23:28:48 -07001233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001235 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1236 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001239 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001241 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001242 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001243 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001244 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001245 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001246 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 }
1248 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001249 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001250 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001254static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Al Viro8687b632006-10-19 23:28:48 -07001256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001258 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1259 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001260 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001261 p = xdr_encode_hyper(p, args->fl->fl_start);
1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001263 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001266static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Al Viro8687b632006-10-19 23:28:48 -07001268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001270 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1271 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001272 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001273 encode_nfs4_stateid(xdr, args->stateid);
1274 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001275 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001276 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001279static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1280{
Trond Myklebustab19b482012-03-04 18:13:57 -05001281 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001282 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001283}
1284
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Trond Myklebustab19b482012-03-04 18:13:57 -05001287 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001288 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001291static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Benny Halevy13c65ce2009-08-14 17:19:25 +03001295 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001296 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001297 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001298 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001299 break;
1300 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001301 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001302 break;
1303 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001305 break;
1306 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001307 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 }
Benny Halevy34558512009-08-14 17:19:30 +03001309 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
1312static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1313{
Al Viro8687b632006-10-19 23:28:48 -07001314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /*
1316 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1317 * owner 4 = 32
1318 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001319 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001320 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001321 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001322 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001323 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001324 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001325 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001326 *p++ = cpu_to_be32(arg->id.uniquifier);
1327 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328}
1329
1330static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1331{
Al Viro8687b632006-10-19 23:28:48 -07001332 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001333 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Benny Halevy13c65ce2009-08-14 17:19:25 +03001335 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001337 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 encode_attrs(xdr, arg->u.attrs, arg->server);
1340 break;
1341 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001342 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001343 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001344 if (nfs4_has_persistent_session(clp)) {
1345 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1346 encode_attrs(xdr, arg->u.attrs, arg->server);
1347 } else {
1348 struct iattr dummy;
1349
1350 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1351 encode_nfs4_verifier(xdr, &arg->u.verifier);
1352 dummy.ia_valid = 0;
1353 encode_attrs(xdr, &dummy, arg->server);
1354 }
1355 } else {
1356 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1357 encode_nfs4_verifier(xdr, &arg->u.verifier);
1358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360}
1361
1362static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1363{
Al Viro8687b632006-10-19 23:28:48 -07001364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Benny Halevy13c65ce2009-08-14 17:19:25 +03001366 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001370 break;
1371 default:
1372 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001373 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
1376}
1377
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001378static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Al Viro8687b632006-10-19 23:28:48 -07001380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Benny Halevy13c65ce2009-08-14 17:19:25 +03001382 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001385 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001386 break;
1387 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001388 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001389 break;
1390 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001391 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001392 break;
1393 default:
1394 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
1396}
1397
1398static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Benny Halevy13c65ce2009-08-14 17:19:25 +03001402 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001403 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 encode_string(xdr, name->len, name->name);
1405}
1406
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001407static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001412 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 encode_delegation_type(xdr, type);
1414}
1415
1416static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1417{
Al Viro8687b632006-10-19 23:28:48 -07001418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001420 p = reserve_space(xdr, 4);
1421 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1422 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 encode_string(xdr, name->len, name->name);
1424}
1425
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001426static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Trond Myklebustab19b482012-03-04 18:13:57 -05001428 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 encode_openhdr(xdr, arg);
1430 encode_opentype(xdr, arg);
1431 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 case NFS4_OPEN_CLAIM_NULL:
1433 encode_claim_null(xdr, arg->name);
1434 break;
1435 case NFS4_OPEN_CLAIM_PREVIOUS:
1436 encode_claim_previous(xdr, arg->u.delegation_type);
1437 break;
1438 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1439 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1440 break;
1441 default:
1442 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001446static 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 -07001447{
Trond Myklebustab19b482012-03-04 18:13:57 -05001448 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001449 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001450 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451}
1452
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001453static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Trond Myklebustab19b482012-03-04 18:13:57 -05001455 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001456 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001457 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001458 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459}
1460
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001461static void
Andy Adamsond0179312008-12-23 16:06:17 -05001462encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Trond Myklebustab19b482012-03-04 18:13:57 -05001464 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001465 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001468static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Trond Myklebustab19b482012-03-04 18:13:57 -05001470 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Trond Myklebust4fc87962012-03-08 17:42:01 -05001473static void encode_open_stateid(struct xdr_stream *xdr,
1474 const struct nfs_open_context *ctx,
1475 const struct nfs_lock_context *l_ctx,
1476 fmode_t fmode,
1477 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001482 nfs4_select_rw_stateid(&stateid, ctx->state,
1483 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001484 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001485 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001486 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001488 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001491static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Al Viro8687b632006-10-19 23:28:48 -07001493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Trond Myklebustab19b482012-03-04 18:13:57 -05001495 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001496 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001497 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Benny Halevy13c65ce2009-08-14 17:19:25 +03001499 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001500 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001501 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001504static 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 -07001505{
Trond Myklebust28331a42011-04-27 13:47:52 -04001506 uint32_t attrs[2] = {
1507 FATTR4_WORD0_RDATTR_ERROR,
1508 FATTR4_WORD1_MOUNTED_ON_FILEID,
1509 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001510 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001511 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001513 if (readdir->plus) {
1514 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001515 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001516 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1517 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1518 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1519 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001520 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001521 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001522 /* Use mounted_on_fileid only if the server supports it */
1523 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1524 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001525
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001526 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001527 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001528 encode_nfs4_verifier(xdr, &readdir->verifier);
1529 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001530 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001531 *p++ = cpu_to_be32(readdir->count);
1532 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001533
Benny Halevye75bc1c2009-08-14 17:18:54 +03001534 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001535 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001536 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001537 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1538 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001539 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001540 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001541 attrs[0] & readdir->bitmask[0],
1542 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static 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 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001553 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static 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 -07001557{
Trond Myklebustab19b482012-03-04 18:13:57 -05001558 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001559 encode_string(xdr, oldname->len, oldname->name);
1560 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Chuck Leverbb4dae52012-03-01 17:01:48 -05001563static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1564 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001566 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001567 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568}
1569
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001570static void
Andy Adamsond0179312008-12-23 16:06:17 -05001571encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001572{
Trond Myklebustab19b482012-03-04 18:13:57 -05001573 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001574}
1575
Chuck Lever9f06c712010-12-14 14:59:18 +00001576static void
Andy Adamsond0179312008-12-23 16:06:17 -05001577encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001578{
Al Viro8687b632006-10-19 23:28:48 -07001579 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001580
Trond Myklebustab19b482012-03-04 18:13:57 -05001581 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001582 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001583 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001584 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001585 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001586 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001587 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001588 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001589 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001590}
1591
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001592static void
Andy Adamsond0179312008-12-23 16:06:17 -05001593encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Trond Myklebustab19b482012-03-04 18:13:57 -05001595 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001598static 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 -07001599{
Trond Myklebustab19b482012-03-04 18:13:57 -05001600 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001601 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001605static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Al Viro8687b632006-10-19 23:28:48 -07001607 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Trond Myklebust70019512012-03-04 20:49:32 -05001609 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001610 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001613 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001614 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1616 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001618 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001621static 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 -07001622{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001623 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1624 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001625 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001626 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630{
Al Viro8687b632006-10-19 23:28:48 -07001631 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
Trond Myklebustab19b482012-03-04 18:13:57 -05001633 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001634 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001635 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Benny Halevy13c65ce2009-08-14 17:19:25 +03001637 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001638 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001639 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001640 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
1642 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Trond Myklebustab19b482012-03-04 18:13:57 -05001647 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001648 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001650
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001651static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1652{
Trond Myklebustab19b482012-03-04 18:13:57 -05001653 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001654 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001655}
1656
Benny Halevy99fe60d2009-04-01 09:22:29 -04001657#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001658/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001659static void encode_exchange_id(struct xdr_stream *xdr,
1660 struct nfs41_exchange_id_args *args,
1661 struct compound_hdr *hdr)
1662{
1663 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001664 char impl_name[NFS4_OPAQUE_LIMIT];
1665 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001666
Trond Myklebust70019512012-03-04 20:49:32 -05001667 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001668 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001669
1670 encode_string(xdr, args->id_len, args->id);
1671
Benny Halevy13c65ce2009-08-14 17:19:25 +03001672 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001673 *p++ = cpu_to_be32(args->flags);
1674 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001675
1676 if (send_implementation_id &&
1677 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1678 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1679 <= NFS4_OPAQUE_LIMIT + 1)
1680 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1681 utsname()->sysname, utsname()->release,
1682 utsname()->version, utsname()->machine);
1683
1684 if (len > 0) {
1685 *p = cpu_to_be32(1); /* implementation id array length=1 */
1686
1687 encode_string(xdr,
1688 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1689 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1690 encode_string(xdr, len, impl_name);
1691 /* just send zeros for nii_date - the date is in nii_name */
1692 p = reserve_space(xdr, 12);
1693 p = xdr_encode_hyper(p, 0);
1694 *p = cpu_to_be32(0);
1695 } else
1696 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001697}
Andy Adamsonfc931582009-04-01 09:22:31 -04001698
1699static void encode_create_session(struct xdr_stream *xdr,
1700 struct nfs41_create_session_args *args,
1701 struct compound_hdr *hdr)
1702{
1703 __be32 *p;
1704 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1705 uint32_t len;
1706 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001707 u32 max_resp_sz_cached;
1708
1709 /*
1710 * Assumes OPEN is the biggest non-idempotent compound.
1711 * 2 is the verifier.
1712 */
1713 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1714 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001715
Andy Adamsonfc931582009-04-01 09:22:31 -04001716 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1717 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001718
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001719 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1720 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001721 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001722 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1723 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001724
Andy Adamsonfc931582009-04-01 09:22:31 -04001725 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001726 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001727 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1728 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001729 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001730 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1731 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1732 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001733
1734 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001735 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1737 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1738 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1739 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1740 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1741 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001742
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001744 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001745 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001746
1747 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001749 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001750 *p++ = cpu_to_be32(0); /* UID */
1751 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001752 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001753}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001754
1755static void encode_destroy_session(struct xdr_stream *xdr,
1756 struct nfs4_session *session,
1757 struct compound_hdr *hdr)
1758{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001759 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1760 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001761}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001762
1763static void encode_reclaim_complete(struct xdr_stream *xdr,
1764 struct nfs41_reclaim_complete_args *args,
1765 struct compound_hdr *hdr)
1766{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001767 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1768 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001769}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001770#endif /* CONFIG_NFS_V4_1 */
1771
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001772static void encode_sequence(struct xdr_stream *xdr,
1773 const struct nfs4_sequence_args *args,
1774 struct compound_hdr *hdr)
1775{
1776#if defined(CONFIG_NFS_V4_1)
1777 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001778 struct nfs4_slot_table *tp;
1779 struct nfs4_slot *slot;
1780 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001781
1782 if (!session)
1783 return;
1784
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001785 tp = &session->fc_slot_table;
1786
1787 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1788 slot = tp->slots + args->sa_slotid;
1789
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001790 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001791
1792 /*
1793 * Sessionid + seqid + slotid + max slotid + cache_this
1794 */
1795 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1796 "max_slotid=%d cache_this=%d\n",
1797 __func__,
1798 ((u32 *)session->sess_id.data)[0],
1799 ((u32 *)session->sess_id.data)[1],
1800 ((u32 *)session->sess_id.data)[2],
1801 ((u32 *)session->sess_id.data)[3],
1802 slot->seq_nr, args->sa_slotid,
1803 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001804 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001805 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001806 *p++ = cpu_to_be32(slot->seq_nr);
1807 *p++ = cpu_to_be32(args->sa_slotid);
1808 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001809 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001810#endif /* CONFIG_NFS_V4_1 */
1811}
1812
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001813#ifdef CONFIG_NFS_V4_1
1814static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001815encode_getdevicelist(struct xdr_stream *xdr,
1816 const struct nfs4_getdevicelist_args *args,
1817 struct compound_hdr *hdr)
1818{
1819 __be32 *p;
1820 nfs4_verifier dummy = {
1821 .data = "dummmmmy",
1822 };
1823
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001824 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1825 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001826 *p++ = cpu_to_be32(args->layoutclass);
1827 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1828 xdr_encode_hyper(p, 0ULL); /* cookie */
1829 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001830}
1831
1832static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001833encode_getdeviceinfo(struct xdr_stream *xdr,
1834 const struct nfs4_getdeviceinfo_args *args,
1835 struct compound_hdr *hdr)
1836{
1837 __be32 *p;
1838
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001839 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1840 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001841 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1842 NFS4_DEVICEID4_SIZE);
1843 *p++ = cpu_to_be32(args->pdev->layout_type);
1844 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1845 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001846}
1847
1848static void
1849encode_layoutget(struct xdr_stream *xdr,
1850 const struct nfs4_layoutget_args *args,
1851 struct compound_hdr *hdr)
1852{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001853 __be32 *p;
1854
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001855 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1856 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001857 *p++ = cpu_to_be32(0); /* Signal layout available */
1858 *p++ = cpu_to_be32(args->type);
1859 *p++ = cpu_to_be32(args->range.iomode);
1860 p = xdr_encode_hyper(p, args->range.offset);
1861 p = xdr_encode_hyper(p, args->range.length);
1862 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001863 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001864 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001865
1866 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1867 __func__,
1868 args->type,
1869 args->range.iomode,
1870 (unsigned long)args->range.offset,
1871 (unsigned long)args->range.length,
1872 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001873}
Andy Adamson863a3c62011-03-23 13:27:54 +00001874
1875static int
1876encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001877 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001878 const struct nfs4_layoutcommit_args *args,
1879 struct compound_hdr *hdr)
1880{
1881 __be32 *p;
1882
1883 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1884 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1885
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001886 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1887 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001888 /* Only whole file layouts */
1889 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001890 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001891 *p = cpu_to_be32(0); /* reclaim */
1892 encode_nfs4_stateid(xdr, &args->stateid);
1893 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001894 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1895 p = xdr_encode_hyper(p, args->lastbytewritten);
1896 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1897 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001898
1899 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1900 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1901 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001902 else
1903 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001904
Andy Adamson863a3c62011-03-23 13:27:54 +00001905 return 0;
1906}
Benny Halevycbe82602011-05-22 19:52:37 +03001907
1908static void
1909encode_layoutreturn(struct xdr_stream *xdr,
1910 const struct nfs4_layoutreturn_args *args,
1911 struct compound_hdr *hdr)
1912{
1913 __be32 *p;
1914
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001915 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1916 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001917 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1918 *p++ = cpu_to_be32(args->layout_type);
1919 *p++ = cpu_to_be32(IOMODE_ANY);
1920 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001921 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001922 p = xdr_encode_hyper(p, 0);
1923 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1924 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001925 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001926 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001927 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1928 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1929 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001930 } else
1931 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001932}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001933
1934static int
1935encode_secinfo_no_name(struct xdr_stream *xdr,
1936 const struct nfs41_secinfo_no_name_args *args,
1937 struct compound_hdr *hdr)
1938{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001939 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1940 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001941 return 0;
1942}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001943
1944static void encode_test_stateid(struct xdr_stream *xdr,
1945 struct nfs41_test_stateid_args *args,
1946 struct compound_hdr *hdr)
1947{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001948 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1949 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001950 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001951}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001952
1953static void encode_free_stateid(struct xdr_stream *xdr,
1954 struct nfs41_free_stateid_args *args,
1955 struct compound_hdr *hdr)
1956{
Trond Myklebustab19b482012-03-04 18:13:57 -05001957 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001958 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001959}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001960#endif /* CONFIG_NFS_V4_1 */
1961
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962/*
1963 * END OF "GENERIC" ENCODE ROUTINES.
1964 */
1965
Benny Halevy66cc0422009-04-01 09:22:10 -04001966static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1967{
1968#if defined(CONFIG_NFS_V4_1)
1969 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001970 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001971#endif /* CONFIG_NFS_V4_1 */
1972 return 0;
1973}
1974
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975/*
1976 * Encode an ACCESS request
1977 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001978static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1979 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001982 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Chuck Lever9f06c712010-12-14 14:59:18 +00001985 encode_compound_hdr(xdr, req, &hdr);
1986 encode_sequence(xdr, &args->seq_args, &hdr);
1987 encode_putfh(xdr, args->fh, &hdr);
1988 encode_access(xdr, args->access, &hdr);
1989 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001990 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991}
1992
1993/*
1994 * Encode LOOKUP request
1995 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001996static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1997 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002000 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
Chuck Lever9f06c712010-12-14 14:59:18 +00002003 encode_compound_hdr(xdr, req, &hdr);
2004 encode_sequence(xdr, &args->seq_args, &hdr);
2005 encode_putfh(xdr, args->dir_fh, &hdr);
2006 encode_lookup(xdr, args->name, &hdr);
2007 encode_getfh(xdr, &hdr);
2008 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002009 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
2012/*
2013 * Encode LOOKUP_ROOT request
2014 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002015static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2016 struct xdr_stream *xdr,
2017 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002020 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Chuck Lever9f06c712010-12-14 14:59:18 +00002023 encode_compound_hdr(xdr, req, &hdr);
2024 encode_sequence(xdr, &args->seq_args, &hdr);
2025 encode_putrootfh(xdr, &hdr);
2026 encode_getfh(xdr, &hdr);
2027 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002028 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029}
2030
2031/*
2032 * Encode REMOVE request
2033 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002034static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2035 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002038 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Chuck Lever9f06c712010-12-14 14:59:18 +00002041 encode_compound_hdr(xdr, req, &hdr);
2042 encode_sequence(xdr, &args->seq_args, &hdr);
2043 encode_putfh(xdr, args->fh, &hdr);
2044 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002045 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048/*
2049 * Encode RENAME request
2050 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002051static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2052 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002055 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Chuck Lever9f06c712010-12-14 14:59:18 +00002058 encode_compound_hdr(xdr, req, &hdr);
2059 encode_sequence(xdr, &args->seq_args, &hdr);
2060 encode_putfh(xdr, args->old_dir, &hdr);
2061 encode_savefh(xdr, &hdr);
2062 encode_putfh(xdr, args->new_dir, &hdr);
2063 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002064 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065}
2066
2067/*
2068 * Encode LINK request
2069 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002070static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2071 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002074 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
Chuck Lever9f06c712010-12-14 14:59:18 +00002077 encode_compound_hdr(xdr, req, &hdr);
2078 encode_sequence(xdr, &args->seq_args, &hdr);
2079 encode_putfh(xdr, args->fh, &hdr);
2080 encode_savefh(xdr, &hdr);
2081 encode_putfh(xdr, args->dir_fh, &hdr);
2082 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002083 encode_restorefh(xdr, &hdr);
2084 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002085 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086}
2087
2088/*
2089 * Encode CREATE request
2090 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002091static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2092 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002095 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Chuck Lever9f06c712010-12-14 14:59:18 +00002098 encode_compound_hdr(xdr, req, &hdr);
2099 encode_sequence(xdr, &args->seq_args, &hdr);
2100 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_create(xdr, args, &hdr);
2102 encode_getfh(xdr, &hdr);
2103 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002104 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105}
2106
2107/*
2108 * Encode SYMLINK request
2109 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002110static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2111 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
Chuck Lever9f06c712010-12-14 14:59:18 +00002113 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114}
2115
2116/*
2117 * Encode GETATTR request
2118 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002119static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2120 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002123 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Chuck Lever9f06c712010-12-14 14:59:18 +00002126 encode_compound_hdr(xdr, req, &hdr);
2127 encode_sequence(xdr, &args->seq_args, &hdr);
2128 encode_putfh(xdr, args->fh, &hdr);
2129 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002130 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
2133/*
2134 * Encode a CLOSE request
2135 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002136static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2137 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Andy Adamson05d564f2008-12-23 16:06:15 -05002139 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002140 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002141 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 encode_compound_hdr(xdr, req, &hdr);
2144 encode_sequence(xdr, &args->seq_args, &hdr);
2145 encode_putfh(xdr, args->fh, &hdr);
2146 encode_close(xdr, args, &hdr);
2147 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002148 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149}
2150
2151/*
2152 * Encode an OPEN request
2153 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002154static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2155 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_compound_hdr(xdr, req, &hdr);
2162 encode_sequence(xdr, &args->seq_args, &hdr);
2163 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002164 encode_open(xdr, args, &hdr);
2165 encode_getfh(xdr, &hdr);
2166 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002167 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168}
2169
2170/*
2171 * Encode an OPEN_CONFIRM request
2172 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002173static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2174 struct xdr_stream *xdr,
2175 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002178 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
Chuck Lever9f06c712010-12-14 14:59:18 +00002181 encode_compound_hdr(xdr, req, &hdr);
2182 encode_putfh(xdr, args->fh, &hdr);
2183 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002184 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185}
2186
2187/*
2188 * Encode an OPEN request with no attributes.
2189 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002190static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2191 struct xdr_stream *xdr,
2192 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_compound_hdr(xdr, req, &hdr);
2199 encode_sequence(xdr, &args->seq_args, &hdr);
2200 encode_putfh(xdr, args->fh, &hdr);
2201 encode_open(xdr, args, &hdr);
2202 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002203 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode an OPEN_DOWNGRADE request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2210 struct xdr_stream *xdr,
2211 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002214 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Chuck Lever9f06c712010-12-14 14:59:18 +00002217 encode_compound_hdr(xdr, req, &hdr);
2218 encode_sequence(xdr, &args->seq_args, &hdr);
2219 encode_putfh(xdr, args->fh, &hdr);
2220 encode_open_downgrade(xdr, args, &hdr);
2221 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002222 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225/*
2226 * Encode a LOCK request
2227 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002228static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2229 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002232 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Chuck Lever9f06c712010-12-14 14:59:18 +00002235 encode_compound_hdr(xdr, req, &hdr);
2236 encode_sequence(xdr, &args->seq_args, &hdr);
2237 encode_putfh(xdr, args->fh, &hdr);
2238 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002239 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240}
2241
2242/*
2243 * Encode a LOCKT request
2244 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002245static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2246 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002249 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Chuck Lever9f06c712010-12-14 14:59:18 +00002252 encode_compound_hdr(xdr, req, &hdr);
2253 encode_sequence(xdr, &args->seq_args, &hdr);
2254 encode_putfh(xdr, args->fh, &hdr);
2255 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002256 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257}
2258
2259/*
2260 * Encode a LOCKU request
2261 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002262static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2263 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002266 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Chuck Lever9f06c712010-12-14 14:59:18 +00002269 encode_compound_hdr(xdr, req, &hdr);
2270 encode_sequence(xdr, &args->seq_args, &hdr);
2271 encode_putfh(xdr, args->fh, &hdr);
2272 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002273 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274}
2275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2277 struct xdr_stream *xdr,
2278 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002279{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002280 struct compound_hdr hdr = {
2281 .minorversion = 0,
2282 };
2283
Chuck Lever9f06c712010-12-14 14:59:18 +00002284 encode_compound_hdr(xdr, req, &hdr);
2285 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002286 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002287}
2288
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289/*
2290 * Encode a READLINK request
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2293 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002296 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_sequence(xdr, &args->seq_args, &hdr);
2301 encode_putfh(xdr, args->fh, &hdr);
2302 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002303
Benny Halevy28f56692009-04-01 09:22:09 -04002304 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002305 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002306 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307}
2308
2309/*
2310 * Encode a READDIR request
2311 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002312static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2313 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002316 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
Chuck Lever9f06c712010-12-14 14:59:18 +00002319 encode_compound_hdr(xdr, req, &hdr);
2320 encode_sequence(xdr, &args->seq_args, &hdr);
2321 encode_putfh(xdr, args->fh, &hdr);
2322 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002323
Benny Halevy28f56692009-04-01 09:22:09 -04002324 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002325 args->pgbase, args->count);
2326 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002327 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002328 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002329 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
2332/*
2333 * Encode a READ request
2334 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002335static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2336 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002339 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Chuck Lever9f06c712010-12-14 14:59:18 +00002342 encode_compound_hdr(xdr, req, &hdr);
2343 encode_sequence(xdr, &args->seq_args, &hdr);
2344 encode_putfh(xdr, args->fh, &hdr);
2345 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
Benny Halevy28f56692009-04-01 09:22:09 -04002347 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002349 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * Encode an SETATTR request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Andy Adamson05d564f2008-12-23 16:06:15 -05002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_setattr(xdr, args, args->server, &hdr);
2367 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002368 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
2371/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002372 * Encode a GETACL request
2373 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002374static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2375 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002376{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002377 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002378 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002379 };
Benny Halevy28f56692009-04-01 09:22:09 -04002380 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002381
Chuck Lever9f06c712010-12-14 14:59:18 +00002382 encode_compound_hdr(xdr, req, &hdr);
2383 encode_sequence(xdr, &args->seq_args, &hdr);
2384 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002385 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002386 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002387
Benny Halevy28f56692009-04-01 09:22:09 -04002388 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002389 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002390
Andy Adamsond0179312008-12-23 16:06:17 -05002391 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002392}
2393
2394/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 * Encode a WRITE request
2396 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002397static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2398 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002401 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
Chuck Lever9f06c712010-12-14 14:59:18 +00002404 encode_compound_hdr(xdr, req, &hdr);
2405 encode_sequence(xdr, &args->seq_args, &hdr);
2406 encode_putfh(xdr, args->fh, &hdr);
2407 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002408 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002409 if (args->bitmask)
2410 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002411 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
2413
2414/*
2415 * a COMMIT request
2416 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002417static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002418 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002421 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Chuck Lever9f06c712010-12-14 14:59:18 +00002424 encode_compound_hdr(xdr, req, &hdr);
2425 encode_sequence(xdr, &args->seq_args, &hdr);
2426 encode_putfh(xdr, args->fh, &hdr);
2427 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002428 if (args->bitmask)
2429 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002430 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431}
2432
2433/*
2434 * FSINFO request
2435 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002436static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2437 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002447 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448}
2449
2450/*
2451 * a PATHCONF request
2452 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002453static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2454 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002457 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Chuck Lever9f06c712010-12-14 14:59:18 +00002460 encode_compound_hdr(xdr, req, &hdr);
2461 encode_sequence(xdr, &args->seq_args, &hdr);
2462 encode_putfh(xdr, args->fh, &hdr);
2463 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002464 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002465 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
2467
2468/*
2469 * a STATFS request
2470 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002471static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2472 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002475 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
Chuck Lever9f06c712010-12-14 14:59:18 +00002478 encode_compound_hdr(xdr, req, &hdr);
2479 encode_sequence(xdr, &args->seq_args, &hdr);
2480 encode_putfh(xdr, args->fh, &hdr);
2481 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002482 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002483 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484}
2485
2486/*
2487 * GETATTR_BITMAP request
2488 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002489static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2490 struct xdr_stream *xdr,
2491 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002494 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
Chuck Lever9f06c712010-12-14 14:59:18 +00002497 encode_compound_hdr(xdr, req, &hdr);
2498 encode_sequence(xdr, &args->seq_args, &hdr);
2499 encode_putfh(xdr, args->fhandle, &hdr);
2500 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002501 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002502 FATTR4_WORD0_LINK_SUPPORT|
2503 FATTR4_WORD0_SYMLINK_SUPPORT|
2504 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * a RENEW request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2512 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002515 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
2517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002519 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002520 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
2523/*
2524 * a SETCLIENTID request
2525 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002526static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2527 struct xdr_stream *xdr,
2528 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002531 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 };
2533
Chuck Lever9f06c712010-12-14 14:59:18 +00002534 encode_compound_hdr(xdr, req, &hdr);
2535 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002536 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537}
2538
2539/*
2540 * a SETCLIENTID_CONFIRM request
2541 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002542static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2543 struct xdr_stream *xdr,
2544 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002547 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 };
Fred Isamandae100c2011-07-30 20:52:37 -04002549 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Chuck Lever9f06c712010-12-14 14:59:18 +00002551 encode_compound_hdr(xdr, req, &hdr);
2552 encode_setclientid_confirm(xdr, arg, &hdr);
2553 encode_putrootfh(xdr, &hdr);
2554 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002555 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
2557
2558/*
2559 * DELEGRETURN request
2560 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002561static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2562 struct xdr_stream *xdr,
2563 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002566 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
Chuck Lever9f06c712010-12-14 14:59:18 +00002569 encode_compound_hdr(xdr, req, &hdr);
2570 encode_sequence(xdr, &args->seq_args, &hdr);
2571 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002572 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002573 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002574 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575}
2576
2577/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002578 * Encode FS_LOCATIONS request
2579 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002580static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2581 struct xdr_stream *xdr,
2582 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002583{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002584 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002585 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002586 };
Benny Halevy28f56692009-04-01 09:22:09 -04002587 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002588
Chuck Lever9f06c712010-12-14 14:59:18 +00002589 encode_compound_hdr(xdr, req, &hdr);
2590 encode_sequence(xdr, &args->seq_args, &hdr);
2591 encode_putfh(xdr, args->dir_fh, &hdr);
2592 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002593 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002594 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002595
Benny Halevy28f56692009-04-01 09:22:09 -04002596 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002597 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002598 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002599}
2600
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002601/*
2602 * Encode SECINFO request
2603 */
2604static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2605 struct xdr_stream *xdr,
2606 struct nfs4_secinfo_arg *args)
2607{
2608 struct compound_hdr hdr = {
2609 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2610 };
2611
2612 encode_compound_hdr(xdr, req, &hdr);
2613 encode_sequence(xdr, &args->seq_args, &hdr);
2614 encode_putfh(xdr, args->dir_fh, &hdr);
2615 encode_secinfo(xdr, args->name, &hdr);
2616 encode_nops(&hdr);
2617}
2618
Benny Halevy99fe60d2009-04-01 09:22:29 -04002619#if defined(CONFIG_NFS_V4_1)
2620/*
2621 * EXCHANGE_ID request
2622 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002623static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002626{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002627 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002628 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002629 };
2630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002633 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002634}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002635
2636/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002637 * a CREATE_SESSION request
2638 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002639static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2640 struct xdr_stream *xdr,
2641 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002642{
Andy Adamsonfc931582009-04-01 09:22:31 -04002643 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002644 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002645 };
2646
Chuck Lever9f06c712010-12-14 14:59:18 +00002647 encode_compound_hdr(xdr, req, &hdr);
2648 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002649 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002650}
2651
2652/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002653 * a DESTROY_SESSION request
2654 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002655static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2656 struct xdr_stream *xdr,
2657 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002658{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002659 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002660 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002661 };
2662
Chuck Lever9f06c712010-12-14 14:59:18 +00002663 encode_compound_hdr(xdr, req, &hdr);
2664 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002665 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002666}
2667
2668/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002669 * a SEQUENCE request
2670 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002671static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2672 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002673{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002674 struct compound_hdr hdr = {
2675 .minorversion = nfs4_xdr_minorversion(args),
2676 };
2677
Chuck Lever9f06c712010-12-14 14:59:18 +00002678 encode_compound_hdr(xdr, req, &hdr);
2679 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002680 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002681}
2682
2683/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002684 * a GET_LEASE_TIME request
2685 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002686static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2687 struct xdr_stream *xdr,
2688 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002689{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002690 struct compound_hdr hdr = {
2691 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2692 };
Fred Isamandae100c2011-07-30 20:52:37 -04002693 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002694
Chuck Lever9f06c712010-12-14 14:59:18 +00002695 encode_compound_hdr(xdr, req, &hdr);
2696 encode_sequence(xdr, &args->la_seq_args, &hdr);
2697 encode_putrootfh(xdr, &hdr);
2698 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002699 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002700}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002701
2702/*
2703 * a RECLAIM_COMPLETE request
2704 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002705static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2706 struct xdr_stream *xdr,
2707 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002708{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002709 struct compound_hdr hdr = {
2710 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2711 };
2712
Chuck Lever9f06c712010-12-14 14:59:18 +00002713 encode_compound_hdr(xdr, req, &hdr);
2714 encode_sequence(xdr, &args->seq_args, &hdr);
2715 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002716 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002717}
2718
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002719/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002720 * Encode GETDEVICELIST request
2721 */
2722static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2723 struct xdr_stream *xdr,
2724 struct nfs4_getdevicelist_args *args)
2725{
2726 struct compound_hdr hdr = {
2727 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2728 };
2729
2730 encode_compound_hdr(xdr, req, &hdr);
2731 encode_sequence(xdr, &args->seq_args, &hdr);
2732 encode_putfh(xdr, args->fh, &hdr);
2733 encode_getdevicelist(xdr, args, &hdr);
2734 encode_nops(&hdr);
2735}
2736
2737/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002738 * Encode GETDEVICEINFO request
2739 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002740static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2741 struct xdr_stream *xdr,
2742 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002743{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002744 struct compound_hdr hdr = {
2745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2746 };
2747
Chuck Lever9f06c712010-12-14 14:59:18 +00002748 encode_compound_hdr(xdr, req, &hdr);
2749 encode_sequence(xdr, &args->seq_args, &hdr);
2750 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002751
2752 /* set up reply kvec. Subtract notification bitmap max size (2)
2753 * so that notification bitmap is put in xdr_buf tail */
2754 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2755 args->pdev->pages, args->pdev->pgbase,
2756 args->pdev->pglen);
2757
2758 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002759}
2760
2761/*
2762 * Encode LAYOUTGET request
2763 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002764static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002767{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002768 struct compound_hdr hdr = {
2769 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2770 };
2771
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_sequence(xdr, &args->seq_args, &hdr);
2774 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2775 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002776
2777 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2778 args->layout.pages, 0, args->layout.pglen);
2779
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002780 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002781}
Andy Adamson863a3c62011-03-23 13:27:54 +00002782
2783/*
2784 * Encode LAYOUTCOMMIT request
2785 */
Benny Halevycbe82602011-05-22 19:52:37 +03002786static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002789{
Benny Halevyac7db722011-05-22 19:53:48 +03002790 struct nfs4_layoutcommit_data *data =
2791 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002792 struct compound_hdr hdr = {
2793 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2794 };
2795
2796 encode_compound_hdr(xdr, req, &hdr);
2797 encode_sequence(xdr, &args->seq_args, &hdr);
2798 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002799 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002800 encode_getfattr(xdr, args->bitmask, &hdr);
2801 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002802}
2803
2804/*
2805 * Encode LAYOUTRETURN request
2806 */
2807static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2808 struct xdr_stream *xdr,
2809 struct nfs4_layoutreturn_args *args)
2810{
2811 struct compound_hdr hdr = {
2812 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2813 };
2814
2815 encode_compound_hdr(xdr, req, &hdr);
2816 encode_sequence(xdr, &args->seq_args, &hdr);
2817 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2818 encode_layoutreturn(xdr, args, &hdr);
2819 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002820}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002821
2822/*
2823 * Encode SECINFO_NO_NAME request
2824 */
2825static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2826 struct xdr_stream *xdr,
2827 struct nfs41_secinfo_no_name_args *args)
2828{
2829 struct compound_hdr hdr = {
2830 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2831 };
2832
2833 encode_compound_hdr(xdr, req, &hdr);
2834 encode_sequence(xdr, &args->seq_args, &hdr);
2835 encode_putrootfh(xdr, &hdr);
2836 encode_secinfo_no_name(xdr, args, &hdr);
2837 encode_nops(&hdr);
2838 return 0;
2839}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002840
2841/*
2842 * Encode TEST_STATEID request
2843 */
2844static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2845 struct xdr_stream *xdr,
2846 struct nfs41_test_stateid_args *args)
2847{
2848 struct compound_hdr hdr = {
2849 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2850 };
2851
2852 encode_compound_hdr(xdr, req, &hdr);
2853 encode_sequence(xdr, &args->seq_args, &hdr);
2854 encode_test_stateid(xdr, args, &hdr);
2855 encode_nops(&hdr);
2856}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002857
2858/*
2859 * Encode FREE_STATEID request
2860 */
2861static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs41_free_stateid_args *args)
2864{
2865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2867 };
2868
2869 encode_compound_hdr(xdr, req, &hdr);
2870 encode_sequence(xdr, &args->seq_args, &hdr);
2871 encode_free_stateid(xdr, args, &hdr);
2872 encode_nops(&hdr);
2873}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002874#endif /* CONFIG_NFS_V4_1 */
2875
Benny Halevy686841b2009-08-14 17:19:48 +03002876static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2877{
2878 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2879 "Remaining buffer length is %tu words.\n",
2880 func, xdr->end - xdr->p);
2881}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Trond Myklebust683b57b2006-06-09 09:34:22 -04002883static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884{
Al Viro8687b632006-10-19 23:28:48 -07002885 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
Benny Halevyc0eae662009-08-14 17:20:14 +03002887 p = xdr_inline_decode(xdr, 4);
2888 if (unlikely(!p))
2889 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002890 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002891 p = xdr_inline_decode(xdr, *len);
2892 if (unlikely(!p))
2893 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 *string = (char *)p;
2895 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002896out_overflow:
2897 print_overflow_msg(__func__, xdr);
2898 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899}
2900
2901static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2902{
Al Viro8687b632006-10-19 23:28:48 -07002903 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904
Benny Halevyc0eae662009-08-14 17:20:14 +03002905 p = xdr_inline_decode(xdr, 8);
2906 if (unlikely(!p))
2907 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002908 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002909 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002910
Benny Halevyc0eae662009-08-14 17:20:14 +03002911 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2912 if (unlikely(!p))
2913 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 hdr->tag = (char *)p;
2915 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002916 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002917 if (unlikely(hdr->nops < 1))
2918 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002920out_overflow:
2921 print_overflow_msg(__func__, xdr);
2922 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923}
2924
2925static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2926{
Al Viro8687b632006-10-19 23:28:48 -07002927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 uint32_t opnum;
2929 int32_t nfserr;
2930
Benny Halevyc0eae662009-08-14 17:20:14 +03002931 p = xdr_inline_decode(xdr, 8);
2932 if (unlikely(!p))
2933 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002934 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002936 dprintk("nfs: Server returned operation"
2937 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 opnum, expected);
2939 return -EIO;
2940 }
Benny Halevycccddf42009-08-14 17:20:19 +03002941 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002943 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002945out_overflow:
2946 print_overflow_msg(__func__, xdr);
2947 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948}
2949
2950/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002951static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952{
Al Viro8687b632006-10-19 23:28:48 -07002953 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002954 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 char *str;
2956
Benny Halevyc0eae662009-08-14 17:20:14 +03002957 p = xdr_inline_decode(xdr, 12);
2958 if (likely(p))
2959 return decode_opaque_inline(xdr, &strlen, &str);
2960 print_overflow_msg(__func__, xdr);
2961 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962}
2963
2964static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2965{
Al Viro8687b632006-10-19 23:28:48 -07002966 uint32_t bmlen;
2967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Benny Halevyc0eae662009-08-14 17:20:14 +03002969 p = xdr_inline_decode(xdr, 4);
2970 if (unlikely(!p))
2971 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002972 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
Fred Isamandae100c2011-07-30 20:52:37 -04002974 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002975 p = xdr_inline_decode(xdr, (bmlen << 2));
2976 if (unlikely(!p))
2977 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002979 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04002980 if (bmlen > 1) {
2981 bitmap[1] = be32_to_cpup(p++);
2982 if (bmlen > 2)
2983 bitmap[2] = be32_to_cpup(p);
2984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 }
2986 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002987out_overflow:
2988 print_overflow_msg(__func__, xdr);
2989 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990}
2991
Al Viro8687b632006-10-19 23:28:48 -07002992static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993{
Al Viro8687b632006-10-19 23:28:48 -07002994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Benny Halevyc0eae662009-08-14 17:20:14 +03002996 p = xdr_inline_decode(xdr, 4);
2997 if (unlikely(!p))
2998 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002999 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 *savep = xdr->p;
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
3007static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3008{
3009 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003010 int ret;
3011 ret = decode_attr_bitmap(xdr, bitmask);
3012 if (unlikely(ret < 0))
3013 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3015 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003016 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3017 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3018 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 return 0;
3020}
3021
3022static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003025 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
3027 *type = 0;
3028 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3029 return -EIO;
3030 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003031 p = xdr_inline_decode(xdr, 4);
3032 if (unlikely(!p))
3033 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003034 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003036 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 return -EIO;
3038 }
3039 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003040 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003042 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003043 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003044out_overflow:
3045 print_overflow_msg(__func__, xdr);
3046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047}
3048
Chuck Lever264e6352012-03-01 17:02:05 -05003049static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3050 uint32_t *bitmap, uint32_t *type)
3051{
3052 __be32 *p;
3053
3054 *type = 0;
3055 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3056 return -EIO;
3057 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3058 p = xdr_inline_decode(xdr, 4);
3059 if (unlikely(!p))
3060 goto out_overflow;
3061 *type = be32_to_cpup(p);
3062 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3063 }
3064 dprintk("%s: expire type=0x%x\n", __func__, *type);
3065 return 0;
3066out_overflow:
3067 print_overflow_msg(__func__, xdr);
3068 return -EIO;
3069}
3070
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3072{
Al Viro8687b632006-10-19 23:28:48 -07003073 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003074 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
3076 *change = 0;
3077 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3078 return -EIO;
3079 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003080 p = xdr_inline_decode(xdr, 8);
3081 if (unlikely(!p))
3082 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003083 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003085 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003087 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003089 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003090out_overflow:
3091 print_overflow_msg(__func__, xdr);
3092 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093}
3094
3095static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3096{
Al Viro8687b632006-10-19 23:28:48 -07003097 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003098 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099
3100 *size = 0;
3101 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3102 return -EIO;
3103 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003104 p = xdr_inline_decode(xdr, 8);
3105 if (unlikely(!p))
3106 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003107 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003109 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003111 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003112 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003113out_overflow:
3114 print_overflow_msg(__func__, xdr);
3115 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116}
3117
3118static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3119{
Al Viro8687b632006-10-19 23:28:48 -07003120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121
3122 *res = 0;
3123 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3124 return -EIO;
3125 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003126 p = xdr_inline_decode(xdr, 4);
3127 if (unlikely(!p))
3128 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003129 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3131 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003132 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003134out_overflow:
3135 print_overflow_msg(__func__, xdr);
3136 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137}
3138
3139static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3140{
Al Viro8687b632006-10-19 23:28:48 -07003141 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142
3143 *res = 0;
3144 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3145 return -EIO;
3146 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, 4);
3148 if (unlikely(!p))
3149 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003150 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3152 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003153 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003155out_overflow:
3156 print_overflow_msg(__func__, xdr);
3157 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158}
3159
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003160static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161{
Al Viro8687b632006-10-19 23:28:48 -07003162 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003163 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 fsid->major = 0;
3166 fsid->minor = 0;
3167 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3168 return -EIO;
3169 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003170 p = xdr_inline_decode(xdr, 16);
3171 if (unlikely(!p))
3172 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003173 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003174 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003176 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003178 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 (unsigned long long)fsid->major,
3180 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003181 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003182out_overflow:
3183 print_overflow_msg(__func__, xdr);
3184 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185}
3186
3187static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3188{
Al Viro8687b632006-10-19 23:28:48 -07003189 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 *res = 60;
3192 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3193 return -EIO;
3194 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003195 p = xdr_inline_decode(xdr, 4);
3196 if (unlikely(!p))
3197 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003198 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3200 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003201 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003203out_overflow:
3204 print_overflow_msg(__func__, xdr);
3205 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206}
3207
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003208static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003209{
3210 __be32 *p;
3211
3212 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3213 return -EIO;
3214 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3215 p = xdr_inline_decode(xdr, 4);
3216 if (unlikely(!p))
3217 goto out_overflow;
3218 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003219 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003220 }
3221 return 0;
3222out_overflow:
3223 print_overflow_msg(__func__, xdr);
3224 return -EIO;
3225}
3226
3227static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3228{
3229 __be32 *p;
3230 int len;
3231
Trond Myklebust7ad07352010-10-23 15:34:20 -04003232 if (fh != NULL)
3233 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003234
3235 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3236 return -EIO;
3237 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3238 p = xdr_inline_decode(xdr, 4);
3239 if (unlikely(!p))
3240 goto out_overflow;
3241 len = be32_to_cpup(p);
3242 if (len > NFS4_FHSIZE)
3243 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003244 p = xdr_inline_decode(xdr, len);
3245 if (unlikely(!p))
3246 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003247 if (fh != NULL) {
3248 memcpy(fh->data, p, len);
3249 fh->size = len;
3250 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003251 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3252 }
3253 return 0;
3254out_overflow:
3255 print_overflow_msg(__func__, xdr);
3256 return -EIO;
3257}
3258
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3260{
Al Viro8687b632006-10-19 23:28:48 -07003261 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262
3263 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3264 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3265 return -EIO;
3266 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003267 p = xdr_inline_decode(xdr, 4);
3268 if (unlikely(!p))
3269 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003270 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3272 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003273 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003275out_overflow:
3276 print_overflow_msg(__func__, xdr);
3277 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278}
3279
3280static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3281{
Al Viro8687b632006-10-19 23:28:48 -07003282 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003283 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
3285 *fileid = 0;
3286 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3287 return -EIO;
3288 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003289 p = xdr_inline_decode(xdr, 8);
3290 if (unlikely(!p))
3291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003292 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003294 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003296 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003297 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003298out_overflow:
3299 print_overflow_msg(__func__, xdr);
3300 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301}
3302
Manoj Naik99baf622006-06-09 09:34:24 -04003303static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3304{
Al Viro8687b632006-10-19 23:28:48 -07003305 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003306 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003307
3308 *fileid = 0;
3309 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3310 return -EIO;
3311 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003312 p = xdr_inline_decode(xdr, 8);
3313 if (unlikely(!p))
3314 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003315 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003316 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003317 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003318 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003319 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003320 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003321out_overflow:
3322 print_overflow_msg(__func__, xdr);
3323 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003324}
3325
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3327{
Al Viro8687b632006-10-19 23:28:48 -07003328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 int status = 0;
3330
3331 *res = 0;
3332 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3333 return -EIO;
3334 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003335 p = xdr_inline_decode(xdr, 8);
3336 if (unlikely(!p))
3337 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003338 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3340 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003341 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003343out_overflow:
3344 print_overflow_msg(__func__, xdr);
3345 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346}
3347
3348static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3349{
Al Viro8687b632006-10-19 23:28:48 -07003350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 int status = 0;
3352
3353 *res = 0;
3354 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3355 return -EIO;
3356 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003357 p = xdr_inline_decode(xdr, 8);
3358 if (unlikely(!p))
3359 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003360 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3362 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003363 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003365out_overflow:
3366 print_overflow_msg(__func__, xdr);
3367 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368}
3369
3370static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3371{
Al Viro8687b632006-10-19 23:28:48 -07003372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 int status = 0;
3374
3375 *res = 0;
3376 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3377 return -EIO;
3378 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003379 p = xdr_inline_decode(xdr, 8);
3380 if (unlikely(!p))
3381 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003382 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3384 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003385 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003387out_overflow:
3388 print_overflow_msg(__func__, xdr);
3389 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390}
3391
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003392static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3393{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003394 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003395 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003396 int status = 0;
3397
Benny Halevyc0eae662009-08-14 17:20:14 +03003398 p = xdr_inline_decode(xdr, 4);
3399 if (unlikely(!p))
3400 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003401 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003402 if (n == 0)
3403 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003404 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003405 path->ncomponents = 0;
3406 while (path->ncomponents < n) {
3407 struct nfs4_string *component = &path->components[path->ncomponents];
3408 status = decode_opaque_inline(xdr, &component->len, &component->data);
3409 if (unlikely(status != 0))
3410 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003411 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003412 pr_cont("%s%.*s ",
3413 (path->ncomponents != n ? "/ " : ""),
3414 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003415 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3416 path->ncomponents++;
3417 else {
3418 dprintk("cannot parse %d components in path\n", n);
3419 goto out_eio;
3420 }
3421 }
3422out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003423 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003424root_path:
3425/* a root pathname is sent as a zero component4 */
3426 path->ncomponents = 1;
3427 path->components[0].len=0;
3428 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003429 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003430 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003431out_eio:
3432 dprintk(" status %d", status);
3433 status = -EIO;
3434 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003435out_overflow:
3436 print_overflow_msg(__func__, xdr);
3437 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003438}
3439
3440static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003441{
3442 int n;
Al Viro8687b632006-10-19 23:28:48 -07003443 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003444 int status = -EIO;
3445
3446 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3447 goto out;
3448 status = 0;
3449 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3450 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003451 status = -EIO;
3452 /* Ignore borken servers that return unrequested attrs */
3453 if (unlikely(res == NULL))
3454 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003455 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003456 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003457 if (unlikely(status != 0))
3458 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459 p = xdr_inline_decode(xdr, 4);
3460 if (unlikely(!p))
3461 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003462 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003463 if (n <= 0)
3464 goto out_eio;
3465 res->nlocations = 0;
3466 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003467 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003468 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003469
Benny Halevyc0eae662009-08-14 17:20:14 +03003470 p = xdr_inline_decode(xdr, 4);
3471 if (unlikely(!p))
3472 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003473 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003474
3475 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003476 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003477 while (loc->nservers < m) {
3478 struct nfs4_string *server = &loc->servers[loc->nservers];
3479 status = decode_opaque_inline(xdr, &server->len, &server->data);
3480 if (unlikely(status != 0))
3481 goto out_eio;
3482 dprintk("%s ", server->data);
3483 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3484 loc->nservers++;
3485 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003486 unsigned int i;
3487 dprintk("%s: using first %u of %u servers "
3488 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003489 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003490 NFS4_FS_LOCATION_MAXSERVERS,
3491 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003492 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003493 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003494 char *data;
3495 status = decode_opaque_inline(xdr, &len, &data);
3496 if (unlikely(status != 0))
3497 goto out_eio;
3498 }
3499 }
3500 }
3501 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003502 if (unlikely(status != 0))
3503 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003505 res->nlocations++;
3506 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003507 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003508 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003509out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003510 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003511 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003512out_overflow:
3513 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003514out_eio:
3515 status = -EIO;
3516 goto out;
3517}
3518
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3520{
Al Viro8687b632006-10-19 23:28:48 -07003521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 int status = 0;
3523
3524 *res = 0;
3525 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3526 return -EIO;
3527 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003528 p = xdr_inline_decode(xdr, 8);
3529 if (unlikely(!p))
3530 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003531 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3533 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003536out_overflow:
3537 print_overflow_msg(__func__, xdr);
3538 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539}
3540
3541static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3542{
Al Viro8687b632006-10-19 23:28:48 -07003543 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 int status = 0;
3545
3546 *maxlink = 1;
3547 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3548 return -EIO;
3549 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003550 p = xdr_inline_decode(xdr, 4);
3551 if (unlikely(!p))
3552 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003553 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3555 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003556 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003558out_overflow:
3559 print_overflow_msg(__func__, xdr);
3560 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561}
3562
3563static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3564{
Al Viro8687b632006-10-19 23:28:48 -07003565 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 int status = 0;
3567
3568 *maxname = 1024;
3569 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3570 return -EIO;
3571 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003572 p = xdr_inline_decode(xdr, 4);
3573 if (unlikely(!p))
3574 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003575 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3577 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003578 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003580out_overflow:
3581 print_overflow_msg(__func__, xdr);
3582 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583}
3584
3585static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3586{
Al Viro8687b632006-10-19 23:28:48 -07003587 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 int status = 0;
3589
3590 *res = 1024;
3591 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3592 return -EIO;
3593 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3594 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003595 p = xdr_inline_decode(xdr, 8);
3596 if (unlikely(!p))
3597 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003598 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 if (maxread > 0x7FFFFFFF)
3600 maxread = 0x7FFFFFFF;
3601 *res = (uint32_t)maxread;
3602 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3603 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003604 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003606out_overflow:
3607 print_overflow_msg(__func__, xdr);
3608 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609}
3610
3611static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3612{
Al Viro8687b632006-10-19 23:28:48 -07003613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 int status = 0;
3615
3616 *res = 1024;
3617 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3618 return -EIO;
3619 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3620 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003621 p = xdr_inline_decode(xdr, 8);
3622 if (unlikely(!p))
3623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003624 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 if (maxwrite > 0x7FFFFFFF)
3626 maxwrite = 0x7FFFFFFF;
3627 *res = (uint32_t)maxwrite;
3628 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3629 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003630 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003632out_overflow:
3633 print_overflow_msg(__func__, xdr);
3634 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635}
3636
Trond Myklebustbca79472009-03-11 14:10:26 -04003637static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638{
Trond Myklebustbca79472009-03-11 14:10:26 -04003639 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003640 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003641 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642
3643 *mode = 0;
3644 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3645 return -EIO;
3646 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003647 p = xdr_inline_decode(xdr, 4);
3648 if (unlikely(!p))
3649 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003650 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003651 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003653 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003655 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003656 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003657out_overflow:
3658 print_overflow_msg(__func__, xdr);
3659 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660}
3661
3662static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3663{
Al Viro8687b632006-10-19 23:28:48 -07003664 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003665 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
3667 *nlink = 1;
3668 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3669 return -EIO;
3670 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003671 p = xdr_inline_decode(xdr, 4);
3672 if (unlikely(!p))
3673 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003674 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003676 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003678 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003679 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003680out_overflow:
3681 print_overflow_msg(__func__, xdr);
3682 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683}
3684
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003685static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003686 const struct nfs_server *server, uint32_t *uid,
3687 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688{
Al Viro8687b632006-10-19 23:28:48 -07003689 uint32_t len;
3690 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692
3693 *uid = -2;
3694 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3695 return -EIO;
3696 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003697 p = xdr_inline_decode(xdr, 4);
3698 if (unlikely(!p))
3699 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003700 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003701 p = xdr_inline_decode(xdr, len);
3702 if (unlikely(!p))
3703 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003704 if (owner_name != NULL) {
3705 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3706 if (owner_name->data != NULL) {
3707 owner_name->len = len;
3708 ret = NFS_ATTR_FATTR_OWNER_NAME;
3709 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003710 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003711 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003712 ret = NFS_ATTR_FATTR_OWNER;
3713 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003715 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003717 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003718 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3720 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003721 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003722 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003723out_overflow:
3724 print_overflow_msg(__func__, xdr);
3725 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726}
3727
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003728static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003729 const struct nfs_server *server, uint32_t *gid,
3730 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731{
Al Viro8687b632006-10-19 23:28:48 -07003732 uint32_t len;
3733 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003734 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
3736 *gid = -2;
3737 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3738 return -EIO;
3739 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003740 p = xdr_inline_decode(xdr, 4);
3741 if (unlikely(!p))
3742 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003743 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003744 p = xdr_inline_decode(xdr, len);
3745 if (unlikely(!p))
3746 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003747 if (group_name != NULL) {
3748 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3749 if (group_name->data != NULL) {
3750 group_name->len = len;
3751 ret = NFS_ATTR_FATTR_GROUP_NAME;
3752 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003753 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003754 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003755 ret = NFS_ATTR_FATTR_GROUP;
3756 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003758 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003760 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003761 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3763 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003764 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003765 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003766out_overflow:
3767 print_overflow_msg(__func__, xdr);
3768 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
3771static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3772{
Al Viro8687b632006-10-19 23:28:48 -07003773 uint32_t major = 0, minor = 0;
3774 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003775 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
3777 *rdev = MKDEV(0,0);
3778 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3779 return -EIO;
3780 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3781 dev_t tmp;
3782
Benny Halevyc0eae662009-08-14 17:20:14 +03003783 p = xdr_inline_decode(xdr, 8);
3784 if (unlikely(!p))
3785 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003786 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003787 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 tmp = MKDEV(major, minor);
3789 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3790 *rdev = tmp;
3791 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003794 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003796out_overflow:
3797 print_overflow_msg(__func__, xdr);
3798 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799}
3800
3801static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3802{
Al Viro8687b632006-10-19 23:28:48 -07003803 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 int status = 0;
3805
3806 *res = 0;
3807 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3808 return -EIO;
3809 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003810 p = xdr_inline_decode(xdr, 8);
3811 if (unlikely(!p))
3812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003813 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3815 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003816 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003818out_overflow:
3819 print_overflow_msg(__func__, xdr);
3820 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821}
3822
3823static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3824{
Al Viro8687b632006-10-19 23:28:48 -07003825 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 int status = 0;
3827
3828 *res = 0;
3829 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3830 return -EIO;
3831 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003832 p = xdr_inline_decode(xdr, 8);
3833 if (unlikely(!p))
3834 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003835 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3837 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003838 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003840out_overflow:
3841 print_overflow_msg(__func__, xdr);
3842 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843}
3844
3845static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3846{
Al Viro8687b632006-10-19 23:28:48 -07003847 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 int status = 0;
3849
3850 *res = 0;
3851 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3852 return -EIO;
3853 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003854 p = xdr_inline_decode(xdr, 8);
3855 if (unlikely(!p))
3856 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003857 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3859 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003860 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003862out_overflow:
3863 print_overflow_msg(__func__, xdr);
3864 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
3866
3867static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3868{
Al Viro8687b632006-10-19 23:28:48 -07003869 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003870 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
3872 *used = 0;
3873 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3874 return -EIO;
3875 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003876 p = xdr_inline_decode(xdr, 8);
3877 if (unlikely(!p))
3878 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003879 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003883 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003885 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003886out_overflow:
3887 print_overflow_msg(__func__, xdr);
3888 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889}
3890
3891static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3892{
Al Viro8687b632006-10-19 23:28:48 -07003893 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 uint64_t sec;
3895 uint32_t nsec;
3896
Benny Halevyc0eae662009-08-14 17:20:14 +03003897 p = xdr_inline_decode(xdr, 12);
3898 if (unlikely(!p))
3899 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003900 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003901 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 time->tv_sec = (time_t)sec;
3903 time->tv_nsec = (long)nsec;
3904 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003905out_overflow:
3906 print_overflow_msg(__func__, xdr);
3907 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908}
3909
3910static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3911{
3912 int status = 0;
3913
3914 time->tv_sec = 0;
3915 time->tv_nsec = 0;
3916 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3917 return -EIO;
3918 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3919 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 if (status == 0)
3921 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3923 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003924 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 return status;
3926}
3927
3928static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3929{
3930 int status = 0;
3931
3932 time->tv_sec = 0;
3933 time->tv_nsec = 0;
3934 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3935 return -EIO;
3936 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3937 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003938 if (status == 0)
3939 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3941 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003942 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 return status;
3944}
3945
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003946static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3947 struct timespec *time)
3948{
3949 int status = 0;
3950
3951 time->tv_sec = 0;
3952 time->tv_nsec = 0;
3953 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3954 return -EIO;
3955 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3956 status = decode_attr_time(xdr, time);
3957 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3958 }
3959 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3960 (long)time->tv_nsec);
3961 return status;
3962}
3963
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3965{
3966 int status = 0;
3967
3968 time->tv_sec = 0;
3969 time->tv_nsec = 0;
3970 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3971 return -EIO;
3972 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3973 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003974 if (status == 0)
3975 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3977 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003978 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 return status;
3980}
3981
Al Viro8687b632006-10-19 23:28:48 -07003982static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983{
3984 unsigned int attrwords = XDR_QUADLEN(attrlen);
3985 unsigned int nwords = xdr->p - savep;
3986
3987 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003988 dprintk("%s: server returned incorrect attribute length: "
3989 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003990 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 attrwords << 2,
3992 (attrwords < nwords) ? '<' : '>',
3993 nwords << 2);
3994 return -EIO;
3995 }
3996 return 0;
3997}
3998
3999static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4000{
Al Viro8687b632006-10-19 23:28:48 -07004001 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002
Benny Halevyc0eae662009-08-14 17:20:14 +03004003 p = xdr_inline_decode(xdr, 20);
4004 if (unlikely(!p))
4005 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004006 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004007 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004008 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004010out_overflow:
4011 print_overflow_msg(__func__, xdr);
4012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013}
4014
4015static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4016{
Al Viro8687b632006-10-19 23:28:48 -07004017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 uint32_t supp, acc;
4019 int status;
4020
4021 status = decode_op_hdr(xdr, OP_ACCESS);
4022 if (status)
4023 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004024 p = xdr_inline_decode(xdr, 8);
4025 if (unlikely(!p))
4026 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004027 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004028 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 access->supported = supp;
4030 access->access = acc;
4031 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004032out_overflow:
4033 print_overflow_msg(__func__, xdr);
4034 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035}
4036
Benny Halevy07d30432009-08-14 17:19:52 +03004037static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038{
Al Viro8687b632006-10-19 23:28:48 -07004039 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004040
4041 p = xdr_inline_decode(xdr, len);
4042 if (likely(p)) {
4043 memcpy(buf, p, len);
4044 return 0;
4045 }
4046 print_overflow_msg(__func__, xdr);
4047 return -EIO;
4048}
4049
4050static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4051{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004052 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053}
4054
4055static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4056{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 int status;
4058
4059 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004060 if (status != -EIO)
4061 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004062 if (!status)
4063 status = decode_stateid(xdr, &res->stateid);
4064 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065}
4066
Benny Halevydb942bb2009-08-14 17:19:56 +03004067static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4068{
Chuck Levercd937102012-03-02 17:14:31 -05004069 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070}
4071
Fred Isaman0b7c0152012-04-20 14:47:39 -04004072static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 int status;
4075
4076 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004077 if (!status)
4078 status = decode_verifier(xdr, res->verf->verifier);
4079 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4083{
Al Viro8687b632006-10-19 23:28:48 -07004084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 uint32_t bmlen;
4086 int status;
4087
4088 status = decode_op_hdr(xdr, OP_CREATE);
4089 if (status)
4090 return status;
4091 if ((status = decode_change_info(xdr, cinfo)))
4092 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004093 p = xdr_inline_decode(xdr, 4);
4094 if (unlikely(!p))
4095 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004096 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004097 p = xdr_inline_decode(xdr, bmlen << 2);
4098 if (likely(p))
4099 return 0;
4100out_overflow:
4101 print_overflow_msg(__func__, xdr);
4102 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103}
4104
4105static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4106{
Al Viro8687b632006-10-19 23:28:48 -07004107 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004108 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 int status;
4110
4111 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4112 goto xdr_error;
4113 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4114 goto xdr_error;
4115 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4116 goto xdr_error;
4117 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4118 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004119 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4120 &res->fh_expire_type)) != 0)
4121 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4123 goto xdr_error;
4124 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4125 goto xdr_error;
4126 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4127 goto xdr_error;
4128 status = verify_attr_len(xdr, savep, attrlen);
4129xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004130 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 return status;
4132}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004133
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4135{
Al Viro8687b632006-10-19 23:28:48 -07004136 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004137 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004139
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4141 goto xdr_error;
4142 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4143 goto xdr_error;
4144 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4145 goto xdr_error;
4146
4147 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4148 goto xdr_error;
4149 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4150 goto xdr_error;
4151 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4152 goto xdr_error;
4153 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4154 goto xdr_error;
4155 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4156 goto xdr_error;
4157 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4158 goto xdr_error;
4159
4160 status = verify_attr_len(xdr, savep, attrlen);
4161xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004162 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 return status;
4164}
4165
4166static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4167{
Al Viro8687b632006-10-19 23:28:48 -07004168 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004169 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4173 goto xdr_error;
4174 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4175 goto xdr_error;
4176 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4177 goto xdr_error;
4178
4179 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4180 goto xdr_error;
4181 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4182 goto xdr_error;
4183
4184 status = verify_attr_len(xdr, savep, attrlen);
4185xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004186 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return status;
4188}
4189
Bryan Schumakerae42c702010-10-21 16:33:17 -04004190static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4191 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004192 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004193 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194{
Trond Myklebustbca79472009-03-11 14:10:26 -04004195 int status;
4196 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004197 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004198 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004200 status = decode_attr_type(xdr, bitmap, &type);
4201 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004203 fattr->mode = 0;
4204 if (status != 0) {
4205 fattr->mode |= nfs_type2fmt[type];
4206 fattr->valid |= status;
4207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004209 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4210 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004212 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004213
4214 status = decode_attr_size(xdr, bitmap, &fattr->size);
4215 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004217 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004218
4219 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4220 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004222 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004223
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004224 err = 0;
4225 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004226 if (status < 0)
4227 goto xdr_error;
4228
4229 status = decode_attr_filehandle(xdr, bitmap, fh);
4230 if (status < 0)
4231 goto xdr_error;
4232
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004233 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4234 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004236 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004237
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004238 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004239 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004240 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004241 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004242
4243 status = decode_attr_mode(xdr, bitmap, &fmode);
4244 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004246 if (status != 0) {
4247 fattr->mode |= fmode;
4248 fattr->valid |= status;
4249 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004250
4251 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4252 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004254 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004255
Trond Myklebust6926afd2012-01-07 13:22:46 -05004256 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004257 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004259 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004260
Trond Myklebust6926afd2012-01-07 13:22:46 -05004261 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004262 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004264 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004265
4266 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
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
4271 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4272 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
4276 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4277 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_time_metadata(xdr, bitmap, &fattr->ctime);
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_time_modify(xdr, bitmap, &fattr->mtime);
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
Trond Myklebust28331a42011-04-27 13:47:52 -04004291 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004292 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004293 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004294 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004295
Bryan Schumakerae42c702010-10-21 16:33:17 -04004296xdr_error:
4297 dprintk("%s: xdr returned %d\n", __func__, -status);
4298 return status;
4299}
4300
4301static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004302 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4303 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004304{
4305 __be32 *savep;
4306 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004307 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004308 int status;
4309
4310 status = decode_op_hdr(xdr, OP_GETATTR);
4311 if (status < 0)
4312 goto xdr_error;
4313
4314 status = decode_attr_bitmap(xdr, bitmap);
4315 if (status < 0)
4316 goto xdr_error;
4317
4318 status = decode_attr_length(xdr, &attrlen, &savep);
4319 if (status < 0)
4320 goto xdr_error;
4321
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004322 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004323 if (status < 0)
4324 goto xdr_error;
4325
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004326 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004328 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329 return status;
4330}
4331
Bryan Schumakerae42c702010-10-21 16:33:17 -04004332static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004333 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004334{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004335 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004336}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337
Andy Adamson504913f2010-10-20 00:17:57 -04004338/*
4339 * Decode potentially multiple layout types. Currently we only support
4340 * one layout driver per file system.
4341 */
4342static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4343 uint32_t *layouttype)
4344{
4345 uint32_t *p;
4346 int num;
4347
4348 p = xdr_inline_decode(xdr, 4);
4349 if (unlikely(!p))
4350 goto out_overflow;
4351 num = be32_to_cpup(p);
4352
4353 /* pNFS is not supported by the underlying file system */
4354 if (num == 0) {
4355 *layouttype = 0;
4356 return 0;
4357 }
4358 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004359 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4360 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004361
4362 /* Decode and set first layout type, move xdr->p past unused types */
4363 p = xdr_inline_decode(xdr, num * 4);
4364 if (unlikely(!p))
4365 goto out_overflow;
4366 *layouttype = be32_to_cpup(p);
4367 return 0;
4368out_overflow:
4369 print_overflow_msg(__func__, xdr);
4370 return -EIO;
4371}
4372
4373/*
4374 * The type of file system exported.
4375 * Note we must ensure that layouttype is set in any non-error case.
4376 */
4377static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4378 uint32_t *layouttype)
4379{
4380 int status = 0;
4381
4382 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4383 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4384 return -EIO;
4385 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4386 status = decode_first_pnfs_layout_type(xdr, layouttype);
4387 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4388 } else
4389 *layouttype = 0;
4390 return status;
4391}
4392
Fred Isamandae100c2011-07-30 20:52:37 -04004393/*
4394 * The prefered block size for layout directed io
4395 */
4396static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4397 uint32_t *res)
4398{
4399 __be32 *p;
4400
4401 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4402 *res = 0;
4403 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4404 p = xdr_inline_decode(xdr, 4);
4405 if (unlikely(!p)) {
4406 print_overflow_msg(__func__, xdr);
4407 return -EIO;
4408 }
4409 *res = be32_to_cpup(p);
4410 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4411 }
4412 return 0;
4413}
4414
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4416{
Al Viro8687b632006-10-19 23:28:48 -07004417 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004418 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 int status;
4420
4421 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4422 goto xdr_error;
4423 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4424 goto xdr_error;
4425 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4426 goto xdr_error;
4427
4428 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4429
4430 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4431 goto xdr_error;
4432 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4433 goto xdr_error;
4434 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4435 goto xdr_error;
4436 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4437 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4438 goto xdr_error;
4439 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004440 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4441 if (status != 0)
4442 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004443 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4444 if (status != 0)
4445 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004446 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4447 if (status)
4448 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449
4450 status = verify_attr_len(xdr, savep, attrlen);
4451xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004452 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 return status;
4454}
4455
4456static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4457{
Al Viro8687b632006-10-19 23:28:48 -07004458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 uint32_t len;
4460 int status;
4461
Trond Myklebust99367812007-07-17 21:52:41 -04004462 /* Zero handle first to allow comparisons */
4463 memset(fh, 0, sizeof(*fh));
4464
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 status = decode_op_hdr(xdr, OP_GETFH);
4466 if (status)
4467 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468
Benny Halevyc0eae662009-08-14 17:20:14 +03004469 p = xdr_inline_decode(xdr, 4);
4470 if (unlikely(!p))
4471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004472 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 if (len > NFS4_FHSIZE)
4474 return -EIO;
4475 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004476 p = xdr_inline_decode(xdr, len);
4477 if (unlikely(!p))
4478 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004479 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004481out_overflow:
4482 print_overflow_msg(__func__, xdr);
4483 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484}
4485
4486static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4487{
4488 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004489
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 status = decode_op_hdr(xdr, OP_LINK);
4491 if (status)
4492 return status;
4493 return decode_change_info(xdr, cinfo);
4494}
4495
4496/*
4497 * We create the owner, so we know a proper owner.id length is 4.
4498 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004499static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004501 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004502 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004503 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004505 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004506 if (unlikely(!p))
4507 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004508 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004509 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004510 type = be32_to_cpup(p++); /* 4 byte read */
4511 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004512 fl->fl_start = (loff_t)offset;
4513 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4514 if (length == ~(uint64_t)0)
4515 fl->fl_end = OFFSET_MAX;
4516 fl->fl_type = F_WRLCK;
4517 if (type & 1)
4518 fl->fl_type = F_RDLCK;
4519 fl->fl_pid = 0;
4520 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004521 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4522 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4523 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004524 if (likely(p))
4525 return -NFS4ERR_DENIED;
4526out_overflow:
4527 print_overflow_msg(__func__, xdr);
4528 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529}
4530
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004531static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 int status;
4534
4535 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004536 if (status == -EIO)
4537 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004539 status = decode_stateid(xdr, &res->stateid);
4540 if (unlikely(status))
4541 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004543 status = decode_lock_denied(xdr, NULL);
4544 if (res->open_seqid != NULL)
4545 nfs_increment_open_seqid(status, res->open_seqid);
4546 nfs_increment_lock_seqid(status, res->lock_seqid);
4547out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 return status;
4549}
4550
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004551static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552{
4553 int status;
4554 status = decode_op_hdr(xdr, OP_LOCKT);
4555 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004556 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 return status;
4558}
4559
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004560static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 int status;
4563
4564 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004565 if (status != -EIO)
4566 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004567 if (status == 0)
4568 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569 return status;
4570}
4571
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004572static int decode_release_lockowner(struct xdr_stream *xdr)
4573{
4574 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4575}
4576
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577static int decode_lookup(struct xdr_stream *xdr)
4578{
4579 return decode_op_hdr(xdr, OP_LOOKUP);
4580}
4581
4582/* This is too sick! */
4583static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4584{
Andy Adamson05d564f2008-12-23 16:06:15 -05004585 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 uint32_t limit_type, nblocks, blocksize;
4587
Benny Halevyc0eae662009-08-14 17:20:14 +03004588 p = xdr_inline_decode(xdr, 12);
4589 if (unlikely(!p))
4590 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004591 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004593 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004594 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004595 break;
4596 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004597 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004598 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004599 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 }
4601 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004602out_overflow:
4603 print_overflow_msg(__func__, xdr);
4604 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605}
4606
4607static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4608{
Andy Adamson05d564f2008-12-23 16:06:15 -05004609 __be32 *p;
4610 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004611 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612
Benny Halevyc0eae662009-08-14 17:20:14 +03004613 p = xdr_inline_decode(xdr, 4);
4614 if (unlikely(!p))
4615 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004616 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4618 res->delegation_type = 0;
4619 return 0;
4620 }
Benny Halevy07d30432009-08-14 17:19:52 +03004621 status = decode_stateid(xdr, &res->delegation);
4622 if (unlikely(status))
4623 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004624 p = xdr_inline_decode(xdr, 4);
4625 if (unlikely(!p))
4626 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004627 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004628
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004630 case NFS4_OPEN_DELEGATE_READ:
4631 res->delegation_type = FMODE_READ;
4632 break;
4633 case NFS4_OPEN_DELEGATE_WRITE:
4634 res->delegation_type = FMODE_WRITE|FMODE_READ;
4635 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 return -EIO;
4637 }
David Howells7539bba2006-08-22 20:06:09 -04004638 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004639out_overflow:
4640 print_overflow_msg(__func__, xdr);
4641 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642}
4643
4644static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4645{
Andy Adamson05d564f2008-12-23 16:06:15 -05004646 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004647 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004648 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649
Andy Adamson05d564f2008-12-23 16:06:15 -05004650 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004651 if (status != -EIO)
4652 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004653 if (!status)
4654 status = decode_stateid(xdr, &res->stateid);
4655 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004656 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657
Andy Adamson05d564f2008-12-23 16:06:15 -05004658 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Benny Halevyc0eae662009-08-14 17:20:14 +03004660 p = xdr_inline_decode(xdr, 8);
4661 if (unlikely(!p))
4662 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004663 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004664 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004665 if (bmlen > 10)
4666 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667
Benny Halevyc0eae662009-08-14 17:20:14 +03004668 p = xdr_inline_decode(xdr, bmlen << 2);
4669 if (unlikely(!p))
4670 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004671 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4672 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004673 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004674 for (; i < NFS4_BITMAP_SIZE; i++)
4675 res->attrset[i] = 0;
4676
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 return decode_delegation(xdr, res);
4678xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004679 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004681out_overflow:
4682 print_overflow_msg(__func__, xdr);
4683 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684}
4685
4686static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4687{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688 int status;
4689
Andy Adamson05d564f2008-12-23 16:06:15 -05004690 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004691 if (status != -EIO)
4692 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004693 if (!status)
4694 status = decode_stateid(xdr, &res->stateid);
4695 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696}
4697
4698static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4699{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 int status;
4701
4702 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004703 if (status != -EIO)
4704 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004705 if (!status)
4706 status = decode_stateid(xdr, &res->stateid);
4707 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708}
4709
4710static int decode_putfh(struct xdr_stream *xdr)
4711{
4712 return decode_op_hdr(xdr, OP_PUTFH);
4713}
4714
4715static int decode_putrootfh(struct xdr_stream *xdr)
4716{
4717 return decode_op_hdr(xdr, OP_PUTROOTFH);
4718}
4719
4720static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4721{
4722 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004723 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 uint32_t count, eof, recvd, hdrlen;
4725 int status;
4726
4727 status = decode_op_hdr(xdr, OP_READ);
4728 if (status)
4729 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004730 p = xdr_inline_decode(xdr, 8);
4731 if (unlikely(!p))
4732 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004733 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004734 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004735 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 recvd = req->rq_rcv_buf.len - hdrlen;
4737 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004738 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 "count %u > recvd %u\n", count, recvd);
4740 count = recvd;
4741 eof = 0;
4742 }
4743 xdr_read_pages(xdr, count);
4744 res->eof = eof;
4745 res->count = count;
4746 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004747out_overflow:
4748 print_overflow_msg(__func__, xdr);
4749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750}
4751
4752static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4753{
4754 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004756 size_t hdrlen;
4757 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004758 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004759 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760
4761 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004762 if (!status)
4763 status = decode_verifier(xdr, readdir->verifier.data);
4764 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004766 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004767 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004768 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769
Benny Halevydb942bb2009-08-14 17:19:56 +03004770 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 recvd = rcvbuf->len - hdrlen;
4772 if (pglen > recvd)
4773 pglen = recvd;
4774 xdr_read_pages(xdr, pglen);
4775
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004776
Trond Myklebustac396122010-11-15 20:26:22 -05004777 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778}
4779
4780static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4781{
4782 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4783 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004784 size_t hdrlen;
4785 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 int status;
4788
4789 status = decode_op_hdr(xdr, OP_READLINK);
4790 if (status)
4791 return status;
4792
4793 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004794 p = xdr_inline_decode(xdr, 4);
4795 if (unlikely(!p))
4796 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004797 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004799 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 return -ENAMETOOLONG;
4801 }
4802 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4803 recvd = req->rq_rcv_buf.len - hdrlen;
4804 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004805 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 "count %u > recvd %u\n", len, recvd);
4807 return -EIO;
4808 }
4809 xdr_read_pages(xdr, len);
4810 /*
4811 * The XDR encode routine has set things up so that
4812 * the link text will be copied directly into the
4813 * buffer. We just have to do overflow-checking,
4814 * and and null-terminate the text (the VFS expects
4815 * null-termination).
4816 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004817 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004819out_overflow:
4820 print_overflow_msg(__func__, xdr);
4821 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822}
4823
4824static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4825{
4826 int status;
4827
4828 status = decode_op_hdr(xdr, OP_REMOVE);
4829 if (status)
4830 goto out;
4831 status = decode_change_info(xdr, cinfo);
4832out:
4833 return status;
4834}
4835
4836static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4837 struct nfs4_change_info *new_cinfo)
4838{
4839 int status;
4840
4841 status = decode_op_hdr(xdr, OP_RENAME);
4842 if (status)
4843 goto out;
4844 if ((status = decode_change_info(xdr, old_cinfo)))
4845 goto out;
4846 status = decode_change_info(xdr, new_cinfo);
4847out:
4848 return status;
4849}
4850
4851static int decode_renew(struct xdr_stream *xdr)
4852{
4853 return decode_op_hdr(xdr, OP_RENEW);
4854}
4855
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004856static int
4857decode_restorefh(struct xdr_stream *xdr)
4858{
4859 return decode_op_hdr(xdr, OP_RESTOREFH);
4860}
4861
J. Bruce Fields029d1052005-06-22 17:16:22 +00004862static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004863 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004864{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004865 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004866 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004867 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004868 struct kvec *iov = req->rq_rcv_buf.head;
4869 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004870 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004871
Andy Adamsonbf118a32011-12-07 11:55:27 -05004872 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004873 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4874 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004875
Andy Adamsonbf118a32011-12-07 11:55:27 -05004876 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004877 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4878 res->acl_data_offset <<= 2;
4879 /* Check if the acl data starts beyond the allocated buffer */
4880 if (res->acl_data_offset > page_len)
4881 return -ERANGE;
4882
J. Bruce Fields029d1052005-06-22 17:16:22 +00004883 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4884 goto out;
4885 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4886 goto out;
4887
4888 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4889 return -EIO;
4890 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004891 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004892
Andy Adamsonbf118a32011-12-07 11:55:27 -05004893 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4894 * are stored with the acl data to handle the problem of
4895 * variable length bitmaps.*/
4896 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004897
J. Bruce Fields029d1052005-06-22 17:16:22 +00004898 /* We ignore &savep and don't do consistency checks on
4899 * the attr length. Let userspace figure it out.... */
4900 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004901 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004902 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004903 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4904 /* getxattr interface called with a NULL buf */
4905 res->acl_len = attrlen;
4906 goto out;
4907 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01004908 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01004909 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004910 return -EINVAL;
4911 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004912 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004913 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004914 } else
4915 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004916
4917out:
4918 return status;
4919}
4920
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921static int
4922decode_savefh(struct xdr_stream *xdr)
4923{
4924 return decode_op_hdr(xdr, OP_SAVEFH);
4925}
4926
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004927static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928{
Al Viro8687b632006-10-19 23:28:48 -07004929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 uint32_t bmlen;
4931 int status;
4932
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 status = decode_op_hdr(xdr, OP_SETATTR);
4934 if (status)
4935 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004936 p = xdr_inline_decode(xdr, 4);
4937 if (unlikely(!p))
4938 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004939 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004940 p = xdr_inline_decode(xdr, bmlen << 2);
4941 if (likely(p))
4942 return 0;
4943out_overflow:
4944 print_overflow_msg(__func__, xdr);
4945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946}
4947
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004948static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949{
Al Viro8687b632006-10-19 23:28:48 -07004950 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 uint32_t opnum;
4952 int32_t nfserr;
4953
Benny Halevyc0eae662009-08-14 17:20:14 +03004954 p = xdr_inline_decode(xdr, 8);
4955 if (unlikely(!p))
4956 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004957 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004959 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004960 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 return -EIO;
4962 }
Benny Halevycccddf42009-08-14 17:20:19 +03004963 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004965 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4966 if (unlikely(!p))
4967 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004968 p = xdr_decode_hyper(p, &res->clientid);
4969 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 } else if (nfserr == NFSERR_CLID_INUSE) {
4971 uint32_t len;
4972
4973 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004974 p = xdr_inline_decode(xdr, 4);
4975 if (unlikely(!p))
4976 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004977 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004978 p = xdr_inline_decode(xdr, len);
4979 if (unlikely(!p))
4980 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981
4982 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004983 p = xdr_inline_decode(xdr, 4);
4984 if (unlikely(!p))
4985 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004986 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004987 p = xdr_inline_decode(xdr, len);
4988 if (unlikely(!p))
4989 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 return -NFSERR_CLID_INUSE;
4991 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004992 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
4994 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004995out_overflow:
4996 print_overflow_msg(__func__, xdr);
4997 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998}
4999
5000static int decode_setclientid_confirm(struct xdr_stream *xdr)
5001{
5002 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5003}
5004
5005static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5006{
Al Viro8687b632006-10-19 23:28:48 -07005007 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 int status;
5009
5010 status = decode_op_hdr(xdr, OP_WRITE);
5011 if (status)
5012 return status;
5013
Benny Halevyc0eae662009-08-14 17:20:14 +03005014 p = xdr_inline_decode(xdr, 16);
5015 if (unlikely(!p))
5016 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005017 res->count = be32_to_cpup(p++);
5018 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005019 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005021out_overflow:
5022 print_overflow_msg(__func__, xdr);
5023 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024}
5025
5026static int decode_delegreturn(struct xdr_stream *xdr)
5027{
5028 return decode_op_hdr(xdr, OP_DELEGRETURN);
5029}
5030
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005031static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5032{
5033 __be32 *p;
5034
5035 p = xdr_inline_decode(xdr, 4);
5036 if (unlikely(!p))
5037 goto out_overflow;
5038 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5039 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5040 goto out_err;
5041
5042 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5043 if (unlikely(!p))
5044 goto out_overflow;
5045 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5046
5047 p = xdr_inline_decode(xdr, 8);
5048 if (unlikely(!p))
5049 goto out_overflow;
5050 flavor->gss.qop4 = be32_to_cpup(p++);
5051 flavor->gss.service = be32_to_cpup(p);
5052
5053 return 0;
5054
5055out_overflow:
5056 print_overflow_msg(__func__, xdr);
5057 return -EIO;
5058out_err:
5059 return -EINVAL;
5060}
5061
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005062static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005063{
5064 struct nfs4_secinfo_flavor *sec_flavor;
5065 int status;
5066 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005067 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005068
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005069 p = xdr_inline_decode(xdr, 4);
5070 if (unlikely(!p))
5071 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005072
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005073 res->flavors->num_flavors = 0;
5074 num_flavors = be32_to_cpup(p);
5075
5076 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005077 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005078 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005079 break;
5080
5081 p = xdr_inline_decode(xdr, 4);
5082 if (unlikely(!p))
5083 goto out_overflow;
5084 sec_flavor->flavor = be32_to_cpup(p);
5085
5086 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005087 status = decode_secinfo_gss(xdr, sec_flavor);
5088 if (status)
5089 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005090 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005091 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005092 }
5093
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005094 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005095out:
5096 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005097out_overflow:
5098 print_overflow_msg(__func__, xdr);
5099 return -EIO;
5100}
5101
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005102static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5103{
5104 int status = decode_op_hdr(xdr, OP_SECINFO);
5105 if (status)
5106 return status;
5107 return decode_secinfo_common(xdr, res);
5108}
5109
Benny Halevy99fe60d2009-04-01 09:22:29 -04005110#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005111static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5112{
5113 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5114 if (status)
5115 return status;
5116 return decode_secinfo_common(xdr, res);
5117}
5118
Benny Halevy99fe60d2009-04-01 09:22:29 -04005119static int decode_exchange_id(struct xdr_stream *xdr,
5120 struct nfs41_exchange_id_res *res)
5121{
5122 __be32 *p;
5123 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005124 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005125 int status;
5126 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005127 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005128
5129 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5130 if (status)
5131 return status;
5132
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, 8);
5134 if (unlikely(!p))
5135 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005136 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005137 p = xdr_inline_decode(xdr, 12);
5138 if (unlikely(!p))
5139 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005140 clp->cl_seqid = be32_to_cpup(p++);
5141 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005142
5143 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005144 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005145 if (dummy != SP4_NONE)
5146 return -EIO;
5147
5148 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005149 p = xdr_inline_decode(xdr, 8);
5150 if (unlikely(!p))
5151 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005152
5153 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005154 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5155 if (unlikely(status))
5156 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005157
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005158 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005159 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5160 if (unlikely(status))
5161 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005162
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005163 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5164 return -EIO;
5165
5166 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5167 res->server_scope->server_scope_sz = dummy;
5168
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005169 /* Implementation Id */
5170 p = xdr_inline_decode(xdr, 4);
5171 if (unlikely(!p))
5172 goto out_overflow;
5173 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005174
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005175 if (impl_id_count) {
5176 /* nii_domain */
5177 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5178 if (unlikely(status))
5179 return status;
5180 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5181 return -EIO;
5182 memcpy(res->impl_id->domain, dummy_str, dummy);
5183
5184 /* nii_name */
5185 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5186 if (unlikely(status))
5187 return status;
5188 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5189 return -EIO;
5190 memcpy(res->impl_id->name, dummy_str, dummy);
5191
5192 /* nii_date */
5193 p = xdr_inline_decode(xdr, 12);
5194 if (unlikely(!p))
5195 goto out_overflow;
5196 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5197 res->impl_id->date.nseconds = be32_to_cpup(p);
5198
5199 /* if there's more than one entry, ignore the rest */
5200 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005201 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005202out_overflow:
5203 print_overflow_msg(__func__, xdr);
5204 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005205}
Andy Adamsonfc931582009-04-01 09:22:31 -04005206
5207static int decode_chan_attrs(struct xdr_stream *xdr,
5208 struct nfs4_channel_attrs *attrs)
5209{
5210 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005211 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005212
Benny Halevyc0eae662009-08-14 17:20:14 +03005213 p = xdr_inline_decode(xdr, 28);
5214 if (unlikely(!p))
5215 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005216 val = be32_to_cpup(p++); /* headerpadsz */
5217 if (val)
5218 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005219 attrs->max_rqst_sz = be32_to_cpup(p++);
5220 attrs->max_resp_sz = be32_to_cpup(p++);
5221 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5222 attrs->max_ops = be32_to_cpup(p++);
5223 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005224 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005225 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005226 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5227 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005228 return -EINVAL;
5229 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005230 if (nr_attrs == 1) {
5231 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5232 if (unlikely(!p))
5233 goto out_overflow;
5234 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005235 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005236out_overflow:
5237 print_overflow_msg(__func__, xdr);
5238 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005239}
5240
Benny Halevye78291e2009-08-14 17:20:00 +03005241static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5242{
5243 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005244}
5245
5246static int decode_create_session(struct xdr_stream *xdr,
5247 struct nfs41_create_session_res *res)
5248{
5249 __be32 *p;
5250 int status;
5251 struct nfs_client *clp = res->client;
5252 struct nfs4_session *session = clp->cl_session;
5253
5254 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005255 if (!status)
5256 status = decode_sessionid(xdr, &session->sess_id);
5257 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005258 return status;
5259
Andy Adamsonfc931582009-04-01 09:22:31 -04005260 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005261 p = xdr_inline_decode(xdr, 8);
5262 if (unlikely(!p))
5263 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005264 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005265 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005266
5267 /* Channel attributes */
5268 status = decode_chan_attrs(xdr, &session->fc_attrs);
5269 if (!status)
5270 status = decode_chan_attrs(xdr, &session->bc_attrs);
5271 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005272out_overflow:
5273 print_overflow_msg(__func__, xdr);
5274 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005275}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005276
5277static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5278{
5279 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5280}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005281
5282static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5283{
5284 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5285}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005286#endif /* CONFIG_NFS_V4_1 */
5287
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005288static int decode_sequence(struct xdr_stream *xdr,
5289 struct nfs4_sequence_res *res,
5290 struct rpc_rqst *rqstp)
5291{
5292#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005293 struct nfs4_sessionid id;
5294 u32 dummy;
5295 int status;
5296 __be32 *p;
5297
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005298 if (!res->sr_session)
5299 return 0;
5300
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005301 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005302 if (!status)
5303 status = decode_sessionid(xdr, &id);
5304 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005305 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005306
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005307 /*
5308 * If the server returns different values for sessionID, slotID or
5309 * sequence number, the server is looney tunes.
5310 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005311 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005312
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005313 if (memcmp(id.data, res->sr_session->sess_id.data,
5314 NFS4_MAX_SESSIONID_LEN)) {
5315 dprintk("%s Invalid session id\n", __func__);
5316 goto out_err;
5317 }
Benny Halevye78291e2009-08-14 17:20:00 +03005318
Benny Halevyc0eae662009-08-14 17:20:14 +03005319 p = xdr_inline_decode(xdr, 20);
5320 if (unlikely(!p))
5321 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005322
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005323 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005324 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005325 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005326 dprintk("%s Invalid sequence number\n", __func__);
5327 goto out_err;
5328 }
5329 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005330 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005331 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005332 dprintk("%s Invalid slot id\n", __func__);
5333 goto out_err;
5334 }
5335 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005336 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005337 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005338 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005339 /* result flags */
5340 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005341 status = 0;
5342out_err:
5343 res->sr_status = status;
5344 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005345out_overflow:
5346 print_overflow_msg(__func__, xdr);
5347 status = -EIO;
5348 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005349#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005350 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005351#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005352}
5353
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005354#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005355/*
5356 * TODO: Need to handle case when EOF != true;
5357 */
5358static int decode_getdevicelist(struct xdr_stream *xdr,
5359 struct pnfs_devicelist *res)
5360{
5361 __be32 *p;
5362 int status, i;
5363 struct nfs_writeverf verftemp;
5364
5365 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5366 if (status)
5367 return status;
5368
5369 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5370 if (unlikely(!p))
5371 goto out_overflow;
5372
5373 /* TODO: Skip cookie for now */
5374 p += 2;
5375
5376 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005377 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005378
5379 res->num_devs = be32_to_cpup(p);
5380
5381 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5382
5383 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005384 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005385 __func__, res->num_devs);
5386 return -EIO;
5387 }
5388
5389 p = xdr_inline_decode(xdr,
5390 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5391 if (unlikely(!p))
5392 goto out_overflow;
5393 for (i = 0; i < res->num_devs; i++)
5394 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5395 NFS4_DEVICEID4_SIZE);
5396 res->eof = be32_to_cpup(p);
5397 return 0;
5398out_overflow:
5399 print_overflow_msg(__func__, xdr);
5400 return -EIO;
5401}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005402
5403static int decode_getdeviceinfo(struct xdr_stream *xdr,
5404 struct pnfs_device *pdev)
5405{
5406 __be32 *p;
5407 uint32_t len, type;
5408 int status;
5409
5410 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5411 if (status) {
5412 if (status == -ETOOSMALL) {
5413 p = xdr_inline_decode(xdr, 4);
5414 if (unlikely(!p))
5415 goto out_overflow;
5416 pdev->mincount = be32_to_cpup(p);
5417 dprintk("%s: Min count too small. mincnt = %u\n",
5418 __func__, pdev->mincount);
5419 }
5420 return status;
5421 }
5422
5423 p = xdr_inline_decode(xdr, 8);
5424 if (unlikely(!p))
5425 goto out_overflow;
5426 type = be32_to_cpup(p++);
5427 if (type != pdev->layout_type) {
5428 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5429 __func__, pdev->layout_type, type);
5430 return -EINVAL;
5431 }
5432 /*
5433 * Get the length of the opaque device_addr4. xdr_read_pages places
5434 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5435 * and places the remaining xdr data in xdr_buf->tail
5436 */
5437 pdev->mincount = be32_to_cpup(p);
5438 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5439
5440 /* Parse notification bitmap, verifying that it is zero. */
5441 p = xdr_inline_decode(xdr, 4);
5442 if (unlikely(!p))
5443 goto out_overflow;
5444 len = be32_to_cpup(p);
5445 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005446 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005447
5448 p = xdr_inline_decode(xdr, 4 * len);
5449 if (unlikely(!p))
5450 goto out_overflow;
5451 for (i = 0; i < len; i++, p++) {
5452 if (be32_to_cpup(p)) {
5453 dprintk("%s: notifications not supported\n",
5454 __func__);
5455 return -EIO;
5456 }
5457 }
5458 }
5459 return 0;
5460out_overflow:
5461 print_overflow_msg(__func__, xdr);
5462 return -EIO;
5463}
5464
5465static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5466 struct nfs4_layoutget_res *res)
5467{
5468 __be32 *p;
5469 int status;
5470 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005471 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5472 struct kvec *iov = rcvbuf->head;
5473 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005474
5475 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5476 if (status)
5477 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005478 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005479 if (unlikely(!p))
5480 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005481 res->return_on_close = be32_to_cpup(p);
5482 decode_stateid(xdr, &res->stateid);
5483 p = xdr_inline_decode(xdr, 4);
5484 if (unlikely(!p))
5485 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005486 layout_count = be32_to_cpup(p);
5487 if (!layout_count) {
5488 dprintk("%s: server responded with empty layout array\n",
5489 __func__);
5490 return -EINVAL;
5491 }
5492
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005493 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005494 if (unlikely(!p))
5495 goto out_overflow;
5496 p = xdr_decode_hyper(p, &res->range.offset);
5497 p = xdr_decode_hyper(p, &res->range.length);
5498 res->range.iomode = be32_to_cpup(p++);
5499 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005500 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005501
5502 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5503 __func__,
5504 (unsigned long)res->range.offset,
5505 (unsigned long)res->range.length,
5506 res->range.iomode,
5507 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005508 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005509
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005510 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5511 recvd = req->rq_rcv_buf.len - hdrlen;
5512 if (res->layoutp->len > recvd) {
5513 dprintk("NFS: server cheating in layoutget reply: "
5514 "layout len %u > recvd %u\n",
5515 res->layoutp->len, recvd);
5516 return -EINVAL;
5517 }
5518
5519 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005520
5521 if (layout_count > 1) {
5522 /* We only handle a length one array at the moment. Any
5523 * further entries are just ignored. Note that this means
5524 * the client may see a response that is less than the
5525 * minimum it requested.
5526 */
5527 dprintk("%s: server responded with %d layouts, dropping tail\n",
5528 __func__, layout_count);
5529 }
5530
5531 return 0;
5532out_overflow:
5533 print_overflow_msg(__func__, xdr);
5534 return -EIO;
5535}
Andy Adamson863a3c62011-03-23 13:27:54 +00005536
Benny Halevycbe82602011-05-22 19:52:37 +03005537static int decode_layoutreturn(struct xdr_stream *xdr,
5538 struct nfs4_layoutreturn_res *res)
5539{
5540 __be32 *p;
5541 int status;
5542
5543 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5544 if (status)
5545 return status;
5546 p = xdr_inline_decode(xdr, 4);
5547 if (unlikely(!p))
5548 goto out_overflow;
5549 res->lrs_present = be32_to_cpup(p);
5550 if (res->lrs_present)
5551 status = decode_stateid(xdr, &res->stateid);
5552 return status;
5553out_overflow:
5554 print_overflow_msg(__func__, xdr);
5555 return -EIO;
5556}
5557
Andy Adamson863a3c62011-03-23 13:27:54 +00005558static int decode_layoutcommit(struct xdr_stream *xdr,
5559 struct rpc_rqst *req,
5560 struct nfs4_layoutcommit_res *res)
5561{
5562 __be32 *p;
5563 __u32 sizechanged;
5564 int status;
5565
5566 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005567 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005568 if (status)
5569 return status;
5570
5571 p = xdr_inline_decode(xdr, 4);
5572 if (unlikely(!p))
5573 goto out_overflow;
5574 sizechanged = be32_to_cpup(p);
5575
5576 if (sizechanged) {
5577 /* throw away new size */
5578 p = xdr_inline_decode(xdr, 8);
5579 if (unlikely(!p))
5580 goto out_overflow;
5581 }
5582 return 0;
5583out_overflow:
5584 print_overflow_msg(__func__, xdr);
5585 return -EIO;
5586}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005587
5588static int decode_test_stateid(struct xdr_stream *xdr,
5589 struct nfs41_test_stateid_res *res)
5590{
5591 __be32 *p;
5592 int status;
5593 int num_res;
5594
5595 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5596 if (status)
5597 return status;
5598
5599 p = xdr_inline_decode(xdr, 4);
5600 if (unlikely(!p))
5601 goto out_overflow;
5602 num_res = be32_to_cpup(p++);
5603 if (num_res != 1)
5604 goto out;
5605
5606 p = xdr_inline_decode(xdr, 4);
5607 if (unlikely(!p))
5608 goto out_overflow;
5609 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005610
5611 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005612out_overflow:
5613 print_overflow_msg(__func__, xdr);
5614out:
5615 return -EIO;
5616}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005617
5618static int decode_free_stateid(struct xdr_stream *xdr,
5619 struct nfs41_free_stateid_res *res)
5620{
5621 __be32 *p;
5622 int status;
5623
5624 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5625 if (status)
5626 return status;
5627
5628 p = xdr_inline_decode(xdr, 4);
5629 if (unlikely(!p))
5630 goto out_overflow;
5631 res->status = be32_to_cpup(p++);
5632 return res->status;
5633out_overflow:
5634 print_overflow_msg(__func__, xdr);
5635 return -EIO;
5636}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005637#endif /* CONFIG_NFS_V4_1 */
5638
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639/*
Benny Halevy49c25592008-12-23 16:06:16 -05005640 * END OF "GENERIC" DECODE ROUTINES.
5641 */
5642
5643/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644 * Decode OPEN_DOWNGRADE response
5645 */
Chuck Leverbf269552010-12-14 14:59:29 +00005646static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5647 struct xdr_stream *xdr,
5648 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649{
Andy Adamson05d564f2008-12-23 16:06:15 -05005650 struct compound_hdr hdr;
5651 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652
Chuck Leverbf269552010-12-14 14:59:29 +00005653 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005654 if (status)
5655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005656 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005657 if (status)
5658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005659 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005660 if (status)
5661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005662 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005663 if (status != 0)
5664 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005665 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005667 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668}
5669
5670/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671 * Decode ACCESS response
5672 */
Chuck Leverbf269552010-12-14 14:59:29 +00005673static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5674 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005675{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676 struct compound_hdr hdr;
5677 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005678
Chuck Leverbf269552010-12-14 14:59:29 +00005679 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005680 if (status)
5681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005682 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005683 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005685 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005686 if (status != 0)
5687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005688 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005689 if (status != 0)
5690 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005691 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692out:
5693 return status;
5694}
5695
5696/*
5697 * Decode LOOKUP response
5698 */
Chuck Leverbf269552010-12-14 14:59:29 +00005699static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5700 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702 struct compound_hdr hdr;
5703 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005704
Chuck Leverbf269552010-12-14 14:59:29 +00005705 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005706 if (status)
5707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005708 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005709 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005711 status = decode_putfh(xdr);
5712 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005714 status = decode_lookup(xdr);
5715 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005717 status = decode_getfh(xdr, res->fh);
5718 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005720 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721out:
5722 return status;
5723}
5724
5725/*
5726 * Decode LOOKUP_ROOT response
5727 */
Chuck Leverbf269552010-12-14 14:59:29 +00005728static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5729 struct xdr_stream *xdr,
5730 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732 struct compound_hdr hdr;
5733 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005734
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005736 if (status)
5737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005739 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 status = decode_putrootfh(xdr);
5742 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005744 status = decode_getfh(xdr, res->fh);
5745 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005746 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747out:
5748 return status;
5749}
5750
5751/*
5752 * Decode REMOVE response
5753 */
Chuck Leverbf269552010-12-14 14:59:29 +00005754static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5755 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005756{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757 struct compound_hdr hdr;
5758 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005759
Chuck Leverbf269552010-12-14 14:59:29 +00005760 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005761 if (status)
5762 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005763 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005764 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005766 status = decode_putfh(xdr);
5767 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005768 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005769 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770out:
5771 return status;
5772}
5773
5774/*
5775 * Decode RENAME response
5776 */
Chuck Leverbf269552010-12-14 14:59:29 +00005777static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5778 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 struct compound_hdr hdr;
5781 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005782
Chuck Leverbf269552010-12-14 14:59:29 +00005783 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005784 if (status)
5785 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005786 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005787 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005789 status = decode_putfh(xdr);
5790 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005792 status = decode_savefh(xdr);
5793 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_putfh(xdr);
5796 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005798 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799out:
5800 return status;
5801}
5802
5803/*
5804 * Decode LINK response
5805 */
Chuck Leverbf269552010-12-14 14:59:29 +00005806static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5807 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 struct compound_hdr hdr;
5810 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005811
Chuck Leverbf269552010-12-14 14:59:29 +00005812 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005813 if (status)
5814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005815 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005816 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_putfh(xdr);
5819 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005820 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005821 status = decode_savefh(xdr);
5822 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_putfh(xdr);
5825 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005827 status = decode_link(xdr, &res->cinfo);
5828 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005829 goto out;
5830 /*
5831 * Note order: OP_LINK leaves the directory as the current
5832 * filehandle.
5833 */
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_restorefh(xdr);
5835 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005836 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005837 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838out:
5839 return status;
5840}
5841
5842/*
5843 * Decode CREATE response
5844 */
Chuck Leverbf269552010-12-14 14:59:29 +00005845static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5846 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 struct compound_hdr hdr;
5849 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005850
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005852 if (status)
5853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005855 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005857 status = decode_putfh(xdr);
5858 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005860 status = decode_create(xdr, &res->dir_cinfo);
5861 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_getfh(xdr, res->fh);
5864 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04005866 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867out:
5868 return status;
5869}
5870
5871/*
5872 * Decode SYMLINK response
5873 */
Chuck Leverbf269552010-12-14 14:59:29 +00005874static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5875 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876{
Chuck Leverbf269552010-12-14 14:59:29 +00005877 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878}
5879
5880/*
5881 * Decode GETATTR response
5882 */
Chuck Leverbf269552010-12-14 14:59:29 +00005883static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5884 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886 struct compound_hdr hdr;
5887 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005888
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 if (status)
5891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005893 if (status)
5894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896 if (status)
5897 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005898 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899out:
5900 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901}
5902
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005903/*
5904 * Encode an SETACL request
5905 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005906static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5907 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005908{
Andy Adamson05d564f2008-12-23 16:06:15 -05005909 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005911 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005912
Chuck Lever9f06c712010-12-14 14:59:18 +00005913 encode_compound_hdr(xdr, req, &hdr);
5914 encode_sequence(xdr, &args->seq_args, &hdr);
5915 encode_putfh(xdr, args->fh, &hdr);
5916 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005917 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005918}
Andy Adamson05d564f2008-12-23 16:06:15 -05005919
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005920/*
5921 * Decode SETACL response
5922 */
5923static int
Chuck Leverbf269552010-12-14 14:59:29 +00005924nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005925 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005926{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005927 struct compound_hdr hdr;
5928 int status;
5929
Chuck Leverbf269552010-12-14 14:59:29 +00005930 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005931 if (status)
5932 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005933 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005934 if (status)
5935 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005936 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005937 if (status)
5938 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005939 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005940out:
5941 return status;
5942}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943
5944/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005945 * Decode GETACL response
5946 */
5947static int
Chuck Leverbf269552010-12-14 14:59:29 +00005948nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005949 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005950{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005951 struct compound_hdr hdr;
5952 int status;
5953
Trond Myklebust331818f2012-02-03 18:30:53 -05005954 if (res->acl_scratch != NULL) {
5955 void *p = page_address(res->acl_scratch);
5956 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5957 }
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005959 if (status)
5960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005962 if (status)
5963 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005964 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005965 if (status)
5966 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005967 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005968
5969out:
5970 return status;
5971}
5972
5973/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 * Decode CLOSE response
5975 */
Chuck Leverbf269552010-12-14 14:59:29 +00005976static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5977 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978{
Andy Adamson05d564f2008-12-23 16:06:15 -05005979 struct compound_hdr hdr;
5980 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005983 if (status)
5984 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005986 if (status)
5987 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005989 if (status)
5990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005992 if (status != 0)
5993 goto out;
5994 /*
5995 * Note: Server may do delete on close for this file
5996 * in which case the getattr call will fail with
5997 * an ESTALE error. Shouldn't be a problem,
5998 * though, since fattr->valid will remain unset.
5999 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006000 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006002 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003}
6004
6005/*
6006 * Decode OPEN response
6007 */
Chuck Leverbf269552010-12-14 14:59:29 +00006008static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6009 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010{
Andy Adamson05d564f2008-12-23 16:06:15 -05006011 struct compound_hdr hdr;
6012 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006015 if (status)
6016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006018 if (status)
6019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006021 if (status)
6022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006024 if (status)
6025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006028 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006029out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006030 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031}
6032
6033/*
6034 * Decode OPEN_CONFIRM response
6035 */
Chuck Leverbf269552010-12-14 14:59:29 +00006036static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6037 struct xdr_stream *xdr,
6038 struct nfs_open_confirmres *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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006044 if (status)
6045 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006047 if (status)
6048 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006051 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052}
6053
6054/*
6055 * Decode OPEN response
6056 */
Chuck Leverbf269552010-12-14 14:59:29 +00006057static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6058 struct xdr_stream *xdr,
6059 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060{
Andy Adamson05d564f2008-12-23 16:06:15 -05006061 struct compound_hdr hdr;
6062 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006065 if (status)
6066 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006068 if (status)
6069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006070 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006071 if (status)
6072 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006073 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006074 if (status)
6075 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006076 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006078 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079}
6080
6081/*
6082 * Decode SETATTR response
6083 */
Chuck Leverbf269552010-12-14 14:59:29 +00006084static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6085 struct xdr_stream *xdr,
6086 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087{
Andy Adamson05d564f2008-12-23 16:06:15 -05006088 struct compound_hdr hdr;
6089 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006092 if (status)
6093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006095 if (status)
6096 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006097 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006098 if (status)
6099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006101 if (status)
6102 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006103 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006105 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106}
6107
6108/*
6109 * Decode LOCK response
6110 */
Chuck Leverbf269552010-12-14 14:59:29 +00006111static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6112 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 struct compound_hdr hdr;
6115 int status;
6116
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 if (status)
6119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006121 if (status)
6122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 if (status)
6125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127out:
6128 return status;
6129}
6130
6131/*
6132 * Decode LOCKT response
6133 */
Chuck Leverbf269552010-12-14 14:59:29 +00006134static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6135 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 struct compound_hdr hdr;
6138 int status;
6139
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 if (status)
6142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006144 if (status)
6145 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 if (status)
6148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150out:
6151 return status;
6152}
6153
6154/*
6155 * Decode LOCKU response
6156 */
Chuck Leverbf269552010-12-14 14:59:29 +00006157static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6158 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 struct compound_hdr hdr;
6161 int status;
6162
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 if (status)
6165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173out:
6174 return status;
6175}
6176
Chuck Leverbf269552010-12-14 14:59:29 +00006177static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6178 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006179{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006180 struct compound_hdr hdr;
6181 int status;
6182
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006184 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006186 return status;
6187}
6188
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189/*
6190 * Decode READLINK response
6191 */
Chuck Leverbf269552010-12-14 14:59:29 +00006192static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6193 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006194 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 struct compound_hdr hdr;
6197 int status;
6198
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 if (status)
6201 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006202 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006203 if (status)
6204 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 if (status)
6207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209out:
6210 return status;
6211}
6212
6213/*
6214 * Decode READDIR response
6215 */
Chuck Leverbf269552010-12-14 14:59:29 +00006216static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6217 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 struct compound_hdr hdr;
6220 int status;
6221
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223 if (status)
6224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006226 if (status)
6227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 if (status)
6230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232out:
6233 return status;
6234}
6235
6236/*
6237 * Decode Read response
6238 */
Chuck Leverbf269552010-12-14 14:59:29 +00006239static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6240 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 struct compound_hdr hdr;
6243 int status;
6244
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 if (status)
6247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006248 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006249 if (status)
6250 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 if (status)
6253 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255 if (!status)
6256 status = res->count;
6257out:
6258 return status;
6259}
6260
6261/*
6262 * Decode WRITE response
6263 */
Chuck Leverbf269552010-12-14 14:59:29 +00006264static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6265 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 struct compound_hdr hdr;
6268 int status;
6269
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 if (status)
6272 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006274 if (status)
6275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 if (status)
6278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006280 if (status)
6281 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006282 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006283 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 if (!status)
6285 status = res->count;
6286out:
6287 return status;
6288}
6289
6290/*
6291 * Decode COMMIT response
6292 */
Chuck Leverbf269552010-12-14 14:59:29 +00006293static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006294 struct nfs_commitres *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_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006309 if (status)
6310 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006311 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006312 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313out:
6314 return status;
6315}
6316
6317/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006318 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 */
Chuck Leverbf269552010-12-14 14:59:29 +00006320static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006321 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 struct compound_hdr hdr;
6324 int status;
6325
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006329 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333 return status;
6334}
6335
6336/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006337 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 */
Chuck Leverbf269552010-12-14 14:59:29 +00006339static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006340 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 struct compound_hdr hdr;
6343 int status;
6344
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006348 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352 return status;
6353}
6354
6355/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006356 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357 */
Chuck Leverbf269552010-12-14 14:59:29 +00006358static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006359 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 struct compound_hdr hdr;
6362 int status;
6363
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006367 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371 return status;
6372}
6373
6374/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006375 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376 */
Chuck Leverbf269552010-12-14 14:59:29 +00006377static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6378 struct xdr_stream *xdr,
6379 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 struct compound_hdr hdr;
6382 int status;
6383
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006385 if (status)
6386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006388 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_putfh(xdr);
6391 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394out:
6395 return status;
6396}
6397
6398/*
6399 * Decode RENEW response
6400 */
Chuck Leverbf269552010-12-14 14:59:29 +00006401static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6402 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 struct compound_hdr hdr;
6405 int status;
6406
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 return status;
6411}
6412
6413/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006414 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 */
Chuck Leverbf269552010-12-14 14:59:29 +00006416static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6417 struct xdr_stream *xdr,
6418 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 struct compound_hdr hdr;
6421 int status;
6422
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 return status;
6427}
6428
6429/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006430 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 */
Chuck Leverbf269552010-12-14 14:59:29 +00006432static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6433 struct xdr_stream *xdr,
6434 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 struct compound_hdr hdr;
6437 int status;
6438
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 return status;
6447}
6448
6449/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006450 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451 */
Chuck Leverbf269552010-12-14 14:59:29 +00006452static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6453 struct xdr_stream *xdr,
6454 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 struct compound_hdr hdr;
6457 int status;
6458
Chuck Leverbf269552010-12-14 14:59:29 +00006459 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006460 if (status)
6461 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006463 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006466 if (status != 0)
6467 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006468 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006469 if (status != 0)
6470 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006471 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006472out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 return status;
6474}
6475
Trond Myklebust683b57b2006-06-09 09:34:22 -04006476/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006477 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006478 */
Chuck Leverbf269552010-12-14 14:59:29 +00006479static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6480 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006481 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006482{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006483 struct compound_hdr hdr;
6484 int status;
6485
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006487 if (status)
6488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006490 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_putfh(xdr);
6493 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_lookup(xdr);
6496 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006498 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006499 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6500 NULL, res->fs_locations,
6501 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006502out:
6503 return status;
6504}
6505
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006506/*
6507 * Decode SECINFO response
6508 */
6509static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6510 struct xdr_stream *xdr,
6511 struct nfs4_secinfo_res *res)
6512{
6513 struct compound_hdr hdr;
6514 int status;
6515
6516 status = decode_compound_hdr(xdr, &hdr);
6517 if (status)
6518 goto out;
6519 status = decode_sequence(xdr, &res->seq_res, rqstp);
6520 if (status)
6521 goto out;
6522 status = decode_putfh(xdr);
6523 if (status)
6524 goto out;
6525 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006526out:
6527 return status;
6528}
6529
Benny Halevy99fe60d2009-04-01 09:22:29 -04006530#if defined(CONFIG_NFS_V4_1)
6531/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006532 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006533 */
Chuck Leverbf269552010-12-14 14:59:29 +00006534static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6535 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006536 void *res)
6537{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006538 struct compound_hdr hdr;
6539 int status;
6540
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006542 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006544 return status;
6545}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006546
6547/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006548 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006549 */
Chuck Leverbf269552010-12-14 14:59:29 +00006550static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6551 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006552 struct nfs41_create_session_res *res)
6553{
Andy Adamsonfc931582009-04-01 09:22:31 -04006554 struct compound_hdr hdr;
6555 int status;
6556
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006558 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006559 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006560 return status;
6561}
6562
6563/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006564 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006565 */
Chuck Leverbf269552010-12-14 14:59:29 +00006566static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6567 struct xdr_stream *xdr,
6568 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006569{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006570 struct compound_hdr hdr;
6571 int status;
6572
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006574 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006576 return status;
6577}
6578
6579/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006580 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006581 */
Chuck Leverbf269552010-12-14 14:59:29 +00006582static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6583 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006584 struct nfs4_sequence_res *res)
6585{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006586 struct compound_hdr hdr;
6587 int status;
6588
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006590 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006592 return status;
6593}
6594
6595/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006596 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006597 */
Chuck Leverbf269552010-12-14 14:59:29 +00006598static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6599 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006600 struct nfs4_get_lease_time_res *res)
6601{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006602 struct compound_hdr hdr;
6603 int status;
6604
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006606 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006608 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006610 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006612 return status;
6613}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006614
6615/*
6616 * Decode RECLAIM_COMPLETE response
6617 */
Chuck Leverbf269552010-12-14 14:59:29 +00006618static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6619 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006620 struct nfs41_reclaim_complete_res *res)
6621{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006622 struct compound_hdr hdr;
6623 int status;
6624
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006626 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006628 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006630 return status;
6631}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006632
6633/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006634 * Decode GETDEVICELIST response
6635 */
6636static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6637 struct xdr_stream *xdr,
6638 struct nfs4_getdevicelist_res *res)
6639{
6640 struct compound_hdr hdr;
6641 int status;
6642
6643 dprintk("encoding getdevicelist!\n");
6644
6645 status = decode_compound_hdr(xdr, &hdr);
6646 if (status != 0)
6647 goto out;
6648 status = decode_sequence(xdr, &res->seq_res, rqstp);
6649 if (status != 0)
6650 goto out;
6651 status = decode_putfh(xdr);
6652 if (status != 0)
6653 goto out;
6654 status = decode_getdevicelist(xdr, res->devlist);
6655out:
6656 return status;
6657}
6658
6659/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006660 * Decode GETDEVINFO response
6661 */
Chuck Leverbf269552010-12-14 14:59:29 +00006662static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6663 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006664 struct nfs4_getdeviceinfo_res *res)
6665{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006666 struct compound_hdr hdr;
6667 int status;
6668
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006670 if (status != 0)
6671 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006672 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006673 if (status != 0)
6674 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006676out:
6677 return status;
6678}
6679
6680/*
6681 * Decode LAYOUTGET response
6682 */
Chuck Leverbf269552010-12-14 14:59:29 +00006683static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6684 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006685 struct nfs4_layoutget_res *res)
6686{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006687 struct compound_hdr hdr;
6688 int status;
6689
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006691 if (status)
6692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006694 if (status)
6695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006697 if (status)
6698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006700out:
6701 return status;
6702}
Andy Adamson863a3c62011-03-23 13:27:54 +00006703
6704/*
Benny Halevycbe82602011-05-22 19:52:37 +03006705 * Decode LAYOUTRETURN response
6706 */
6707static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6708 struct xdr_stream *xdr,
6709 struct nfs4_layoutreturn_res *res)
6710{
6711 struct compound_hdr hdr;
6712 int status;
6713
6714 status = decode_compound_hdr(xdr, &hdr);
6715 if (status)
6716 goto out;
6717 status = decode_sequence(xdr, &res->seq_res, rqstp);
6718 if (status)
6719 goto out;
6720 status = decode_putfh(xdr);
6721 if (status)
6722 goto out;
6723 status = decode_layoutreturn(xdr, res);
6724out:
6725 return status;
6726}
6727
6728/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006729 * Decode LAYOUTCOMMIT response
6730 */
6731static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6732 struct xdr_stream *xdr,
6733 struct nfs4_layoutcommit_res *res)
6734{
6735 struct compound_hdr hdr;
6736 int status;
6737
6738 status = decode_compound_hdr(xdr, &hdr);
6739 if (status)
6740 goto out;
6741 status = decode_sequence(xdr, &res->seq_res, rqstp);
6742 if (status)
6743 goto out;
6744 status = decode_putfh(xdr);
6745 if (status)
6746 goto out;
6747 status = decode_layoutcommit(xdr, rqstp, res);
6748 if (status)
6749 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006750 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006751out:
6752 return status;
6753}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006754
6755/*
6756 * Decode SECINFO_NO_NAME response
6757 */
6758static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6759 struct xdr_stream *xdr,
6760 struct nfs4_secinfo_res *res)
6761{
6762 struct compound_hdr hdr;
6763 int status;
6764
6765 status = decode_compound_hdr(xdr, &hdr);
6766 if (status)
6767 goto out;
6768 status = decode_sequence(xdr, &res->seq_res, rqstp);
6769 if (status)
6770 goto out;
6771 status = decode_putrootfh(xdr);
6772 if (status)
6773 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006774 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006775out:
6776 return status;
6777}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006778
6779/*
6780 * Decode TEST_STATEID response
6781 */
6782static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6783 struct xdr_stream *xdr,
6784 struct nfs41_test_stateid_res *res)
6785{
6786 struct compound_hdr hdr;
6787 int status;
6788
6789 status = decode_compound_hdr(xdr, &hdr);
6790 if (status)
6791 goto out;
6792 status = decode_sequence(xdr, &res->seq_res, rqstp);
6793 if (status)
6794 goto out;
6795 status = decode_test_stateid(xdr, res);
6796out:
6797 return status;
6798}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006799
6800/*
6801 * Decode FREE_STATEID response
6802 */
6803static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6804 struct xdr_stream *xdr,
6805 struct nfs41_free_stateid_res *res)
6806{
6807 struct compound_hdr hdr;
6808 int status;
6809
6810 status = decode_compound_hdr(xdr, &hdr);
6811 if (status)
6812 goto out;
6813 status = decode_sequence(xdr, &res->seq_res, rqstp);
6814 if (status)
6815 goto out;
6816 status = decode_free_stateid(xdr, res);
6817out:
6818 return status;
6819}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006820#endif /* CONFIG_NFS_V4_1 */
6821
Chuck Lever573c4e12010-12-14 14:58:11 +00006822/**
6823 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6824 * the local page cache.
6825 * @xdr: XDR stream where entry resides
6826 * @entry: buffer to fill in with entry data
6827 * @plus: boolean indicating whether this should be a readdirplus entry
6828 *
6829 * Returns zero if successful, otherwise a negative errno value is
6830 * returned.
6831 *
6832 * This function is not invoked during READDIR reply decoding, but
6833 * rather whenever an application invokes the getdents(2) system call
6834 * on a directory already in our cache.
6835 */
6836int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6837 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838{
Fred Isamandae100c2011-07-30 20:52:37 -04006839 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006841 __be32 *p = xdr_inline_decode(xdr, 4);
6842 if (unlikely(!p))
6843 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006844 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006845 p = xdr_inline_decode(xdr, 4);
6846 if (unlikely(!p))
6847 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006848 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006849 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006851 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006852 }
6853
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006854 p = xdr_inline_decode(xdr, 12);
6855 if (unlikely(!p))
6856 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857 entry->prev_cookie = entry->cookie;
6858 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006859 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006860
Trond Myklebust9af8c222010-10-24 11:52:55 -04006861 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006862 if (unlikely(!p))
6863 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865
6866 /*
6867 * In case the server doesn't return an inode number,
6868 * we fake one here. (We don't use inode number 0,
6869 * since glibc seems to choke on it...)
6870 */
6871 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006872 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873
Trond Myklebust9af8c222010-10-24 11:52:55 -04006874 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006875 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006876
6877 if (decode_attr_length(xdr, &len, &p) < 0)
6878 goto out_overflow;
6879
Chuck Lever573c4e12010-12-14 14:58:11 +00006880 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006881 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006882 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006883 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6884 entry->ino = entry->fattr->mounted_on_fileid;
6885 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006886 entry->ino = entry->fattr->fileid;
6887
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006888 entry->d_type = DT_UNKNOWN;
6889 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6890 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6891
Chuck Lever573c4e12010-12-14 14:58:11 +00006892 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006893
6894out_overflow:
6895 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006896 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897}
6898
6899/*
6900 * We need to translate between nfs status return values and
6901 * the local errno values which may not be the same.
6902 */
6903static struct {
6904 int stat;
6905 int errno;
6906} nfs_errtbl[] = {
6907 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006908 { NFS4ERR_PERM, -EPERM },
6909 { NFS4ERR_NOENT, -ENOENT },
6910 { NFS4ERR_IO, -errno_NFSERR_IO},
6911 { NFS4ERR_NXIO, -ENXIO },
6912 { NFS4ERR_ACCESS, -EACCES },
6913 { NFS4ERR_EXIST, -EEXIST },
6914 { NFS4ERR_XDEV, -EXDEV },
6915 { NFS4ERR_NOTDIR, -ENOTDIR },
6916 { NFS4ERR_ISDIR, -EISDIR },
6917 { NFS4ERR_INVAL, -EINVAL },
6918 { NFS4ERR_FBIG, -EFBIG },
6919 { NFS4ERR_NOSPC, -ENOSPC },
6920 { NFS4ERR_ROFS, -EROFS },
6921 { NFS4ERR_MLINK, -EMLINK },
6922 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6923 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6924 { NFS4ERR_DQUOT, -EDQUOT },
6925 { NFS4ERR_STALE, -ESTALE },
6926 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006927 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6928 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6929 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006930 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006931 { NFS4ERR_BADTYPE, -EBADTYPE },
6932 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006933 { NFS4ERR_SYMLINK, -ELOOP },
6934 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6935 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006936 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937};
6938
6939/*
6940 * Convert an NFS error code to a local one.
6941 * This one is used jointly by NFSv2 and NFSv3.
6942 */
6943static int
David Howells0a8ea432006-08-22 20:06:08 -04006944nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945{
6946 int i;
6947 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6948 if (nfs_errtbl[i].stat == stat)
6949 return nfs_errtbl[i].errno;
6950 }
6951 if (stat <= 10000 || stat > 10100) {
6952 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006953 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 }
6955 /* If we cannot translate the error, the recovery routines should
6956 * handle it.
6957 * Note: remaining NFSv4 error codes have values > 10000, so should
6958 * not conflict with native Linux error codes.
6959 */
Benny Halevy856dff32008-03-31 17:39:06 +03006960 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961}
6962
Linus Torvalds1da177e2005-04-16 15:20:36 -07006963#define PROC(proc, argtype, restype) \
6964[NFSPROC4_CLNT_##proc] = { \
6965 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006966 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006967 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006968 .p_arglen = NFS4_##argtype##_sz, \
6969 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006970 .p_statidx = NFSPROC4_CLNT_##proc, \
6971 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006972}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006973
6974struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006975 PROC(READ, enc_read, dec_read),
6976 PROC(WRITE, enc_write, dec_write),
6977 PROC(COMMIT, enc_commit, dec_commit),
6978 PROC(OPEN, enc_open, dec_open),
6979 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6980 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6981 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6982 PROC(CLOSE, enc_close, dec_close),
6983 PROC(SETATTR, enc_setattr, dec_setattr),
6984 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6985 PROC(RENEW, enc_renew, dec_renew),
6986 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6987 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6988 PROC(LOCK, enc_lock, dec_lock),
6989 PROC(LOCKT, enc_lockt, dec_lockt),
6990 PROC(LOCKU, enc_locku, dec_locku),
6991 PROC(ACCESS, enc_access, dec_access),
6992 PROC(GETATTR, enc_getattr, dec_getattr),
6993 PROC(LOOKUP, enc_lookup, dec_lookup),
6994 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6995 PROC(REMOVE, enc_remove, dec_remove),
6996 PROC(RENAME, enc_rename, dec_rename),
6997 PROC(LINK, enc_link, dec_link),
6998 PROC(SYMLINK, enc_symlink, dec_symlink),
6999 PROC(CREATE, enc_create, dec_create),
7000 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7001 PROC(STATFS, enc_statfs, dec_statfs),
7002 PROC(READLINK, enc_readlink, dec_readlink),
7003 PROC(READDIR, enc_readdir, dec_readdir),
7004 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7005 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7006 PROC(GETACL, enc_getacl, dec_getacl),
7007 PROC(SETACL, enc_setacl, dec_setacl),
7008 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7009 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007010 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007011#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007012 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7013 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7014 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7015 PROC(SEQUENCE, enc_sequence, dec_sequence),
7016 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7017 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7018 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7019 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007020 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007021 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007022 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007023 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007024 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007025 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007026#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007027};
7028
Trond Myklebusta613fa12012-01-20 13:53:56 -05007029const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007030 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007031 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007032 .procs = nfs4_procedures
7033};
7034
7035/*
7036 * Local variables:
7037 * c-basic-offset: 8
7038 * End:
7039 */