blob: f958849cb304f38c5ee58794730ae312067238fe [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 Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#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 + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Trond Myklebustcb17e552012-03-04 18:13:56 -0500888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500900 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 xdr_encode_opaque(p, str, len);
902}
903
Trond Myklebust4ade9822012-03-04 18:13:57 -0500904static void encode_uint32(struct xdr_stream *xdr, u32 n)
905{
906 __be32 *p;
907
908 p = reserve_space(xdr, 4);
909 *p = cpu_to_be32(n);
910}
911
912static void encode_nfs4_seqid(struct xdr_stream *xdr,
913 const struct nfs_seqid *seqid)
914{
915 encode_uint32(xdr, seqid->sequence->counter);
916}
917
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400918static void encode_compound_hdr(struct xdr_stream *xdr,
919 struct rpc_rqst *req,
920 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400923 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400924
925 /* initialize running count of expected bytes in reply.
926 * NOTE: the replied tag SHOULD be the same is the one sent,
927 * but this is not required as a MUST for the server to do so. */
928 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500931 encode_string(xdr, hdr->taglen, hdr->tag);
932 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300933 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500934 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300935 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500936}
937
Trond Myklebustab19b482012-03-04 18:13:57 -0500938static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
939 uint32_t replen,
940 struct compound_hdr *hdr)
941{
942 encode_uint32(xdr, op);
943 hdr->nops++;
944 hdr->replen += replen;
945}
946
Andy Adamsond0179312008-12-23 16:06:17 -0500947static void encode_nops(struct compound_hdr *hdr)
948{
Andy Adamsonfc931582009-04-01 09:22:31 -0400949 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500950 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500953static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
954{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500955 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500956}
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
959{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500960 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500963static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
965 char owner_name[IDMAP_NAMESZ];
966 char owner_group[IDMAP_NAMESZ];
967 int owner_namelen = 0;
968 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700969 __be32 *p;
970 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 int len;
972 uint32_t bmval0 = 0;
973 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /*
976 * We reserve enough space to write the entire attribute buffer at once.
977 * In the worst-case, this would be
978 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
979 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000980 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 */
982 len = 16;
983
984 /* Sigh */
985 if (iap->ia_valid & ATTR_SIZE)
986 len += 8;
987 if (iap->ia_valid & ATTR_MODE)
988 len += 4;
989 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800990 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400992 dprintk("nfs: couldn't resolve uid %d to string\n",
993 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 /* XXX */
995 strcpy(owner_name, "nobody");
996 owner_namelen = sizeof("nobody") - 1;
997 /* goto out; */
998 }
999 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1000 }
1001 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001002 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001004 dprintk("nfs: couldn't resolve gid %d to string\n",
1005 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 strcpy(owner_group, "nobody");
1007 owner_grouplen = sizeof("nobody") - 1;
1008 /* goto out; */
1009 }
1010 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1011 }
1012 if (iap->ia_valid & ATTR_ATIME_SET)
1013 len += 16;
1014 else if (iap->ia_valid & ATTR_ATIME)
1015 len += 4;
1016 if (iap->ia_valid & ATTR_MTIME_SET)
1017 len += 16;
1018 else if (iap->ia_valid & ATTR_MTIME)
1019 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001020 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 /*
1023 * We write the bitmap length now, but leave the bitmap and the attribute
1024 * buffer length to be backfilled at the end of this routine.
1025 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001026 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 q = p;
1028 p += 3;
1029
1030 if (iap->ia_valid & ATTR_SIZE) {
1031 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001032 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 if (iap->ia_valid & ATTR_MODE) {
1035 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001036 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038 if (iap->ia_valid & ATTR_UID) {
1039 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001040 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 if (iap->ia_valid & ATTR_GID) {
1043 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001044 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_ATIME_SET) {
1047 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1049 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001050 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1051 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
1053 else if (iap->ia_valid & ATTR_ATIME) {
1054 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
1057 if (iap->ia_valid & ATTR_MTIME_SET) {
1058 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001059 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1060 *p++ = cpu_to_be32(0);
1061 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1062 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064 else if (iap->ia_valid & ATTR_MTIME) {
1065 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001066 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 /*
1070 * Now we backfill the bitmap and the attribute buffer length.
1071 */
1072 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001073 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 len, ((char *)p - (char *)q) + 4);
1075 BUG();
1076 }
1077 len = (char *)p - (char *)q - 12;
1078 *q++ = htonl(bmval0);
1079 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001080 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Al Viro8687b632006-10-19 23:28:48 -07001087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Benny Halevy13c65ce2009-08-14 17:19:25 +03001089 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001090 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001091 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001092 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001093 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001096static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Trond Myklebustab19b482012-03-04 18:13:57 -05001098 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001099 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001100 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Al Viro8687b632006-10-19 23:28:48 -07001105 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001106
Benny Halevy13c65ce2009-08-14 17:19:25 +03001107 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001108 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001109 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001110 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001111 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001112 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001115static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Al Viro8687b632006-10-19 23:28:48 -07001117 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001118
Benny Halevy13c65ce2009-08-14 17:19:25 +03001119 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001120 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001121 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 switch (create->ftype) {
1124 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001125 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001126 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001127 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 break;
1129
1130 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001131 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001132 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001133 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 break;
1135
1136 default:
1137 break;
1138 }
1139
Benny Halevy811652b2009-08-14 17:19:34 +03001140 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001141 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001142 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001147static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Andy Adamson05d564f2008-12-23 16:06:15 -05001149 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Benny Halevy13c65ce2009-08-14 17:19:25 +03001151 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001152 *p++ = cpu_to_be32(OP_GETATTR);
1153 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001154 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001155 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001156 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001159static 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 -07001160{
Andy Adamson05d564f2008-12-23 16:06:15 -05001161 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Benny Halevy13c65ce2009-08-14 17:19:25 +03001163 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001164 *p++ = cpu_to_be32(OP_GETATTR);
1165 *p++ = cpu_to_be32(2);
1166 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001167 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001168 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001169 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
Fred Isamandae100c2011-07-30 20:52:37 -04001172static void
1173encode_getattr_three(struct xdr_stream *xdr,
1174 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1175 struct compound_hdr *hdr)
1176{
1177 __be32 *p;
1178
Trond Myklebustab19b482012-03-04 18:13:57 -05001179 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001180 if (bm2) {
1181 p = reserve_space(xdr, 16);
1182 *p++ = cpu_to_be32(3);
1183 *p++ = cpu_to_be32(bm0);
1184 *p++ = cpu_to_be32(bm1);
1185 *p = cpu_to_be32(bm2);
1186 } else if (bm1) {
1187 p = reserve_space(xdr, 12);
1188 *p++ = cpu_to_be32(2);
1189 *p++ = cpu_to_be32(bm0);
1190 *p = cpu_to_be32(bm1);
1191 } else {
1192 p = reserve_space(xdr, 8);
1193 *p++ = cpu_to_be32(1);
1194 *p = cpu_to_be32(bm0);
1195 }
Fred Isamandae100c2011-07-30 20:52:37 -04001196}
1197
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001198static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001200 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1201 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202}
1203
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001204static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
Fred Isamandae100c2011-07-30 20:52:37 -04001206 encode_getattr_three(xdr,
1207 bitmask[0] & nfs4_fsinfo_bitmap[0],
1208 bitmask[1] & nfs4_fsinfo_bitmap[1],
1209 bitmask[2] & nfs4_fsinfo_bitmap[2],
1210 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001213static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001214{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001215 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1216 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001217}
1218
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001219static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
Trond Myklebustab19b482012-03-04 18:13:57 -05001221 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001224static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
Trond Myklebustab19b482012-03-04 18:13:57 -05001226 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001227 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001230static inline int nfs4_lock_type(struct file_lock *fl, int block)
1231{
1232 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1233 return block ? NFS4_READW_LT : NFS4_READ_LT;
1234 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1235}
1236
1237static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1238{
1239 if (fl->fl_end == OFFSET_MAX)
1240 return ~(uint64_t)0;
1241 return fl->fl_end - fl->fl_start + 1;
1242}
1243
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1245{
1246 __be32 *p;
1247
Trond Myklebustd035c362010-12-21 10:45:27 -05001248 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001249 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001250 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001251 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001252 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001253 xdr_encode_hyper(p, lowner->id);
1254}
1255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256/*
1257 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1258 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1259 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Al Viro8687b632006-10-19 23:28:48 -07001262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Benny Halevy13c65ce2009-08-14 17:19:25 +03001264 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001265 *p++ = cpu_to_be32(OP_LOCK);
1266 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1267 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001268 p = xdr_encode_hyper(p, args->fl->fl_start);
1269 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001270 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001271 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001272 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001273 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001274 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001278 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001279 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
Andy Adamsond0179312008-12-23 16:06:17 -05001281 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001282 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283}
1284
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Al Viro8687b632006-10-19 23:28:48 -07001287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001289 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001290 *p++ = cpu_to_be32(OP_LOCKT);
1291 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001292 p = xdr_encode_hyper(p, args->fl->fl_start);
1293 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001294 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001295 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001296 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297}
1298
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001299static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Al Viro8687b632006-10-19 23:28:48 -07001301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(OP_LOCKU);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001305 *p = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1306 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001307 encode_nfs4_stateid(xdr, args->stateid);
1308 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001309 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001310 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001311 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001312 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
1314
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001315static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1316{
Trond Myklebustab19b482012-03-04 18:13:57 -05001317 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001318 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001319}
1320
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001321static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Trond Myklebustab19b482012-03-04 18:13:57 -05001323 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001324 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001327static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Benny Halevy13c65ce2009-08-14 17:19:25 +03001331 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001332 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001333 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001334 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001335 break;
1336 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001337 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001338 break;
1339 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001340 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001341 break;
1342 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Benny Halevy34558512009-08-14 17:19:30 +03001345 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
1348static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 /*
1352 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1353 * owner 4 = 32
1354 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001355 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001356 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001357 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001358 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001359 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001360 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001361 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001362 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363}
1364
1365static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1366{
Al Viro8687b632006-10-19 23:28:48 -07001367 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001368 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Benny Halevy13c65ce2009-08-14 17:19:25 +03001370 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001372 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001373 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 encode_attrs(xdr, arg->u.attrs, arg->server);
1375 break;
1376 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001377 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001378 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001379 if (nfs4_has_persistent_session(clp)) {
1380 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1381 encode_attrs(xdr, arg->u.attrs, arg->server);
1382 } else {
1383 struct iattr dummy;
1384
1385 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1386 encode_nfs4_verifier(xdr, &arg->u.verifier);
1387 dummy.ia_valid = 0;
1388 encode_attrs(xdr, &dummy, arg->server);
1389 }
1390 } else {
1391 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1392 encode_nfs4_verifier(xdr, &arg->u.verifier);
1393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 }
1395}
1396
1397static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1398{
Al Viro8687b632006-10-19 23:28:48 -07001399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Benny Halevy13c65ce2009-08-14 17:19:25 +03001401 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001403 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 break;
1406 default:
1407 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001408 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001409 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 }
1411}
1412
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001413static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
Al Viro8687b632006-10-19 23:28:48 -07001415 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Benny Halevy13c65ce2009-08-14 17:19:25 +03001417 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 break;
1422 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001423 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001424 break;
1425 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001426 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001427 break;
1428 default:
1429 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431}
1432
1433static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1434{
Al Viro8687b632006-10-19 23:28:48 -07001435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Benny Halevy13c65ce2009-08-14 17:19:25 +03001437 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001438 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 encode_string(xdr, name->len, name->name);
1440}
1441
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001442static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
Al Viro8687b632006-10-19 23:28:48 -07001444 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Benny Halevy13c65ce2009-08-14 17:19:25 +03001446 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001447 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 encode_delegation_type(xdr, type);
1449}
1450
1451static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1452{
Al Viro8687b632006-10-19 23:28:48 -07001453 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001455 p = reserve_space(xdr, 4);
1456 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1457 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_string(xdr, name->len, name->name);
1459}
1460
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001461static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Trond Myklebustab19b482012-03-04 18:13:57 -05001463 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 encode_openhdr(xdr, arg);
1465 encode_opentype(xdr, arg);
1466 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 case NFS4_OPEN_CLAIM_NULL:
1468 encode_claim_null(xdr, arg->name);
1469 break;
1470 case NFS4_OPEN_CLAIM_PREVIOUS:
1471 encode_claim_previous(xdr, arg->u.delegation_type);
1472 break;
1473 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1474 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1475 break;
1476 default:
1477 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001481static 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 -07001482{
Trond Myklebustab19b482012-03-04 18:13:57 -05001483 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001484 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001485 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486}
1487
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001488static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Trond Myklebustab19b482012-03-04 18:13:57 -05001490 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001491 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001492 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001493 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void
Andy Adamsond0179312008-12-23 16:06:17 -05001497encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Trond Myklebustab19b482012-03-04 18:13:57 -05001499 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001500 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501}
1502
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001503static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
Trond Myklebustab19b482012-03-04 18:13:57 -05001505 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001508static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 if (ctx->state != NULL) {
Trond Myklebust1e3987c2012-03-04 18:13:56 -05001513 nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001514 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001515 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001516 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001518 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Al Viro8687b632006-10-19 23:28:48 -07001523 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Trond Myklebustab19b482012-03-04 18:13:57 -05001525 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001526 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001527 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Benny Halevy13c65ce2009-08-14 17:19:25 +03001529 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001530 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001531 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534static 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 -07001535{
Trond Myklebust28331a42011-04-27 13:47:52 -04001536 uint32_t attrs[2] = {
1537 FATTR4_WORD0_RDATTR_ERROR,
1538 FATTR4_WORD1_MOUNTED_ON_FILEID,
1539 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001540 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001541 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001543 if (readdir->plus) {
1544 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001545 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001546 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1547 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1548 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1549 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001550 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001551 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001552 /* Use mounted_on_fileid only if the server supports it */
1553 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1554 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001555
Chuck Levercd937102012-03-02 17:14:31 -05001556 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001557 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001558 p = xdr_encode_hyper(p, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001559 encode_nfs4_verifier(xdr, &readdir->verifier);
1560 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001561 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001562 *p++ = cpu_to_be32(readdir->count);
1563 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001564
Benny Halevye75bc1c2009-08-14 17:18:54 +03001565 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001566 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001567 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001568 hdr->replen += decode_readdir_maxsz;
Chuck Levercd937102012-03-02 17:14:31 -05001569 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001570 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1571 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001572 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001573 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001574 attrs[0] & readdir->bitmask[0],
1575 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001578static 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 -07001579{
Trond Myklebustab19b482012-03-04 18:13:57 -05001580 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001583static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
Trond Myklebustab19b482012-03-04 18:13:57 -05001585 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001586 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001589static 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 -07001590{
Trond Myklebustab19b482012-03-04 18:13:57 -05001591 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001592 encode_string(xdr, oldname->len, oldname->name);
1593 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594}
1595
Chuck Leverbb4dae52012-03-01 17:01:48 -05001596static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1597 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598{
Al Viro8687b632006-10-19 23:28:48 -07001599 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Benny Halevy13c65ce2009-08-14 17:19:25 +03001601 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001602 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001603 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001604 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001605 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void
Andy Adamsond0179312008-12-23 16:06:17 -05001609encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001612}
1613
Chuck Lever9f06c712010-12-14 14:59:18 +00001614static void
Andy Adamsond0179312008-12-23 16:06:17 -05001615encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001616{
Al Viro8687b632006-10-19 23:28:48 -07001617 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001618
Trond Myklebustab19b482012-03-04 18:13:57 -05001619 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001620 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001622 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001623 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001624 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001625 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001626 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001627 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001628}
1629
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001630static void
Andy Adamsond0179312008-12-23 16:06:17 -05001631encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
Trond Myklebustab19b482012-03-04 18:13:57 -05001633 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001636static 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 -07001637{
Trond Myklebustab19b482012-03-04 18:13:57 -05001638 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001639 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001640 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001643static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Al Viro8687b632006-10-19 23:28:48 -07001645 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Trond Myklebust70019512012-03-04 20:49:32 -05001647 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001648 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001651 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001652 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1654 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001655 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001656 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001659static 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 -07001660{
Andy Adamson05d564f2008-12-23 16:06:15 -05001661 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Chuck Levercd937102012-03-02 17:14:31 -05001663 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001664 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001665 p = xdr_encode_hyper(p, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001666 encode_nfs4_verifier(xdr, &arg->confirm);
Andy Adamsond0179312008-12-23 16:06:17 -05001667 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001668 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669}
1670
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001671static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
Al Viro8687b632006-10-19 23:28:48 -07001673 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Trond Myklebustab19b482012-03-04 18:13:57 -05001675 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001676 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001677 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Benny Halevy13c65ce2009-08-14 17:19:25 +03001679 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001680 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001681 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001682 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
1684 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001687static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Trond Myklebustab19b482012-03-04 18:13:57 -05001689 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001690 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001692
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001693static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1694{
Trond Myklebustab19b482012-03-04 18:13:57 -05001695 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001696 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001697}
1698
Benny Halevy99fe60d2009-04-01 09:22:29 -04001699#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001700/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001701static void encode_exchange_id(struct xdr_stream *xdr,
1702 struct nfs41_exchange_id_args *args,
1703 struct compound_hdr *hdr)
1704{
1705 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001706 char impl_name[NFS4_OPAQUE_LIMIT];
1707 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001708
Trond Myklebust70019512012-03-04 20:49:32 -05001709 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001710 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001711
1712 encode_string(xdr, args->id_len, args->id);
1713
Benny Halevy13c65ce2009-08-14 17:19:25 +03001714 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001715 *p++ = cpu_to_be32(args->flags);
1716 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001717
1718 if (send_implementation_id &&
1719 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1720 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1721 <= NFS4_OPAQUE_LIMIT + 1)
1722 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1723 utsname()->sysname, utsname()->release,
1724 utsname()->version, utsname()->machine);
1725
1726 if (len > 0) {
1727 *p = cpu_to_be32(1); /* implementation id array length=1 */
1728
1729 encode_string(xdr,
1730 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1731 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1732 encode_string(xdr, len, impl_name);
1733 /* just send zeros for nii_date - the date is in nii_name */
1734 p = reserve_space(xdr, 12);
1735 p = xdr_encode_hyper(p, 0);
1736 *p = cpu_to_be32(0);
1737 } else
1738 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001739}
Andy Adamsonfc931582009-04-01 09:22:31 -04001740
1741static void encode_create_session(struct xdr_stream *xdr,
1742 struct nfs41_create_session_args *args,
1743 struct compound_hdr *hdr)
1744{
1745 __be32 *p;
1746 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1747 uint32_t len;
1748 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001749 u32 max_resp_sz_cached;
1750
1751 /*
1752 * Assumes OPEN is the biggest non-idempotent compound.
1753 * 2 is the verifier.
1754 */
1755 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1756 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001757
Andy Adamsonfc931582009-04-01 09:22:31 -04001758 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1759 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001760
Benny Halevy13c65ce2009-08-14 17:19:25 +03001761 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001762 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001763 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001764 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1765 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001766
Andy Adamsonfc931582009-04-01 09:22:31 -04001767 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001768 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001769 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1770 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001771 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001772 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1773 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1774 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001775
1776 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001777 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001778 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1779 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1780 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1781 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1782 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1783 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001784
Benny Halevye75bc1c2009-08-14 17:18:54 +03001785 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001786 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001787 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001788
1789 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001790 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001791 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001792 *p++ = cpu_to_be32(0); /* UID */
1793 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001794 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001795 hdr->nops++;
1796 hdr->replen += decode_create_session_maxsz;
1797}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001798
1799static void encode_destroy_session(struct xdr_stream *xdr,
1800 struct nfs4_session *session,
1801 struct compound_hdr *hdr)
1802{
1803 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001804 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001805 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001806 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001807 hdr->nops++;
1808 hdr->replen += decode_destroy_session_maxsz;
1809}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001810
1811static void encode_reclaim_complete(struct xdr_stream *xdr,
1812 struct nfs41_reclaim_complete_args *args,
1813 struct compound_hdr *hdr)
1814{
1815 __be32 *p;
1816
1817 p = reserve_space(xdr, 8);
1818 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1819 *p++ = cpu_to_be32(args->one_fs);
1820 hdr->nops++;
1821 hdr->replen += decode_reclaim_complete_maxsz;
1822}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001823#endif /* CONFIG_NFS_V4_1 */
1824
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001825static void encode_sequence(struct xdr_stream *xdr,
1826 const struct nfs4_sequence_args *args,
1827 struct compound_hdr *hdr)
1828{
1829#if defined(CONFIG_NFS_V4_1)
1830 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001831 struct nfs4_slot_table *tp;
1832 struct nfs4_slot *slot;
1833 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001834
1835 if (!session)
1836 return;
1837
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001838 tp = &session->fc_slot_table;
1839
1840 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1841 slot = tp->slots + args->sa_slotid;
1842
Benny Halevy13c65ce2009-08-14 17:19:25 +03001843 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001845
1846 /*
1847 * Sessionid + seqid + slotid + max slotid + cache_this
1848 */
1849 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1850 "max_slotid=%d cache_this=%d\n",
1851 __func__,
1852 ((u32 *)session->sess_id.data)[0],
1853 ((u32 *)session->sess_id.data)[1],
1854 ((u32 *)session->sess_id.data)[2],
1855 ((u32 *)session->sess_id.data)[3],
1856 slot->seq_nr, args->sa_slotid,
1857 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001858 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(slot->seq_nr);
1860 *p++ = cpu_to_be32(args->sa_slotid);
1861 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001862 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001863 hdr->nops++;
1864 hdr->replen += decode_sequence_maxsz;
1865#endif /* CONFIG_NFS_V4_1 */
1866}
1867
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001868#ifdef CONFIG_NFS_V4_1
1869static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001870encode_getdevicelist(struct xdr_stream *xdr,
1871 const struct nfs4_getdevicelist_args *args,
1872 struct compound_hdr *hdr)
1873{
1874 __be32 *p;
1875 nfs4_verifier dummy = {
1876 .data = "dummmmmy",
1877 };
1878
1879 p = reserve_space(xdr, 20);
1880 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1881 *p++ = cpu_to_be32(args->layoutclass);
1882 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1883 xdr_encode_hyper(p, 0ULL); /* cookie */
1884 encode_nfs4_verifier(xdr, &dummy);
1885 hdr->nops++;
1886 hdr->replen += decode_getdevicelist_maxsz;
1887}
1888
1889static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001890encode_getdeviceinfo(struct xdr_stream *xdr,
1891 const struct nfs4_getdeviceinfo_args *args,
1892 struct compound_hdr *hdr)
1893{
1894 __be32 *p;
1895
1896 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1897 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1898 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1899 NFS4_DEVICEID4_SIZE);
1900 *p++ = cpu_to_be32(args->pdev->layout_type);
1901 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1902 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1903 hdr->nops++;
1904 hdr->replen += decode_getdeviceinfo_maxsz;
1905}
1906
1907static void
1908encode_layoutget(struct xdr_stream *xdr,
1909 const struct nfs4_layoutget_args *args,
1910 struct compound_hdr *hdr)
1911{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912 __be32 *p;
1913
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001914 p = reserve_space(xdr, 40);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001915 *p++ = cpu_to_be32(OP_LAYOUTGET);
1916 *p++ = cpu_to_be32(0); /* Signal layout available */
1917 *p++ = cpu_to_be32(args->type);
1918 *p++ = cpu_to_be32(args->range.iomode);
1919 p = xdr_encode_hyper(p, args->range.offset);
1920 p = xdr_encode_hyper(p, args->range.length);
1921 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001922 encode_nfs4_stateid(xdr, &args->stateid);
1923 p = reserve_space(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001924 *p = cpu_to_be32(args->maxcount);
1925
1926 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1927 __func__,
1928 args->type,
1929 args->range.iomode,
1930 (unsigned long)args->range.offset,
1931 (unsigned long)args->range.length,
1932 args->maxcount);
1933 hdr->nops++;
1934 hdr->replen += decode_layoutget_maxsz;
1935}
Andy Adamson863a3c62011-03-23 13:27:54 +00001936
1937static int
1938encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001939 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001940 const struct nfs4_layoutcommit_args *args,
1941 struct compound_hdr *hdr)
1942{
1943 __be32 *p;
1944
1945 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1946 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1947
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001948 p = reserve_space(xdr, 24);
Andy Adamson863a3c62011-03-23 13:27:54 +00001949 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1950 /* Only whole file layouts */
1951 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001952 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001953 *p = cpu_to_be32(0); /* reclaim */
1954 encode_nfs4_stateid(xdr, &args->stateid);
1955 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001956 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1957 p = xdr_encode_hyper(p, args->lastbytewritten);
1958 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1959 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001960
1961 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1962 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1963 NFS_I(inode)->layout, xdr, args);
1964 else {
1965 p = reserve_space(xdr, 4);
1966 *p = cpu_to_be32(0); /* no layout-type payload */
1967 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001968
1969 hdr->nops++;
1970 hdr->replen += decode_layoutcommit_maxsz;
1971 return 0;
1972}
Benny Halevycbe82602011-05-22 19:52:37 +03001973
1974static void
1975encode_layoutreturn(struct xdr_stream *xdr,
1976 const struct nfs4_layoutreturn_args *args,
1977 struct compound_hdr *hdr)
1978{
1979 __be32 *p;
1980
1981 p = reserve_space(xdr, 20);
1982 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1983 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1984 *p++ = cpu_to_be32(args->layout_type);
1985 *p++ = cpu_to_be32(IOMODE_ANY);
1986 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001987 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001988 p = xdr_encode_hyper(p, 0);
1989 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1990 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001991 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001992 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001993 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1994 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1995 NFS_I(args->inode)->layout, xdr, args);
1996 } else {
1997 p = reserve_space(xdr, 4);
1998 *p = cpu_to_be32(0);
1999 }
Benny Halevycbe82602011-05-22 19:52:37 +03002000 hdr->nops++;
2001 hdr->replen += decode_layoutreturn_maxsz;
2002}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002003
2004static int
2005encode_secinfo_no_name(struct xdr_stream *xdr,
2006 const struct nfs41_secinfo_no_name_args *args,
2007 struct compound_hdr *hdr)
2008{
2009 __be32 *p;
2010 p = reserve_space(xdr, 8);
2011 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2012 *p++ = cpu_to_be32(args->style);
2013 hdr->nops++;
2014 hdr->replen += decode_secinfo_no_name_maxsz;
2015 return 0;
2016}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002017
2018static void encode_test_stateid(struct xdr_stream *xdr,
2019 struct nfs41_test_stateid_args *args,
2020 struct compound_hdr *hdr)
2021{
2022 __be32 *p;
2023
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002024 p = reserve_space(xdr, 8);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002025 *p++ = cpu_to_be32(OP_TEST_STATEID);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002026 *p = cpu_to_be32(1);
2027 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002028 hdr->nops++;
2029 hdr->replen += decode_test_stateid_maxsz;
2030}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002031
2032static void encode_free_stateid(struct xdr_stream *xdr,
2033 struct nfs41_free_stateid_args *args,
2034 struct compound_hdr *hdr)
2035{
Trond Myklebustab19b482012-03-04 18:13:57 -05002036 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002037 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002038}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002039#endif /* CONFIG_NFS_V4_1 */
2040
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041/*
2042 * END OF "GENERIC" ENCODE ROUTINES.
2043 */
2044
Benny Halevy66cc0422009-04-01 09:22:10 -04002045static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2046{
2047#if defined(CONFIG_NFS_V4_1)
2048 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002049 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002050#endif /* CONFIG_NFS_V4_1 */
2051 return 0;
2052}
2053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054/*
2055 * Encode an ACCESS request
2056 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002057static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2058 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Chuck Lever9f06c712010-12-14 14:59:18 +00002064 encode_compound_hdr(xdr, req, &hdr);
2065 encode_sequence(xdr, &args->seq_args, &hdr);
2066 encode_putfh(xdr, args->fh, &hdr);
2067 encode_access(xdr, args->access, &hdr);
2068 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002069 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}
2071
2072/*
2073 * Encode LOOKUP request
2074 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002075static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2076 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002079 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Chuck Lever9f06c712010-12-14 14:59:18 +00002082 encode_compound_hdr(xdr, req, &hdr);
2083 encode_sequence(xdr, &args->seq_args, &hdr);
2084 encode_putfh(xdr, args->dir_fh, &hdr);
2085 encode_lookup(xdr, args->name, &hdr);
2086 encode_getfh(xdr, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Encode LOOKUP_ROOT request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2095 struct xdr_stream *xdr,
2096 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002099 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 encode_compound_hdr(xdr, req, &hdr);
2103 encode_sequence(xdr, &args->seq_args, &hdr);
2104 encode_putrootfh(xdr, &hdr);
2105 encode_getfh(xdr, &hdr);
2106 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002107 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108}
2109
2110/*
2111 * Encode REMOVE request
2112 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002113static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2114 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002117 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
Chuck Lever9f06c712010-12-14 14:59:18 +00002120 encode_compound_hdr(xdr, req, &hdr);
2121 encode_sequence(xdr, &args->seq_args, &hdr);
2122 encode_putfh(xdr, args->fh, &hdr);
2123 encode_remove(xdr, &args->name, &hdr);
2124 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/*
2129 * Encode RENAME request
2130 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002131static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2132 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putfh(xdr, args->old_dir, &hdr);
2141 encode_savefh(xdr, &hdr);
2142 encode_putfh(xdr, args->new_dir, &hdr);
2143 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2144 encode_getfattr(xdr, args->bitmask, &hdr);
2145 encode_restorefh(xdr, &hdr);
2146 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002147 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
2150/*
2151 * Encode LINK request
2152 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002153static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2154 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002157 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
Chuck Lever9f06c712010-12-14 14:59:18 +00002160 encode_compound_hdr(xdr, req, &hdr);
2161 encode_sequence(xdr, &args->seq_args, &hdr);
2162 encode_putfh(xdr, args->fh, &hdr);
2163 encode_savefh(xdr, &hdr);
2164 encode_putfh(xdr, args->dir_fh, &hdr);
2165 encode_link(xdr, args->name, &hdr);
2166 encode_getfattr(xdr, args->bitmask, &hdr);
2167 encode_restorefh(xdr, &hdr);
2168 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002169 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/*
2173 * Encode CREATE request
2174 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002175static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2176 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Chuck Lever9f06c712010-12-14 14:59:18 +00002182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->dir_fh, &hdr);
2185 encode_savefh(xdr, &hdr);
2186 encode_create(xdr, args, &hdr);
2187 encode_getfh(xdr, &hdr);
2188 encode_getfattr(xdr, args->bitmask, &hdr);
2189 encode_restorefh(xdr, &hdr);
2190 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002191 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
2194/*
2195 * Encode SYMLINK request
2196 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002197static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2198 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Chuck Lever9f06c712010-12-14 14:59:18 +00002200 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode GETATTR request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->fh, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002217 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
2220/*
2221 * Encode a CLOSE request
2222 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002223static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2224 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225{
Andy Adamson05d564f2008-12-23 16:06:15 -05002226 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002228 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
Chuck Lever9f06c712010-12-14 14:59:18 +00002230 encode_compound_hdr(xdr, req, &hdr);
2231 encode_sequence(xdr, &args->seq_args, &hdr);
2232 encode_putfh(xdr, args->fh, &hdr);
2233 encode_close(xdr, args, &hdr);
2234 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002235 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
2238/*
2239 * Encode an OPEN request
2240 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002241static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2242 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002245 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
2251 encode_savefh(xdr, &hdr);
2252 encode_open(xdr, args, &hdr);
2253 encode_getfh(xdr, &hdr);
2254 encode_getfattr(xdr, args->bitmask, &hdr);
2255 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002256 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002257 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
2259
2260/*
2261 * Encode an OPEN_CONFIRM request
2262 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002263static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2264 struct xdr_stream *xdr,
2265 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002268 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Chuck Lever9f06c712010-12-14 14:59:18 +00002271 encode_compound_hdr(xdr, req, &hdr);
2272 encode_putfh(xdr, args->fh, &hdr);
2273 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002274 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275}
2276
2277/*
2278 * Encode an OPEN request with no attributes.
2279 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002280static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2281 struct xdr_stream *xdr,
2282 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Chuck Lever9f06c712010-12-14 14:59:18 +00002288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_open(xdr, args, &hdr);
2292 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002293 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
2297 * Encode an OPEN_DOWNGRADE request
2298 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002299static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2300 struct xdr_stream *xdr,
2301 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002304 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Chuck Lever9f06c712010-12-14 14:59:18 +00002307 encode_compound_hdr(xdr, req, &hdr);
2308 encode_sequence(xdr, &args->seq_args, &hdr);
2309 encode_putfh(xdr, args->fh, &hdr);
2310 encode_open_downgrade(xdr, args, &hdr);
2311 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002312 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
2315/*
2316 * Encode a LOCK request
2317 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002318static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2319 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002322 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_sequence(xdr, &args->seq_args, &hdr);
2327 encode_putfh(xdr, args->fh, &hdr);
2328 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002329 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
2332/*
2333 * Encode a LOCKT request
2334 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002335static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2336 struct nfs_lockt_args *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_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002346 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
2349/*
2350 * Encode a LOCKU request
2351 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002352static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2353 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002356 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Chuck Lever9f06c712010-12-14 14:59:18 +00002359 encode_compound_hdr(xdr, req, &hdr);
2360 encode_sequence(xdr, &args->seq_args, &hdr);
2361 encode_putfh(xdr, args->fh, &hdr);
2362 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002363 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364}
2365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2367 struct xdr_stream *xdr,
2368 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002369{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002370 struct compound_hdr hdr = {
2371 .minorversion = 0,
2372 };
2373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002376 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002377}
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379/*
2380 * Encode a READLINK request
2381 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002382static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2383 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Chuck Lever9f06c712010-12-14 14:59:18 +00002389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
2392 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002393
Benny Halevy28f56692009-04-01 09:22:09 -04002394 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002395 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002396 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397}
2398
2399/*
2400 * Encode a READDIR request
2401 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002402static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2403 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002406 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Chuck Lever9f06c712010-12-14 14:59:18 +00002409 encode_compound_hdr(xdr, req, &hdr);
2410 encode_sequence(xdr, &args->seq_args, &hdr);
2411 encode_putfh(xdr, args->fh, &hdr);
2412 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002413
Benny Halevy28f56692009-04-01 09:22:09 -04002414 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002415 args->pgbase, args->count);
2416 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002417 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002418 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002419 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420}
2421
2422/*
2423 * Encode a READ request
2424 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002425static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2426 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002429 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Chuck Lever9f06c712010-12-14 14:59:18 +00002432 encode_compound_hdr(xdr, req, &hdr);
2433 encode_sequence(xdr, &args->seq_args, &hdr);
2434 encode_putfh(xdr, args->fh, &hdr);
2435 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
Benny Halevy28f56692009-04-01 09:22:09 -04002437 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002439 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002440 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441}
2442
2443/*
2444 * Encode an SETATTR request
2445 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002446static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2447 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Andy Adamson05d564f2008-12-23 16:06:15 -05002449 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002450 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002451 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453 encode_compound_hdr(xdr, req, &hdr);
2454 encode_sequence(xdr, &args->seq_args, &hdr);
2455 encode_putfh(xdr, args->fh, &hdr);
2456 encode_setattr(xdr, args, args->server, &hdr);
2457 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002458 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459}
2460
2461/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002462 * Encode a GETACL request
2463 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002464static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2465 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002466{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002467 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002468 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002469 };
Benny Halevy28f56692009-04-01 09:22:09 -04002470 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_sequence(xdr, &args->seq_args, &hdr);
2474 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002475 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002477
Benny Halevy28f56692009-04-01 09:22:09 -04002478 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002479 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002480
Andy Adamsond0179312008-12-23 16:06:17 -05002481 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002482}
2483
2484/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 * Encode a WRITE request
2486 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002487static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2488 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002491 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Chuck Lever9f06c712010-12-14 14:59:18 +00002494 encode_compound_hdr(xdr, req, &hdr);
2495 encode_sequence(xdr, &args->seq_args, &hdr);
2496 encode_putfh(xdr, args->fh, &hdr);
2497 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002498 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002499 if (args->bitmask)
2500 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002501 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502}
2503
2504/*
2505 * a COMMIT request
2506 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002507static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2508 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002511 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
Chuck Lever9f06c712010-12-14 14:59:18 +00002514 encode_compound_hdr(xdr, req, &hdr);
2515 encode_sequence(xdr, &args->seq_args, &hdr);
2516 encode_putfh(xdr, args->fh, &hdr);
2517 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002518 if (args->bitmask)
2519 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002520 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
2523/*
2524 * FSINFO request
2525 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002526static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2527 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002530 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_sequence(xdr, &args->seq_args, &hdr);
2535 encode_putfh(xdr, args->fh, &hdr);
2536 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002537 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538}
2539
2540/*
2541 * a PATHCONF request
2542 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002543static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2544 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002547 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
Chuck Lever9f06c712010-12-14 14:59:18 +00002550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_sequence(xdr, &args->seq_args, &hdr);
2552 encode_putfh(xdr, args->fh, &hdr);
2553 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002554 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002555 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
2557
2558/*
2559 * a STATFS request
2560 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002561static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2562 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002565 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
Chuck Lever9f06c712010-12-14 14:59:18 +00002568 encode_compound_hdr(xdr, req, &hdr);
2569 encode_sequence(xdr, &args->seq_args, &hdr);
2570 encode_putfh(xdr, args->fh, &hdr);
2571 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002572 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002573 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574}
2575
2576/*
2577 * GETATTR_BITMAP request
2578 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002579static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002584 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
Chuck Lever9f06c712010-12-14 14:59:18 +00002587 encode_compound_hdr(xdr, req, &hdr);
2588 encode_sequence(xdr, &args->seq_args, &hdr);
2589 encode_putfh(xdr, args->fhandle, &hdr);
2590 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002591 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002592 FATTR4_WORD0_LINK_SUPPORT|
2593 FATTR4_WORD0_SYMLINK_SUPPORT|
2594 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002595 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
2598/*
2599 * a RENEW request
2600 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002601static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2602 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002605 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
2607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002609 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002610 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611}
2612
2613/*
2614 * a SETCLIENTID request
2615 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002616static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2617 struct xdr_stream *xdr,
2618 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002621 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 };
2623
Chuck Lever9f06c712010-12-14 14:59:18 +00002624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002626 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627}
2628
2629/*
2630 * a SETCLIENTID_CONFIRM request
2631 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002632static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2633 struct xdr_stream *xdr,
2634 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002637 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 };
Fred Isamandae100c2011-07-30 20:52:37 -04002639 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
Chuck Lever9f06c712010-12-14 14:59:18 +00002641 encode_compound_hdr(xdr, req, &hdr);
2642 encode_setclientid_confirm(xdr, arg, &hdr);
2643 encode_putrootfh(xdr, &hdr);
2644 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002645 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646}
2647
2648/*
2649 * DELEGRETURN request
2650 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002651static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2652 struct xdr_stream *xdr,
2653 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002656 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Chuck Lever9f06c712010-12-14 14:59:18 +00002659 encode_compound_hdr(xdr, req, &hdr);
2660 encode_sequence(xdr, &args->seq_args, &hdr);
2661 encode_putfh(xdr, args->fhandle, &hdr);
2662 encode_delegreturn(xdr, args->stateid, &hdr);
2663 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002664 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665}
2666
2667/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002668 * Encode FS_LOCATIONS request
2669 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002670static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2671 struct xdr_stream *xdr,
2672 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002673{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002675 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002676 };
Benny Halevy28f56692009-04-01 09:22:09 -04002677 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002678
Chuck Lever9f06c712010-12-14 14:59:18 +00002679 encode_compound_hdr(xdr, req, &hdr);
2680 encode_sequence(xdr, &args->seq_args, &hdr);
2681 encode_putfh(xdr, args->dir_fh, &hdr);
2682 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002683 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002684 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002685
Benny Halevy28f56692009-04-01 09:22:09 -04002686 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002687 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002688 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002689}
2690
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002691/*
2692 * Encode SECINFO request
2693 */
2694static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
2696 struct nfs4_secinfo_arg *args)
2697{
2698 struct compound_hdr hdr = {
2699 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2700 };
2701
2702 encode_compound_hdr(xdr, req, &hdr);
2703 encode_sequence(xdr, &args->seq_args, &hdr);
2704 encode_putfh(xdr, args->dir_fh, &hdr);
2705 encode_secinfo(xdr, args->name, &hdr);
2706 encode_nops(&hdr);
2707}
2708
Benny Halevy99fe60d2009-04-01 09:22:29 -04002709#if defined(CONFIG_NFS_V4_1)
2710/*
2711 * EXCHANGE_ID request
2712 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002713static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2714 struct xdr_stream *xdr,
2715 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002716{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002717 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002718 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002719 };
2720
Chuck Lever9f06c712010-12-14 14:59:18 +00002721 encode_compound_hdr(xdr, req, &hdr);
2722 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002723 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002724}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002725
2726/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002727 * a CREATE_SESSION request
2728 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002729static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2730 struct xdr_stream *xdr,
2731 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002732{
Andy Adamsonfc931582009-04-01 09:22:31 -04002733 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002734 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002735 };
2736
Chuck Lever9f06c712010-12-14 14:59:18 +00002737 encode_compound_hdr(xdr, req, &hdr);
2738 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002739 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002740}
2741
2742/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002743 * a DESTROY_SESSION request
2744 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002745static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
2747 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002748{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002749 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002750 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002751 };
2752
Chuck Lever9f06c712010-12-14 14:59:18 +00002753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002755 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002756}
2757
2758/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002759 * a SEQUENCE request
2760 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002761static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2762 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002763{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002764 struct compound_hdr hdr = {
2765 .minorversion = nfs4_xdr_minorversion(args),
2766 };
2767
Chuck Lever9f06c712010-12-14 14:59:18 +00002768 encode_compound_hdr(xdr, req, &hdr);
2769 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002770 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002771}
2772
2773/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002774 * a GET_LEASE_TIME request
2775 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002776static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
2778 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002779{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002780 struct compound_hdr hdr = {
2781 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2782 };
Fred Isamandae100c2011-07-30 20:52:37 -04002783 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002784
Chuck Lever9f06c712010-12-14 14:59:18 +00002785 encode_compound_hdr(xdr, req, &hdr);
2786 encode_sequence(xdr, &args->la_seq_args, &hdr);
2787 encode_putrootfh(xdr, &hdr);
2788 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002789 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002790}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002791
2792/*
2793 * a RECLAIM_COMPLETE request
2794 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002795static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
2797 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002798{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002799 struct compound_hdr hdr = {
2800 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2801 };
2802
Chuck Lever9f06c712010-12-14 14:59:18 +00002803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_sequence(xdr, &args->seq_args, &hdr);
2805 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002806 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002807}
2808
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002809/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002810 * Encode GETDEVICELIST request
2811 */
2812static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2813 struct xdr_stream *xdr,
2814 struct nfs4_getdevicelist_args *args)
2815{
2816 struct compound_hdr hdr = {
2817 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2818 };
2819
2820 encode_compound_hdr(xdr, req, &hdr);
2821 encode_sequence(xdr, &args->seq_args, &hdr);
2822 encode_putfh(xdr, args->fh, &hdr);
2823 encode_getdevicelist(xdr, args, &hdr);
2824 encode_nops(&hdr);
2825}
2826
2827/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002828 * Encode GETDEVICEINFO request
2829 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002830static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2831 struct xdr_stream *xdr,
2832 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002833{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002834 struct compound_hdr hdr = {
2835 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2836 };
2837
Chuck Lever9f06c712010-12-14 14:59:18 +00002838 encode_compound_hdr(xdr, req, &hdr);
2839 encode_sequence(xdr, &args->seq_args, &hdr);
2840 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002841
2842 /* set up reply kvec. Subtract notification bitmap max size (2)
2843 * so that notification bitmap is put in xdr_buf tail */
2844 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2845 args->pdev->pages, args->pdev->pgbase,
2846 args->pdev->pglen);
2847
2848 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002849}
2850
2851/*
2852 * Encode LAYOUTGET request
2853 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002854static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2855 struct xdr_stream *xdr,
2856 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002857{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002858 struct compound_hdr hdr = {
2859 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2860 };
2861
Chuck Lever9f06c712010-12-14 14:59:18 +00002862 encode_compound_hdr(xdr, req, &hdr);
2863 encode_sequence(xdr, &args->seq_args, &hdr);
2864 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2865 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002866
2867 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2868 args->layout.pages, 0, args->layout.pglen);
2869
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002870 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002871}
Andy Adamson863a3c62011-03-23 13:27:54 +00002872
2873/*
2874 * Encode LAYOUTCOMMIT request
2875 */
Benny Halevycbe82602011-05-22 19:52:37 +03002876static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2877 struct xdr_stream *xdr,
2878 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002879{
Benny Halevyac7db722011-05-22 19:53:48 +03002880 struct nfs4_layoutcommit_data *data =
2881 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002882 struct compound_hdr hdr = {
2883 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2884 };
2885
2886 encode_compound_hdr(xdr, req, &hdr);
2887 encode_sequence(xdr, &args->seq_args, &hdr);
2888 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002889 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002890 encode_getfattr(xdr, args->bitmask, &hdr);
2891 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002892}
2893
2894/*
2895 * Encode LAYOUTRETURN request
2896 */
2897static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
2899 struct nfs4_layoutreturn_args *args)
2900{
2901 struct compound_hdr hdr = {
2902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2903 };
2904
2905 encode_compound_hdr(xdr, req, &hdr);
2906 encode_sequence(xdr, &args->seq_args, &hdr);
2907 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2908 encode_layoutreturn(xdr, args, &hdr);
2909 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002910}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002911
2912/*
2913 * Encode SECINFO_NO_NAME request
2914 */
2915static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs41_secinfo_no_name_args *args)
2918{
2919 struct compound_hdr hdr = {
2920 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2921 };
2922
2923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_sequence(xdr, &args->seq_args, &hdr);
2925 encode_putrootfh(xdr, &hdr);
2926 encode_secinfo_no_name(xdr, args, &hdr);
2927 encode_nops(&hdr);
2928 return 0;
2929}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002930
2931/*
2932 * Encode TEST_STATEID request
2933 */
2934static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2935 struct xdr_stream *xdr,
2936 struct nfs41_test_stateid_args *args)
2937{
2938 struct compound_hdr hdr = {
2939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2940 };
2941
2942 encode_compound_hdr(xdr, req, &hdr);
2943 encode_sequence(xdr, &args->seq_args, &hdr);
2944 encode_test_stateid(xdr, args, &hdr);
2945 encode_nops(&hdr);
2946}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002947
2948/*
2949 * Encode FREE_STATEID request
2950 */
2951static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2952 struct xdr_stream *xdr,
2953 struct nfs41_free_stateid_args *args)
2954{
2955 struct compound_hdr hdr = {
2956 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2957 };
2958
2959 encode_compound_hdr(xdr, req, &hdr);
2960 encode_sequence(xdr, &args->seq_args, &hdr);
2961 encode_free_stateid(xdr, args, &hdr);
2962 encode_nops(&hdr);
2963}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002964#endif /* CONFIG_NFS_V4_1 */
2965
Benny Halevy686841b2009-08-14 17:19:48 +03002966static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2967{
2968 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2969 "Remaining buffer length is %tu words.\n",
2970 func, xdr->end - xdr->p);
2971}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
Trond Myklebust683b57b2006-06-09 09:34:22 -04002973static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
Al Viro8687b632006-10-19 23:28:48 -07002975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Benny Halevyc0eae662009-08-14 17:20:14 +03002977 p = xdr_inline_decode(xdr, 4);
2978 if (unlikely(!p))
2979 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002980 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002981 p = xdr_inline_decode(xdr, *len);
2982 if (unlikely(!p))
2983 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 *string = (char *)p;
2985 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002986out_overflow:
2987 print_overflow_msg(__func__, xdr);
2988 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989}
2990
2991static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2992{
Al Viro8687b632006-10-19 23:28:48 -07002993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, 8);
2996 if (unlikely(!p))
2997 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002998 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002999 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003000
Benny Halevyc0eae662009-08-14 17:20:14 +03003001 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3002 if (unlikely(!p))
3003 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 hdr->tag = (char *)p;
3005 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003006 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003007 if (unlikely(hdr->nops < 1))
3008 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003010out_overflow:
3011 print_overflow_msg(__func__, xdr);
3012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013}
3014
3015static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3016{
Al Viro8687b632006-10-19 23:28:48 -07003017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 uint32_t opnum;
3019 int32_t nfserr;
3020
Benny Halevyc0eae662009-08-14 17:20:14 +03003021 p = xdr_inline_decode(xdr, 8);
3022 if (unlikely(!p))
3023 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003024 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003026 dprintk("nfs: Server returned operation"
3027 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 opnum, expected);
3029 return -EIO;
3030 }
Benny Halevycccddf42009-08-14 17:20:19 +03003031 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003033 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003035out_overflow:
3036 print_overflow_msg(__func__, xdr);
3037 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038}
3039
3040/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003041static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042{
Al Viro8687b632006-10-19 23:28:48 -07003043 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003044 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 char *str;
3046
Benny Halevyc0eae662009-08-14 17:20:14 +03003047 p = xdr_inline_decode(xdr, 12);
3048 if (likely(p))
3049 return decode_opaque_inline(xdr, &strlen, &str);
3050 print_overflow_msg(__func__, xdr);
3051 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
3054static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3055{
Al Viro8687b632006-10-19 23:28:48 -07003056 uint32_t bmlen;
3057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Benny Halevyc0eae662009-08-14 17:20:14 +03003059 p = xdr_inline_decode(xdr, 4);
3060 if (unlikely(!p))
3061 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003062 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
Fred Isamandae100c2011-07-30 20:52:37 -04003064 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003065 p = xdr_inline_decode(xdr, (bmlen << 2));
3066 if (unlikely(!p))
3067 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003069 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003070 if (bmlen > 1) {
3071 bitmap[1] = be32_to_cpup(p++);
3072 if (bmlen > 2)
3073 bitmap[2] = be32_to_cpup(p);
3074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 }
3076 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003077out_overflow:
3078 print_overflow_msg(__func__, xdr);
3079 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080}
3081
Al Viro8687b632006-10-19 23:28:48 -07003082static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083{
Al Viro8687b632006-10-19 23:28:48 -07003084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085
Benny Halevyc0eae662009-08-14 17:20:14 +03003086 p = xdr_inline_decode(xdr, 4);
3087 if (unlikely(!p))
3088 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003089 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 *savep = xdr->p;
3091 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003092out_overflow:
3093 print_overflow_msg(__func__, xdr);
3094 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095}
3096
3097static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3098{
3099 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003100 int ret;
3101 ret = decode_attr_bitmap(xdr, bitmask);
3102 if (unlikely(ret < 0))
3103 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3105 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003106 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3107 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3108 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 return 0;
3110}
3111
3112static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3113{
Al Viro8687b632006-10-19 23:28:48 -07003114 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003115 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
3117 *type = 0;
3118 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3119 return -EIO;
3120 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003121 p = xdr_inline_decode(xdr, 4);
3122 if (unlikely(!p))
3123 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003124 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003126 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 return -EIO;
3128 }
3129 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003130 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003132 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003133 return ret;
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
Chuck Lever264e6352012-03-01 17:02:05 -05003139static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3140 uint32_t *bitmap, uint32_t *type)
3141{
3142 __be32 *p;
3143
3144 *type = 0;
3145 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3146 return -EIO;
3147 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3148 p = xdr_inline_decode(xdr, 4);
3149 if (unlikely(!p))
3150 goto out_overflow;
3151 *type = be32_to_cpup(p);
3152 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3153 }
3154 dprintk("%s: expire type=0x%x\n", __func__, *type);
3155 return 0;
3156out_overflow:
3157 print_overflow_msg(__func__, xdr);
3158 return -EIO;
3159}
3160
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3162{
Al Viro8687b632006-10-19 23:28:48 -07003163 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003164 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
3166 *change = 0;
3167 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3168 return -EIO;
3169 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003170 p = xdr_inline_decode(xdr, 8);
3171 if (unlikely(!p))
3172 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003173 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003177 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003179 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003180out_overflow:
3181 print_overflow_msg(__func__, xdr);
3182 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183}
3184
3185static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3186{
Al Viro8687b632006-10-19 23:28:48 -07003187 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003188 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
3190 *size = 0;
3191 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3192 return -EIO;
3193 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003194 p = xdr_inline_decode(xdr, 8);
3195 if (unlikely(!p))
3196 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003197 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003199 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003201 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 return ret;
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
3208static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3209{
Al Viro8687b632006-10-19 23:28:48 -07003210 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
3212 *res = 0;
3213 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3214 return -EIO;
3215 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003216 p = xdr_inline_decode(xdr, 4);
3217 if (unlikely(!p))
3218 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003219 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3221 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003222 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003224out_overflow:
3225 print_overflow_msg(__func__, xdr);
3226 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227}
3228
3229static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3230{
Al Viro8687b632006-10-19 23:28:48 -07003231 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232
3233 *res = 0;
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3235 return -EIO;
3236 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003237 p = xdr_inline_decode(xdr, 4);
3238 if (unlikely(!p))
3239 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003240 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3242 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003243 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003245out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248}
3249
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003250static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251{
Al Viro8687b632006-10-19 23:28:48 -07003252 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003253 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255 fsid->major = 0;
3256 fsid->minor = 0;
3257 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3258 return -EIO;
3259 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003260 p = xdr_inline_decode(xdr, 16);
3261 if (unlikely(!p))
3262 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003263 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003264 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003266 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003268 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 (unsigned long long)fsid->major,
3270 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003271 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003272out_overflow:
3273 print_overflow_msg(__func__, xdr);
3274 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275}
3276
3277static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3278{
Al Viro8687b632006-10-19 23:28:48 -07003279 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
3281 *res = 60;
3282 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3283 return -EIO;
3284 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003285 p = xdr_inline_decode(xdr, 4);
3286 if (unlikely(!p))
3287 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003288 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3290 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003291 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003293out_overflow:
3294 print_overflow_msg(__func__, xdr);
3295 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296}
3297
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003298static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003299{
3300 __be32 *p;
3301
3302 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3303 return -EIO;
3304 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3305 p = xdr_inline_decode(xdr, 4);
3306 if (unlikely(!p))
3307 goto out_overflow;
3308 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003309 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003310 }
3311 return 0;
3312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
3315}
3316
3317static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3318{
3319 __be32 *p;
3320 int len;
3321
Trond Myklebust7ad07352010-10-23 15:34:20 -04003322 if (fh != NULL)
3323 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003324
3325 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3326 return -EIO;
3327 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3328 p = xdr_inline_decode(xdr, 4);
3329 if (unlikely(!p))
3330 goto out_overflow;
3331 len = be32_to_cpup(p);
3332 if (len > NFS4_FHSIZE)
3333 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003334 p = xdr_inline_decode(xdr, len);
3335 if (unlikely(!p))
3336 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003337 if (fh != NULL) {
3338 memcpy(fh->data, p, len);
3339 fh->size = len;
3340 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003341 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3342 }
3343 return 0;
3344out_overflow:
3345 print_overflow_msg(__func__, xdr);
3346 return -EIO;
3347}
3348
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3350{
Al Viro8687b632006-10-19 23:28:48 -07003351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
3353 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3354 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3355 return -EIO;
3356 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003357 p = xdr_inline_decode(xdr, 4);
3358 if (unlikely(!p))
3359 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003360 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3362 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003363 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 return 0;
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_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3371{
Al Viro8687b632006-10-19 23:28:48 -07003372 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003373 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374
3375 *fileid = 0;
3376 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3377 return -EIO;
3378 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
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, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003384 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003386 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003387 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003388out_overflow:
3389 print_overflow_msg(__func__, xdr);
3390 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391}
3392
Manoj Naik99baf622006-06-09 09:34:24 -04003393static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3394{
Al Viro8687b632006-10-19 23:28:48 -07003395 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003396 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003397
3398 *fileid = 0;
3399 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3400 return -EIO;
3401 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003402 p = xdr_inline_decode(xdr, 8);
3403 if (unlikely(!p))
3404 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003405 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003406 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003407 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003408 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003409 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003410 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003411out_overflow:
3412 print_overflow_msg(__func__, xdr);
3413 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003414}
3415
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3417{
Al Viro8687b632006-10-19 23:28:48 -07003418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 int status = 0;
3420
3421 *res = 0;
3422 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3423 return -EIO;
3424 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003425 p = xdr_inline_decode(xdr, 8);
3426 if (unlikely(!p))
3427 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003428 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3430 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003431 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003433out_overflow:
3434 print_overflow_msg(__func__, xdr);
3435 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436}
3437
3438static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3439{
Al Viro8687b632006-10-19 23:28:48 -07003440 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 int status = 0;
3442
3443 *res = 0;
3444 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3445 return -EIO;
3446 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003447 p = xdr_inline_decode(xdr, 8);
3448 if (unlikely(!p))
3449 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003450 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3452 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003453 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003455out_overflow:
3456 print_overflow_msg(__func__, xdr);
3457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458}
3459
3460static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3461{
Al Viro8687b632006-10-19 23:28:48 -07003462 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 int status = 0;
3464
3465 *res = 0;
3466 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3467 return -EIO;
3468 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 8);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3474 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003475 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003477out_overflow:
3478 print_overflow_msg(__func__, xdr);
3479 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480}
3481
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003482static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3483{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003484 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003485 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003486 int status = 0;
3487
Benny Halevyc0eae662009-08-14 17:20:14 +03003488 p = xdr_inline_decode(xdr, 4);
3489 if (unlikely(!p))
3490 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003491 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003492 if (n == 0)
3493 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003494 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003495 path->ncomponents = 0;
3496 while (path->ncomponents < n) {
3497 struct nfs4_string *component = &path->components[path->ncomponents];
3498 status = decode_opaque_inline(xdr, &component->len, &component->data);
3499 if (unlikely(status != 0))
3500 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003501 if (unlikely(nfs_debug & NFSDBG_XDR))
3502 pr_cont("%s%.*s ",
3503 (path->ncomponents != n ? "/ " : ""),
3504 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003505 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3506 path->ncomponents++;
3507 else {
3508 dprintk("cannot parse %d components in path\n", n);
3509 goto out_eio;
3510 }
3511 }
3512out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003513 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003514root_path:
3515/* a root pathname is sent as a zero component4 */
3516 path->ncomponents = 1;
3517 path->components[0].len=0;
3518 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003519 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003520 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003521out_eio:
3522 dprintk(" status %d", status);
3523 status = -EIO;
3524 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003525out_overflow:
3526 print_overflow_msg(__func__, xdr);
3527 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003528}
3529
3530static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003531{
3532 int n;
Al Viro8687b632006-10-19 23:28:48 -07003533 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003534 int status = -EIO;
3535
3536 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3537 goto out;
3538 status = 0;
3539 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3540 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003541 status = -EIO;
3542 /* Ignore borken servers that return unrequested attrs */
3543 if (unlikely(res == NULL))
3544 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003545 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003546 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003547 if (unlikely(status != 0))
3548 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003549 p = xdr_inline_decode(xdr, 4);
3550 if (unlikely(!p))
3551 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003552 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003553 if (n <= 0)
3554 goto out_eio;
3555 res->nlocations = 0;
3556 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003557 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003558 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003559
Benny Halevyc0eae662009-08-14 17:20:14 +03003560 p = xdr_inline_decode(xdr, 4);
3561 if (unlikely(!p))
3562 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003563 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003564
3565 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003566 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003567 while (loc->nservers < m) {
3568 struct nfs4_string *server = &loc->servers[loc->nservers];
3569 status = decode_opaque_inline(xdr, &server->len, &server->data);
3570 if (unlikely(status != 0))
3571 goto out_eio;
3572 dprintk("%s ", server->data);
3573 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3574 loc->nservers++;
3575 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003576 unsigned int i;
3577 dprintk("%s: using first %u of %u servers "
3578 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003579 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003580 NFS4_FS_LOCATION_MAXSERVERS,
3581 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003582 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003583 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003584 char *data;
3585 status = decode_opaque_inline(xdr, &len, &data);
3586 if (unlikely(status != 0))
3587 goto out_eio;
3588 }
3589 }
3590 }
3591 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003592 if (unlikely(status != 0))
3593 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003594 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003595 res->nlocations++;
3596 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003597 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003598 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003599out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003600 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003601 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003602out_overflow:
3603 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003604out_eio:
3605 status = -EIO;
3606 goto out;
3607}
3608
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3610{
Al Viro8687b632006-10-19 23:28:48 -07003611 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 int status = 0;
3613
3614 *res = 0;
3615 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3616 return -EIO;
3617 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003618 p = xdr_inline_decode(xdr, 8);
3619 if (unlikely(!p))
3620 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003621 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3623 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003624 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003626out_overflow:
3627 print_overflow_msg(__func__, xdr);
3628 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629}
3630
3631static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3632{
Al Viro8687b632006-10-19 23:28:48 -07003633 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 int status = 0;
3635
3636 *maxlink = 1;
3637 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3638 return -EIO;
3639 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003640 p = xdr_inline_decode(xdr, 4);
3641 if (unlikely(!p))
3642 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003643 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3645 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003646 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003648out_overflow:
3649 print_overflow_msg(__func__, xdr);
3650 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651}
3652
3653static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3654{
Al Viro8687b632006-10-19 23:28:48 -07003655 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 int status = 0;
3657
3658 *maxname = 1024;
3659 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3660 return -EIO;
3661 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003662 p = xdr_inline_decode(xdr, 4);
3663 if (unlikely(!p))
3664 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003665 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3667 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003668 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003670out_overflow:
3671 print_overflow_msg(__func__, xdr);
3672 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673}
3674
3675static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3676{
Al Viro8687b632006-10-19 23:28:48 -07003677 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 int status = 0;
3679
3680 *res = 1024;
3681 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3682 return -EIO;
3683 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3684 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003685 p = xdr_inline_decode(xdr, 8);
3686 if (unlikely(!p))
3687 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003688 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 if (maxread > 0x7FFFFFFF)
3690 maxread = 0x7FFFFFFF;
3691 *res = (uint32_t)maxread;
3692 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3693 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003694 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003696out_overflow:
3697 print_overflow_msg(__func__, xdr);
3698 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699}
3700
3701static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3702{
Al Viro8687b632006-10-19 23:28:48 -07003703 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 int status = 0;
3705
3706 *res = 1024;
3707 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3708 return -EIO;
3709 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3710 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003711 p = xdr_inline_decode(xdr, 8);
3712 if (unlikely(!p))
3713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003714 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 if (maxwrite > 0x7FFFFFFF)
3716 maxwrite = 0x7FFFFFFF;
3717 *res = (uint32_t)maxwrite;
3718 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3719 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003720 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003722out_overflow:
3723 print_overflow_msg(__func__, xdr);
3724 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725}
3726
Trond Myklebustbca79472009-03-11 14:10:26 -04003727static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728{
Trond Myklebustbca79472009-03-11 14:10:26 -04003729 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003730 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003731 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732
3733 *mode = 0;
3734 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3735 return -EIO;
3736 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003737 p = xdr_inline_decode(xdr, 4);
3738 if (unlikely(!p))
3739 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003740 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003741 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003743 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003746 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003747out_overflow:
3748 print_overflow_msg(__func__, xdr);
3749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750}
3751
3752static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3753{
Al Viro8687b632006-10-19 23:28:48 -07003754 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003755 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756
3757 *nlink = 1;
3758 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3759 return -EIO;
3760 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003761 p = xdr_inline_decode(xdr, 4);
3762 if (unlikely(!p))
3763 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003764 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003766 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003768 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003769 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003770out_overflow:
3771 print_overflow_msg(__func__, xdr);
3772 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773}
3774
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003775static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003776 const struct nfs_server *server, uint32_t *uid,
3777 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778{
Al Viro8687b632006-10-19 23:28:48 -07003779 uint32_t len;
3780 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
3783 *uid = -2;
3784 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3785 return -EIO;
3786 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003787 p = xdr_inline_decode(xdr, 4);
3788 if (unlikely(!p))
3789 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003790 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003791 p = xdr_inline_decode(xdr, len);
3792 if (unlikely(!p))
3793 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003794 if (owner_name != NULL) {
3795 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3796 if (owner_name->data != NULL) {
3797 owner_name->len = len;
3798 ret = NFS_ATTR_FATTR_OWNER_NAME;
3799 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003800 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003801 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003802 ret = NFS_ATTR_FATTR_OWNER;
3803 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003807 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003808 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3810 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003811 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003812 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003813out_overflow:
3814 print_overflow_msg(__func__, xdr);
3815 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816}
3817
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003818static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003819 const struct nfs_server *server, uint32_t *gid,
3820 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821{
Al Viro8687b632006-10-19 23:28:48 -07003822 uint32_t len;
3823 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003824 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
3826 *gid = -2;
3827 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3828 return -EIO;
3829 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003830 p = xdr_inline_decode(xdr, 4);
3831 if (unlikely(!p))
3832 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003833 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003834 p = xdr_inline_decode(xdr, len);
3835 if (unlikely(!p))
3836 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003837 if (group_name != NULL) {
3838 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3839 if (group_name->data != NULL) {
3840 group_name->len = len;
3841 ret = NFS_ATTR_FATTR_GROUP_NAME;
3842 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003843 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003844 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003845 ret = NFS_ATTR_FATTR_GROUP;
3846 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003848 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003850 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003851 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3853 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003854 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003855 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003856out_overflow:
3857 print_overflow_msg(__func__, xdr);
3858 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859}
3860
3861static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3862{
Al Viro8687b632006-10-19 23:28:48 -07003863 uint32_t major = 0, minor = 0;
3864 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003865 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
3867 *rdev = MKDEV(0,0);
3868 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3869 return -EIO;
3870 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3871 dev_t tmp;
3872
Benny Halevyc0eae662009-08-14 17:20:14 +03003873 p = xdr_inline_decode(xdr, 8);
3874 if (unlikely(!p))
3875 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003876 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003877 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 tmp = MKDEV(major, minor);
3879 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3880 *rdev = tmp;
3881 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003882 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003884 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
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_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3892{
Al Viro8687b632006-10-19 23:28:48 -07003893 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 int status = 0;
3895
3896 *res = 0;
3897 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3898 return -EIO;
3899 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003900 p = xdr_inline_decode(xdr, 8);
3901 if (unlikely(!p))
3902 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003903 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3905 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003906 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003908out_overflow:
3909 print_overflow_msg(__func__, xdr);
3910 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911}
3912
3913static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3914{
Al Viro8687b632006-10-19 23:28:48 -07003915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 int status = 0;
3917
3918 *res = 0;
3919 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3920 return -EIO;
3921 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003922 p = xdr_inline_decode(xdr, 8);
3923 if (unlikely(!p))
3924 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003925 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3927 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003928 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003930out_overflow:
3931 print_overflow_msg(__func__, xdr);
3932 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933}
3934
3935static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3936{
Al Viro8687b632006-10-19 23:28:48 -07003937 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 int status = 0;
3939
3940 *res = 0;
3941 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3942 return -EIO;
3943 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003944 p = xdr_inline_decode(xdr, 8);
3945 if (unlikely(!p))
3946 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003947 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3949 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003950 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003952out_overflow:
3953 print_overflow_msg(__func__, xdr);
3954 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955}
3956
3957static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3958{
Al Viro8687b632006-10-19 23:28:48 -07003959 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003960 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
3962 *used = 0;
3963 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3964 return -EIO;
3965 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003966 p = xdr_inline_decode(xdr, 8);
3967 if (unlikely(!p))
3968 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003969 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003971 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003973 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003975 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003976out_overflow:
3977 print_overflow_msg(__func__, xdr);
3978 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979}
3980
3981static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3982{
Al Viro8687b632006-10-19 23:28:48 -07003983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 uint64_t sec;
3985 uint32_t nsec;
3986
Benny Halevyc0eae662009-08-14 17:20:14 +03003987 p = xdr_inline_decode(xdr, 12);
3988 if (unlikely(!p))
3989 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003990 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003991 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 time->tv_sec = (time_t)sec;
3993 time->tv_nsec = (long)nsec;
3994 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003995out_overflow:
3996 print_overflow_msg(__func__, xdr);
3997 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998}
3999
4000static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4001{
4002 int status = 0;
4003
4004 time->tv_sec = 0;
4005 time->tv_nsec = 0;
4006 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4007 return -EIO;
4008 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4009 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004010 if (status == 0)
4011 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4013 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004014 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 return status;
4016}
4017
4018static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4019{
4020 int status = 0;
4021
4022 time->tv_sec = 0;
4023 time->tv_nsec = 0;
4024 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4025 return -EIO;
4026 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4027 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004028 if (status == 0)
4029 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4031 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004032 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 return status;
4034}
4035
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004036static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4037 struct timespec *time)
4038{
4039 int status = 0;
4040
4041 time->tv_sec = 0;
4042 time->tv_nsec = 0;
4043 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4044 return -EIO;
4045 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4046 status = decode_attr_time(xdr, time);
4047 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4048 }
4049 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4050 (long)time->tv_nsec);
4051 return status;
4052}
4053
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4055{
4056 int status = 0;
4057
4058 time->tv_sec = 0;
4059 time->tv_nsec = 0;
4060 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4061 return -EIO;
4062 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4063 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004064 if (status == 0)
4065 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4067 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004068 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 return status;
4070}
4071
Al Viro8687b632006-10-19 23:28:48 -07004072static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073{
4074 unsigned int attrwords = XDR_QUADLEN(attrlen);
4075 unsigned int nwords = xdr->p - savep;
4076
4077 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004078 dprintk("%s: server returned incorrect attribute length: "
4079 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004080 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 attrwords << 2,
4082 (attrwords < nwords) ? '<' : '>',
4083 nwords << 2);
4084 return -EIO;
4085 }
4086 return 0;
4087}
4088
4089static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4090{
Al Viro8687b632006-10-19 23:28:48 -07004091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092
Benny Halevyc0eae662009-08-14 17:20:14 +03004093 p = xdr_inline_decode(xdr, 20);
4094 if (unlikely(!p))
4095 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004096 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004097 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004098 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004100out_overflow:
4101 print_overflow_msg(__func__, xdr);
4102 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103}
4104
4105static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4106{
Al Viro8687b632006-10-19 23:28:48 -07004107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 uint32_t supp, acc;
4109 int status;
4110
4111 status = decode_op_hdr(xdr, OP_ACCESS);
4112 if (status)
4113 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004114 p = xdr_inline_decode(xdr, 8);
4115 if (unlikely(!p))
4116 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004117 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004118 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 access->supported = supp;
4120 access->access = acc;
4121 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004122out_overflow:
4123 print_overflow_msg(__func__, xdr);
4124 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125}
4126
Benny Halevy07d30432009-08-14 17:19:52 +03004127static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128{
Al Viro8687b632006-10-19 23:28:48 -07004129 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004130
4131 p = xdr_inline_decode(xdr, len);
4132 if (likely(p)) {
4133 memcpy(buf, p, len);
4134 return 0;
4135 }
4136 print_overflow_msg(__func__, xdr);
4137 return -EIO;
4138}
4139
4140static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4141{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004142 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143}
4144
4145static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 int status;
4148
4149 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004150 if (status != -EIO)
4151 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004152 if (!status)
4153 status = decode_stateid(xdr, &res->stateid);
4154 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155}
4156
Benny Halevydb942bb2009-08-14 17:19:56 +03004157static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4158{
Chuck Levercd937102012-03-02 17:14:31 -05004159 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160}
4161
4162static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4163{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 int status;
4165
4166 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004167 if (!status)
4168 status = decode_verifier(xdr, res->verf->verifier);
4169 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170}
4171
4172static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4173{
Al Viro8687b632006-10-19 23:28:48 -07004174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 uint32_t bmlen;
4176 int status;
4177
4178 status = decode_op_hdr(xdr, OP_CREATE);
4179 if (status)
4180 return status;
4181 if ((status = decode_change_info(xdr, cinfo)))
4182 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004183 p = xdr_inline_decode(xdr, 4);
4184 if (unlikely(!p))
4185 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004186 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004187 p = xdr_inline_decode(xdr, bmlen << 2);
4188 if (likely(p))
4189 return 0;
4190out_overflow:
4191 print_overflow_msg(__func__, xdr);
4192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193}
4194
4195static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4196{
Al Viro8687b632006-10-19 23:28:48 -07004197 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004198 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 int status;
4200
4201 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4202 goto xdr_error;
4203 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4204 goto xdr_error;
4205 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4206 goto xdr_error;
4207 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4208 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004209 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4210 &res->fh_expire_type)) != 0)
4211 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4213 goto xdr_error;
4214 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4215 goto xdr_error;
4216 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4217 goto xdr_error;
4218 status = verify_attr_len(xdr, savep, attrlen);
4219xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004220 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 return status;
4222}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004223
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4225{
Al Viro8687b632006-10-19 23:28:48 -07004226 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004227 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4231 goto xdr_error;
4232 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4233 goto xdr_error;
4234 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4235 goto xdr_error;
4236
4237 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4238 goto xdr_error;
4239 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4240 goto xdr_error;
4241 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4242 goto xdr_error;
4243 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4244 goto xdr_error;
4245 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4246 goto xdr_error;
4247 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4248 goto xdr_error;
4249
4250 status = verify_attr_len(xdr, savep, attrlen);
4251xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004252 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 return status;
4254}
4255
4256static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4257{
Al Viro8687b632006-10-19 23:28:48 -07004258 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004259 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004261
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4263 goto xdr_error;
4264 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4265 goto xdr_error;
4266 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4267 goto xdr_error;
4268
4269 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4270 goto xdr_error;
4271 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4272 goto xdr_error;
4273
4274 status = verify_attr_len(xdr, savep, attrlen);
4275xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004276 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 return status;
4278}
4279
Bryan Schumakerae42c702010-10-21 16:33:17 -04004280static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4281 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004282 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004283 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284{
Trond Myklebustbca79472009-03-11 14:10:26 -04004285 int status;
4286 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004287 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004288 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004290 status = decode_attr_type(xdr, bitmap, &type);
4291 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004293 fattr->mode = 0;
4294 if (status != 0) {
4295 fattr->mode |= nfs_type2fmt[type];
4296 fattr->valid |= status;
4297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004299 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4300 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004302 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004303
4304 status = decode_attr_size(xdr, bitmap, &fattr->size);
4305 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004307 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004308
4309 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4310 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004312 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004313
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004314 err = 0;
4315 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004316 if (status < 0)
4317 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004318 if (err == -NFS4ERR_WRONGSEC)
4319 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004320
4321 status = decode_attr_filehandle(xdr, bitmap, fh);
4322 if (status < 0)
4323 goto xdr_error;
4324
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004325 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4326 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004328 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004329
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004330 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004331 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004332 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004333 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004334
4335 status = decode_attr_mode(xdr, bitmap, &fmode);
4336 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004338 if (status != 0) {
4339 fattr->mode |= fmode;
4340 fattr->valid |= status;
4341 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004342
4343 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4344 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004346 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004347
Trond Myklebust6926afd2012-01-07 13:22:46 -05004348 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004349 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004351 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004352
Trond Myklebust6926afd2012-01-07 13:22:46 -05004353 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004354 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004356 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004357
4358 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4359 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004361 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004362
4363 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4364 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004366 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004367
4368 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4369 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004371 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004372
4373 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4374 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004376 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004377
4378 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4379 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004381 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004382
Trond Myklebust28331a42011-04-27 13:47:52 -04004383 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004384 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004385 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004386 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004387
Bryan Schumakerae42c702010-10-21 16:33:17 -04004388xdr_error:
4389 dprintk("%s: xdr returned %d\n", __func__, -status);
4390 return status;
4391}
4392
4393static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004394 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4395 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004396{
4397 __be32 *savep;
4398 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004399 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004400 int status;
4401
4402 status = decode_op_hdr(xdr, OP_GETATTR);
4403 if (status < 0)
4404 goto xdr_error;
4405
4406 status = decode_attr_bitmap(xdr, bitmap);
4407 if (status < 0)
4408 goto xdr_error;
4409
4410 status = decode_attr_length(xdr, &attrlen, &savep);
4411 if (status < 0)
4412 goto xdr_error;
4413
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004414 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004415 if (status < 0)
4416 goto xdr_error;
4417
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004418 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004420 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 return status;
4422}
4423
Bryan Schumakerae42c702010-10-21 16:33:17 -04004424static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004425 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004426{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004427 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004428}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429
Andy Adamson504913f2010-10-20 00:17:57 -04004430/*
4431 * Decode potentially multiple layout types. Currently we only support
4432 * one layout driver per file system.
4433 */
4434static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4435 uint32_t *layouttype)
4436{
4437 uint32_t *p;
4438 int num;
4439
4440 p = xdr_inline_decode(xdr, 4);
4441 if (unlikely(!p))
4442 goto out_overflow;
4443 num = be32_to_cpup(p);
4444
4445 /* pNFS is not supported by the underlying file system */
4446 if (num == 0) {
4447 *layouttype = 0;
4448 return 0;
4449 }
4450 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004451 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4452 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004453
4454 /* Decode and set first layout type, move xdr->p past unused types */
4455 p = xdr_inline_decode(xdr, num * 4);
4456 if (unlikely(!p))
4457 goto out_overflow;
4458 *layouttype = be32_to_cpup(p);
4459 return 0;
4460out_overflow:
4461 print_overflow_msg(__func__, xdr);
4462 return -EIO;
4463}
4464
4465/*
4466 * The type of file system exported.
4467 * Note we must ensure that layouttype is set in any non-error case.
4468 */
4469static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4470 uint32_t *layouttype)
4471{
4472 int status = 0;
4473
4474 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4475 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4476 return -EIO;
4477 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4478 status = decode_first_pnfs_layout_type(xdr, layouttype);
4479 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4480 } else
4481 *layouttype = 0;
4482 return status;
4483}
4484
Fred Isamandae100c2011-07-30 20:52:37 -04004485/*
4486 * The prefered block size for layout directed io
4487 */
4488static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4489 uint32_t *res)
4490{
4491 __be32 *p;
4492
4493 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4494 *res = 0;
4495 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4496 p = xdr_inline_decode(xdr, 4);
4497 if (unlikely(!p)) {
4498 print_overflow_msg(__func__, xdr);
4499 return -EIO;
4500 }
4501 *res = be32_to_cpup(p);
4502 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4503 }
4504 return 0;
4505}
4506
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4508{
Al Viro8687b632006-10-19 23:28:48 -07004509 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004510 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 int status;
4512
4513 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4514 goto xdr_error;
4515 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4516 goto xdr_error;
4517 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4518 goto xdr_error;
4519
4520 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4521
4522 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4523 goto xdr_error;
4524 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4525 goto xdr_error;
4526 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4527 goto xdr_error;
4528 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4529 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4530 goto xdr_error;
4531 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004532 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4533 if (status != 0)
4534 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004535 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4536 if (status != 0)
4537 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004538 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4539 if (status)
4540 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541
4542 status = verify_attr_len(xdr, savep, attrlen);
4543xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004544 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 return status;
4546}
4547
4548static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4549{
Al Viro8687b632006-10-19 23:28:48 -07004550 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 uint32_t len;
4552 int status;
4553
Trond Myklebust99367812007-07-17 21:52:41 -04004554 /* Zero handle first to allow comparisons */
4555 memset(fh, 0, sizeof(*fh));
4556
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 status = decode_op_hdr(xdr, OP_GETFH);
4558 if (status)
4559 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560
Benny Halevyc0eae662009-08-14 17:20:14 +03004561 p = xdr_inline_decode(xdr, 4);
4562 if (unlikely(!p))
4563 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004564 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 if (len > NFS4_FHSIZE)
4566 return -EIO;
4567 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004568 p = xdr_inline_decode(xdr, len);
4569 if (unlikely(!p))
4570 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004571 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004573out_overflow:
4574 print_overflow_msg(__func__, xdr);
4575 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576}
4577
4578static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4579{
4580 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004581
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 status = decode_op_hdr(xdr, OP_LINK);
4583 if (status)
4584 return status;
4585 return decode_change_info(xdr, cinfo);
4586}
4587
4588/*
4589 * We create the owner, so we know a proper owner.id length is 4.
4590 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004591static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004593 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004594 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004595 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004597 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004598 if (unlikely(!p))
4599 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004600 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004601 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004602 type = be32_to_cpup(p++); /* 4 byte read */
4603 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004604 fl->fl_start = (loff_t)offset;
4605 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4606 if (length == ~(uint64_t)0)
4607 fl->fl_end = OFFSET_MAX;
4608 fl->fl_type = F_WRLCK;
4609 if (type & 1)
4610 fl->fl_type = F_RDLCK;
4611 fl->fl_pid = 0;
4612 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004613 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4614 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4615 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004616 if (likely(p))
4617 return -NFS4ERR_DENIED;
4618out_overflow:
4619 print_overflow_msg(__func__, xdr);
4620 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621}
4622
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004623static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 int status;
4626
4627 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004628 if (status == -EIO)
4629 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004631 status = decode_stateid(xdr, &res->stateid);
4632 if (unlikely(status))
4633 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004635 status = decode_lock_denied(xdr, NULL);
4636 if (res->open_seqid != NULL)
4637 nfs_increment_open_seqid(status, res->open_seqid);
4638 nfs_increment_lock_seqid(status, res->lock_seqid);
4639out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 return status;
4641}
4642
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004643static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644{
4645 int status;
4646 status = decode_op_hdr(xdr, OP_LOCKT);
4647 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004648 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 return status;
4650}
4651
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004652static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 int status;
4655
4656 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004657 if (status != -EIO)
4658 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004659 if (status == 0)
4660 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 return status;
4662}
4663
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004664static int decode_release_lockowner(struct xdr_stream *xdr)
4665{
4666 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4667}
4668
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669static int decode_lookup(struct xdr_stream *xdr)
4670{
4671 return decode_op_hdr(xdr, OP_LOOKUP);
4672}
4673
4674/* This is too sick! */
4675static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4676{
Andy Adamson05d564f2008-12-23 16:06:15 -05004677 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678 uint32_t limit_type, nblocks, blocksize;
4679
Benny Halevyc0eae662009-08-14 17:20:14 +03004680 p = xdr_inline_decode(xdr, 12);
4681 if (unlikely(!p))
4682 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004683 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004685 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004686 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004687 break;
4688 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004689 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004690 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004691 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 }
4693 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004694out_overflow:
4695 print_overflow_msg(__func__, xdr);
4696 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697}
4698
4699static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4700{
Andy Adamson05d564f2008-12-23 16:06:15 -05004701 __be32 *p;
4702 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004703 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704
Benny Halevyc0eae662009-08-14 17:20:14 +03004705 p = xdr_inline_decode(xdr, 4);
4706 if (unlikely(!p))
4707 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004708 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4710 res->delegation_type = 0;
4711 return 0;
4712 }
Benny Halevy07d30432009-08-14 17:19:52 +03004713 status = decode_stateid(xdr, &res->delegation);
4714 if (unlikely(status))
4715 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004716 p = xdr_inline_decode(xdr, 4);
4717 if (unlikely(!p))
4718 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004719 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004720
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004722 case NFS4_OPEN_DELEGATE_READ:
4723 res->delegation_type = FMODE_READ;
4724 break;
4725 case NFS4_OPEN_DELEGATE_WRITE:
4726 res->delegation_type = FMODE_WRITE|FMODE_READ;
4727 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 return -EIO;
4729 }
David Howells7539bba2006-08-22 20:06:09 -04004730 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004731out_overflow:
4732 print_overflow_msg(__func__, xdr);
4733 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734}
4735
4736static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4737{
Andy Adamson05d564f2008-12-23 16:06:15 -05004738 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004739 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004740 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741
Andy Adamson05d564f2008-12-23 16:06:15 -05004742 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004743 if (status != -EIO)
4744 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004745 if (!status)
4746 status = decode_stateid(xdr, &res->stateid);
4747 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004748 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749
Andy Adamson05d564f2008-12-23 16:06:15 -05004750 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751
Benny Halevyc0eae662009-08-14 17:20:14 +03004752 p = xdr_inline_decode(xdr, 8);
4753 if (unlikely(!p))
4754 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004755 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004756 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004757 if (bmlen > 10)
4758 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759
Benny Halevyc0eae662009-08-14 17:20:14 +03004760 p = xdr_inline_decode(xdr, bmlen << 2);
4761 if (unlikely(!p))
4762 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004763 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4764 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004765 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004766 for (; i < NFS4_BITMAP_SIZE; i++)
4767 res->attrset[i] = 0;
4768
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 return decode_delegation(xdr, res);
4770xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004771 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004773out_overflow:
4774 print_overflow_msg(__func__, xdr);
4775 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776}
4777
4778static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4779{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 int status;
4781
Andy Adamson05d564f2008-12-23 16:06:15 -05004782 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004783 if (status != -EIO)
4784 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004785 if (!status)
4786 status = decode_stateid(xdr, &res->stateid);
4787 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788}
4789
4790static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4791{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 int status;
4793
4794 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004795 if (status != -EIO)
4796 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004797 if (!status)
4798 status = decode_stateid(xdr, &res->stateid);
4799 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800}
4801
4802static int decode_putfh(struct xdr_stream *xdr)
4803{
4804 return decode_op_hdr(xdr, OP_PUTFH);
4805}
4806
4807static int decode_putrootfh(struct xdr_stream *xdr)
4808{
4809 return decode_op_hdr(xdr, OP_PUTROOTFH);
4810}
4811
4812static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4813{
4814 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 uint32_t count, eof, recvd, hdrlen;
4817 int status;
4818
4819 status = decode_op_hdr(xdr, OP_READ);
4820 if (status)
4821 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004822 p = xdr_inline_decode(xdr, 8);
4823 if (unlikely(!p))
4824 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004825 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004826 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004827 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828 recvd = req->rq_rcv_buf.len - hdrlen;
4829 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004830 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 "count %u > recvd %u\n", count, recvd);
4832 count = recvd;
4833 eof = 0;
4834 }
4835 xdr_read_pages(xdr, count);
4836 res->eof = eof;
4837 res->count = count;
4838 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004839out_overflow:
4840 print_overflow_msg(__func__, xdr);
4841 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842}
4843
4844static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4845{
4846 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004848 size_t hdrlen;
4849 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004850 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004851 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852
4853 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004854 if (!status)
4855 status = decode_verifier(xdr, readdir->verifier.data);
4856 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004858 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004859 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004860 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861
Benny Halevydb942bb2009-08-14 17:19:56 +03004862 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 recvd = rcvbuf->len - hdrlen;
4864 if (pglen > recvd)
4865 pglen = recvd;
4866 xdr_read_pages(xdr, pglen);
4867
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004868
Trond Myklebustac396122010-11-15 20:26:22 -05004869 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870}
4871
4872static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4873{
4874 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4875 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004876 size_t hdrlen;
4877 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004878 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 int status;
4880
4881 status = decode_op_hdr(xdr, OP_READLINK);
4882 if (status)
4883 return status;
4884
4885 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004886 p = xdr_inline_decode(xdr, 4);
4887 if (unlikely(!p))
4888 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004889 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004891 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 return -ENAMETOOLONG;
4893 }
4894 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4895 recvd = req->rq_rcv_buf.len - hdrlen;
4896 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004897 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 "count %u > recvd %u\n", len, recvd);
4899 return -EIO;
4900 }
4901 xdr_read_pages(xdr, len);
4902 /*
4903 * The XDR encode routine has set things up so that
4904 * the link text will be copied directly into the
4905 * buffer. We just have to do overflow-checking,
4906 * and and null-terminate the text (the VFS expects
4907 * null-termination).
4908 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004909 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004911out_overflow:
4912 print_overflow_msg(__func__, xdr);
4913 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914}
4915
4916static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4917{
4918 int status;
4919
4920 status = decode_op_hdr(xdr, OP_REMOVE);
4921 if (status)
4922 goto out;
4923 status = decode_change_info(xdr, cinfo);
4924out:
4925 return status;
4926}
4927
4928static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4929 struct nfs4_change_info *new_cinfo)
4930{
4931 int status;
4932
4933 status = decode_op_hdr(xdr, OP_RENAME);
4934 if (status)
4935 goto out;
4936 if ((status = decode_change_info(xdr, old_cinfo)))
4937 goto out;
4938 status = decode_change_info(xdr, new_cinfo);
4939out:
4940 return status;
4941}
4942
4943static int decode_renew(struct xdr_stream *xdr)
4944{
4945 return decode_op_hdr(xdr, OP_RENEW);
4946}
4947
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004948static int
4949decode_restorefh(struct xdr_stream *xdr)
4950{
4951 return decode_op_hdr(xdr, OP_RESTOREFH);
4952}
4953
J. Bruce Fields029d1052005-06-22 17:16:22 +00004954static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004955 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004956{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004957 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004958 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004959 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004960 struct kvec *iov = req->rq_rcv_buf.head;
4961 int status;
4962
Andy Adamsonbf118a32011-12-07 11:55:27 -05004963 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004964 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4965 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004966 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004967 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4968 goto out;
4969 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4970 goto out;
4971
4972 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4973 return -EIO;
4974 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004975 size_t hdrlen;
4976 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004977
Andy Adamsonbf118a32011-12-07 11:55:27 -05004978 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4979 * are stored with the acl data to handle the problem of
4980 * variable length bitmaps.*/
4981 xdr->p = bm_p;
4982 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4983 res->acl_data_offset <<= 2;
4984
J. Bruce Fields029d1052005-06-22 17:16:22 +00004985 /* We ignore &savep and don't do consistency checks on
4986 * the attr length. Let userspace figure it out.... */
4987 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004988 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004989 recvd = req->rq_rcv_buf.len - hdrlen;
4990 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004991 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4992 /* getxattr interface called with a NULL buf */
4993 res->acl_len = attrlen;
4994 goto out;
4995 }
4996 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00004997 attrlen, recvd);
4998 return -EINVAL;
4999 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005000 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005001 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005002 } else
5003 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005004
5005out:
5006 return status;
5007}
5008
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009static int
5010decode_savefh(struct xdr_stream *xdr)
5011{
5012 return decode_op_hdr(xdr, OP_SAVEFH);
5013}
5014
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005015static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016{
Al Viro8687b632006-10-19 23:28:48 -07005017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 uint32_t bmlen;
5019 int status;
5020
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 status = decode_op_hdr(xdr, OP_SETATTR);
5022 if (status)
5023 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005024 p = xdr_inline_decode(xdr, 4);
5025 if (unlikely(!p))
5026 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005027 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005028 p = xdr_inline_decode(xdr, bmlen << 2);
5029 if (likely(p))
5030 return 0;
5031out_overflow:
5032 print_overflow_msg(__func__, xdr);
5033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034}
5035
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005036static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037{
Al Viro8687b632006-10-19 23:28:48 -07005038 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039 uint32_t opnum;
5040 int32_t nfserr;
5041
Benny Halevyc0eae662009-08-14 17:20:14 +03005042 p = xdr_inline_decode(xdr, 8);
5043 if (unlikely(!p))
5044 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005045 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005047 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005048 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 return -EIO;
5050 }
Benny Halevycccddf42009-08-14 17:20:19 +03005051 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005053 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5054 if (unlikely(!p))
5055 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005056 p = xdr_decode_hyper(p, &res->clientid);
5057 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 } else if (nfserr == NFSERR_CLID_INUSE) {
5059 uint32_t len;
5060
5061 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005062 p = xdr_inline_decode(xdr, 4);
5063 if (unlikely(!p))
5064 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005065 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005066 p = xdr_inline_decode(xdr, len);
5067 if (unlikely(!p))
5068 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069
5070 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005071 p = xdr_inline_decode(xdr, 4);
5072 if (unlikely(!p))
5073 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005074 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005075 p = xdr_inline_decode(xdr, len);
5076 if (unlikely(!p))
5077 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 return -NFSERR_CLID_INUSE;
5079 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005080 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081
5082 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005083out_overflow:
5084 print_overflow_msg(__func__, xdr);
5085 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086}
5087
5088static int decode_setclientid_confirm(struct xdr_stream *xdr)
5089{
5090 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5091}
5092
5093static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5094{
Al Viro8687b632006-10-19 23:28:48 -07005095 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 int status;
5097
5098 status = decode_op_hdr(xdr, OP_WRITE);
5099 if (status)
5100 return status;
5101
Benny Halevyc0eae662009-08-14 17:20:14 +03005102 p = xdr_inline_decode(xdr, 16);
5103 if (unlikely(!p))
5104 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005105 res->count = be32_to_cpup(p++);
5106 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005107 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005109out_overflow:
5110 print_overflow_msg(__func__, xdr);
5111 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112}
5113
5114static int decode_delegreturn(struct xdr_stream *xdr)
5115{
5116 return decode_op_hdr(xdr, OP_DELEGRETURN);
5117}
5118
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005119static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5120{
5121 __be32 *p;
5122
5123 p = xdr_inline_decode(xdr, 4);
5124 if (unlikely(!p))
5125 goto out_overflow;
5126 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5127 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5128 goto out_err;
5129
5130 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5131 if (unlikely(!p))
5132 goto out_overflow;
5133 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5134
5135 p = xdr_inline_decode(xdr, 8);
5136 if (unlikely(!p))
5137 goto out_overflow;
5138 flavor->gss.qop4 = be32_to_cpup(p++);
5139 flavor->gss.service = be32_to_cpup(p);
5140
5141 return 0;
5142
5143out_overflow:
5144 print_overflow_msg(__func__, xdr);
5145 return -EIO;
5146out_err:
5147 return -EINVAL;
5148}
5149
5150static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5151{
5152 struct nfs4_secinfo_flavor *sec_flavor;
5153 int status;
5154 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005155 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005156
5157 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005158 if (status)
5159 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005160 p = xdr_inline_decode(xdr, 4);
5161 if (unlikely(!p))
5162 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005163
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005164 res->flavors->num_flavors = 0;
5165 num_flavors = be32_to_cpup(p);
5166
5167 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005168 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005169 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005170 break;
5171
5172 p = xdr_inline_decode(xdr, 4);
5173 if (unlikely(!p))
5174 goto out_overflow;
5175 sec_flavor->flavor = be32_to_cpup(p);
5176
5177 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005178 status = decode_secinfo_gss(xdr, sec_flavor);
5179 if (status)
5180 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005181 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005182 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005183 }
5184
Bryan Schumaker613e9012011-04-27 15:28:44 -04005185out:
5186 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005187out_overflow:
5188 print_overflow_msg(__func__, xdr);
5189 return -EIO;
5190}
5191
Benny Halevy99fe60d2009-04-01 09:22:29 -04005192#if defined(CONFIG_NFS_V4_1)
5193static int decode_exchange_id(struct xdr_stream *xdr,
5194 struct nfs41_exchange_id_res *res)
5195{
5196 __be32 *p;
5197 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005198 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005199 int status;
5200 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005201 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005202
5203 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5204 if (status)
5205 return status;
5206
Benny Halevyc0eae662009-08-14 17:20:14 +03005207 p = xdr_inline_decode(xdr, 8);
5208 if (unlikely(!p))
5209 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005210 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005211 p = xdr_inline_decode(xdr, 12);
5212 if (unlikely(!p))
5213 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005214 clp->cl_seqid = be32_to_cpup(p++);
5215 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005216
5217 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005218 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005219 if (dummy != SP4_NONE)
5220 return -EIO;
5221
5222 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005223 p = xdr_inline_decode(xdr, 8);
5224 if (unlikely(!p))
5225 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005226
5227 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005228 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5229 if (unlikely(status))
5230 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005231
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005232 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005233 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5234 if (unlikely(status))
5235 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005236
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005237 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5238 return -EIO;
5239
5240 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5241 res->server_scope->server_scope_sz = dummy;
5242
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005243 /* Implementation Id */
5244 p = xdr_inline_decode(xdr, 4);
5245 if (unlikely(!p))
5246 goto out_overflow;
5247 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005248
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005249 if (impl_id_count) {
5250 /* nii_domain */
5251 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5252 if (unlikely(status))
5253 return status;
5254 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5255 return -EIO;
5256 memcpy(res->impl_id->domain, dummy_str, dummy);
5257
5258 /* nii_name */
5259 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5260 if (unlikely(status))
5261 return status;
5262 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5263 return -EIO;
5264 memcpy(res->impl_id->name, dummy_str, dummy);
5265
5266 /* nii_date */
5267 p = xdr_inline_decode(xdr, 12);
5268 if (unlikely(!p))
5269 goto out_overflow;
5270 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5271 res->impl_id->date.nseconds = be32_to_cpup(p);
5272
5273 /* if there's more than one entry, ignore the rest */
5274 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005275 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005276out_overflow:
5277 print_overflow_msg(__func__, xdr);
5278 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005279}
Andy Adamsonfc931582009-04-01 09:22:31 -04005280
5281static int decode_chan_attrs(struct xdr_stream *xdr,
5282 struct nfs4_channel_attrs *attrs)
5283{
5284 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005285 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005286
Benny Halevyc0eae662009-08-14 17:20:14 +03005287 p = xdr_inline_decode(xdr, 28);
5288 if (unlikely(!p))
5289 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005290 val = be32_to_cpup(p++); /* headerpadsz */
5291 if (val)
5292 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005293 attrs->max_rqst_sz = be32_to_cpup(p++);
5294 attrs->max_resp_sz = be32_to_cpup(p++);
5295 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5296 attrs->max_ops = be32_to_cpup(p++);
5297 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005298 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005299 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005300 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5301 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005302 return -EINVAL;
5303 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005304 if (nr_attrs == 1) {
5305 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5306 if (unlikely(!p))
5307 goto out_overflow;
5308 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005309 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005310out_overflow:
5311 print_overflow_msg(__func__, xdr);
5312 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005313}
5314
Benny Halevye78291e2009-08-14 17:20:00 +03005315static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5316{
5317 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005318}
5319
5320static int decode_create_session(struct xdr_stream *xdr,
5321 struct nfs41_create_session_res *res)
5322{
5323 __be32 *p;
5324 int status;
5325 struct nfs_client *clp = res->client;
5326 struct nfs4_session *session = clp->cl_session;
5327
5328 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005329 if (!status)
5330 status = decode_sessionid(xdr, &session->sess_id);
5331 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005332 return status;
5333
Andy Adamsonfc931582009-04-01 09:22:31 -04005334 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005335 p = xdr_inline_decode(xdr, 8);
5336 if (unlikely(!p))
5337 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005338 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005339 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005340
5341 /* Channel attributes */
5342 status = decode_chan_attrs(xdr, &session->fc_attrs);
5343 if (!status)
5344 status = decode_chan_attrs(xdr, &session->bc_attrs);
5345 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005346out_overflow:
5347 print_overflow_msg(__func__, xdr);
5348 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005349}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005350
5351static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5352{
5353 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5354}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005355
5356static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5357{
5358 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5359}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005360#endif /* CONFIG_NFS_V4_1 */
5361
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005362static int decode_sequence(struct xdr_stream *xdr,
5363 struct nfs4_sequence_res *res,
5364 struct rpc_rqst *rqstp)
5365{
5366#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005367 struct nfs4_sessionid id;
5368 u32 dummy;
5369 int status;
5370 __be32 *p;
5371
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005372 if (!res->sr_session)
5373 return 0;
5374
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005375 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005376 if (!status)
5377 status = decode_sessionid(xdr, &id);
5378 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005379 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005380
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005381 /*
5382 * If the server returns different values for sessionID, slotID or
5383 * sequence number, the server is looney tunes.
5384 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005385 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005386
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005387 if (memcmp(id.data, res->sr_session->sess_id.data,
5388 NFS4_MAX_SESSIONID_LEN)) {
5389 dprintk("%s Invalid session id\n", __func__);
5390 goto out_err;
5391 }
Benny Halevye78291e2009-08-14 17:20:00 +03005392
Benny Halevyc0eae662009-08-14 17:20:14 +03005393 p = xdr_inline_decode(xdr, 20);
5394 if (unlikely(!p))
5395 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005396
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005397 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005398 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005399 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005400 dprintk("%s Invalid sequence number\n", __func__);
5401 goto out_err;
5402 }
5403 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005404 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005405 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005406 dprintk("%s Invalid slot id\n", __func__);
5407 goto out_err;
5408 }
5409 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005410 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005411 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005412 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005413 /* result flags */
5414 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005415 status = 0;
5416out_err:
5417 res->sr_status = status;
5418 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005419out_overflow:
5420 print_overflow_msg(__func__, xdr);
5421 status = -EIO;
5422 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005423#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005424 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005425#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005426}
5427
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005428#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005429/*
5430 * TODO: Need to handle case when EOF != true;
5431 */
5432static int decode_getdevicelist(struct xdr_stream *xdr,
5433 struct pnfs_devicelist *res)
5434{
5435 __be32 *p;
5436 int status, i;
5437 struct nfs_writeverf verftemp;
5438
5439 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5440 if (status)
5441 return status;
5442
5443 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5444 if (unlikely(!p))
5445 goto out_overflow;
5446
5447 /* TODO: Skip cookie for now */
5448 p += 2;
5449
5450 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005451 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005452
5453 res->num_devs = be32_to_cpup(p);
5454
5455 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5456
5457 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005458 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005459 __func__, res->num_devs);
5460 return -EIO;
5461 }
5462
5463 p = xdr_inline_decode(xdr,
5464 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5465 if (unlikely(!p))
5466 goto out_overflow;
5467 for (i = 0; i < res->num_devs; i++)
5468 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5469 NFS4_DEVICEID4_SIZE);
5470 res->eof = be32_to_cpup(p);
5471 return 0;
5472out_overflow:
5473 print_overflow_msg(__func__, xdr);
5474 return -EIO;
5475}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005476
5477static int decode_getdeviceinfo(struct xdr_stream *xdr,
5478 struct pnfs_device *pdev)
5479{
5480 __be32 *p;
5481 uint32_t len, type;
5482 int status;
5483
5484 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5485 if (status) {
5486 if (status == -ETOOSMALL) {
5487 p = xdr_inline_decode(xdr, 4);
5488 if (unlikely(!p))
5489 goto out_overflow;
5490 pdev->mincount = be32_to_cpup(p);
5491 dprintk("%s: Min count too small. mincnt = %u\n",
5492 __func__, pdev->mincount);
5493 }
5494 return status;
5495 }
5496
5497 p = xdr_inline_decode(xdr, 8);
5498 if (unlikely(!p))
5499 goto out_overflow;
5500 type = be32_to_cpup(p++);
5501 if (type != pdev->layout_type) {
5502 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5503 __func__, pdev->layout_type, type);
5504 return -EINVAL;
5505 }
5506 /*
5507 * Get the length of the opaque device_addr4. xdr_read_pages places
5508 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5509 * and places the remaining xdr data in xdr_buf->tail
5510 */
5511 pdev->mincount = be32_to_cpup(p);
5512 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5513
5514 /* Parse notification bitmap, verifying that it is zero. */
5515 p = xdr_inline_decode(xdr, 4);
5516 if (unlikely(!p))
5517 goto out_overflow;
5518 len = be32_to_cpup(p);
5519 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005520 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005521
5522 p = xdr_inline_decode(xdr, 4 * len);
5523 if (unlikely(!p))
5524 goto out_overflow;
5525 for (i = 0; i < len; i++, p++) {
5526 if (be32_to_cpup(p)) {
5527 dprintk("%s: notifications not supported\n",
5528 __func__);
5529 return -EIO;
5530 }
5531 }
5532 }
5533 return 0;
5534out_overflow:
5535 print_overflow_msg(__func__, xdr);
5536 return -EIO;
5537}
5538
5539static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5540 struct nfs4_layoutget_res *res)
5541{
5542 __be32 *p;
5543 int status;
5544 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005545 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5546 struct kvec *iov = rcvbuf->head;
5547 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005548
5549 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5550 if (status)
5551 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005552 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005553 if (unlikely(!p))
5554 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005555 res->return_on_close = be32_to_cpup(p);
5556 decode_stateid(xdr, &res->stateid);
5557 p = xdr_inline_decode(xdr, 4);
5558 if (unlikely(!p))
5559 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005560 layout_count = be32_to_cpup(p);
5561 if (!layout_count) {
5562 dprintk("%s: server responded with empty layout array\n",
5563 __func__);
5564 return -EINVAL;
5565 }
5566
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005567 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005568 if (unlikely(!p))
5569 goto out_overflow;
5570 p = xdr_decode_hyper(p, &res->range.offset);
5571 p = xdr_decode_hyper(p, &res->range.length);
5572 res->range.iomode = be32_to_cpup(p++);
5573 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005574 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005575
5576 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5577 __func__,
5578 (unsigned long)res->range.offset,
5579 (unsigned long)res->range.length,
5580 res->range.iomode,
5581 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005582 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005583
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005584 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5585 recvd = req->rq_rcv_buf.len - hdrlen;
5586 if (res->layoutp->len > recvd) {
5587 dprintk("NFS: server cheating in layoutget reply: "
5588 "layout len %u > recvd %u\n",
5589 res->layoutp->len, recvd);
5590 return -EINVAL;
5591 }
5592
5593 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005594
5595 if (layout_count > 1) {
5596 /* We only handle a length one array at the moment. Any
5597 * further entries are just ignored. Note that this means
5598 * the client may see a response that is less than the
5599 * minimum it requested.
5600 */
5601 dprintk("%s: server responded with %d layouts, dropping tail\n",
5602 __func__, layout_count);
5603 }
5604
5605 return 0;
5606out_overflow:
5607 print_overflow_msg(__func__, xdr);
5608 return -EIO;
5609}
Andy Adamson863a3c62011-03-23 13:27:54 +00005610
Benny Halevycbe82602011-05-22 19:52:37 +03005611static int decode_layoutreturn(struct xdr_stream *xdr,
5612 struct nfs4_layoutreturn_res *res)
5613{
5614 __be32 *p;
5615 int status;
5616
5617 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5618 if (status)
5619 return status;
5620 p = xdr_inline_decode(xdr, 4);
5621 if (unlikely(!p))
5622 goto out_overflow;
5623 res->lrs_present = be32_to_cpup(p);
5624 if (res->lrs_present)
5625 status = decode_stateid(xdr, &res->stateid);
5626 return status;
5627out_overflow:
5628 print_overflow_msg(__func__, xdr);
5629 return -EIO;
5630}
5631
Andy Adamson863a3c62011-03-23 13:27:54 +00005632static int decode_layoutcommit(struct xdr_stream *xdr,
5633 struct rpc_rqst *req,
5634 struct nfs4_layoutcommit_res *res)
5635{
5636 __be32 *p;
5637 __u32 sizechanged;
5638 int status;
5639
5640 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005641 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005642 if (status)
5643 return status;
5644
5645 p = xdr_inline_decode(xdr, 4);
5646 if (unlikely(!p))
5647 goto out_overflow;
5648 sizechanged = be32_to_cpup(p);
5649
5650 if (sizechanged) {
5651 /* throw away new size */
5652 p = xdr_inline_decode(xdr, 8);
5653 if (unlikely(!p))
5654 goto out_overflow;
5655 }
5656 return 0;
5657out_overflow:
5658 print_overflow_msg(__func__, xdr);
5659 return -EIO;
5660}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005661
5662static int decode_test_stateid(struct xdr_stream *xdr,
5663 struct nfs41_test_stateid_res *res)
5664{
5665 __be32 *p;
5666 int status;
5667 int num_res;
5668
5669 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5670 if (status)
5671 return status;
5672
5673 p = xdr_inline_decode(xdr, 4);
5674 if (unlikely(!p))
5675 goto out_overflow;
5676 num_res = be32_to_cpup(p++);
5677 if (num_res != 1)
5678 goto out;
5679
5680 p = xdr_inline_decode(xdr, 4);
5681 if (unlikely(!p))
5682 goto out_overflow;
5683 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005684
5685 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005686out_overflow:
5687 print_overflow_msg(__func__, xdr);
5688out:
5689 return -EIO;
5690}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005691
5692static int decode_free_stateid(struct xdr_stream *xdr,
5693 struct nfs41_free_stateid_res *res)
5694{
5695 __be32 *p;
5696 int status;
5697
5698 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5699 if (status)
5700 return status;
5701
5702 p = xdr_inline_decode(xdr, 4);
5703 if (unlikely(!p))
5704 goto out_overflow;
5705 res->status = be32_to_cpup(p++);
5706 return res->status;
5707out_overflow:
5708 print_overflow_msg(__func__, xdr);
5709 return -EIO;
5710}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005711#endif /* CONFIG_NFS_V4_1 */
5712
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713/*
Benny Halevy49c25592008-12-23 16:06:16 -05005714 * END OF "GENERIC" DECODE ROUTINES.
5715 */
5716
5717/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718 * Decode OPEN_DOWNGRADE response
5719 */
Chuck Leverbf269552010-12-14 14:59:29 +00005720static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5721 struct xdr_stream *xdr,
5722 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723{
Andy Adamson05d564f2008-12-23 16:06:15 -05005724 struct compound_hdr hdr;
5725 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726
Chuck Leverbf269552010-12-14 14:59:29 +00005727 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005728 if (status)
5729 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005730 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005731 if (status)
5732 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005733 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005734 if (status)
5735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005736 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005737 if (status != 0)
5738 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005739 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005741 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742}
5743
5744/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 * Decode ACCESS response
5746 */
Chuck Leverbf269552010-12-14 14:59:29 +00005747static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5748 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 struct compound_hdr hdr;
5751 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005752
Chuck Leverbf269552010-12-14 14:59:29 +00005753 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005754 if (status)
5755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005757 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005760 if (status != 0)
5761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005763 if (status != 0)
5764 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005765 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766out:
5767 return status;
5768}
5769
5770/*
5771 * Decode LOOKUP response
5772 */
Chuck Leverbf269552010-12-14 14:59:29 +00005773static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5774 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 struct compound_hdr hdr;
5777 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005778
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005780 if (status)
5781 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005782 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005783 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_putfh(xdr);
5786 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005788 status = decode_lookup(xdr);
5789 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005791 status = decode_getfh(xdr, res->fh);
5792 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005794 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795out:
5796 return status;
5797}
5798
5799/*
5800 * Decode LOOKUP_ROOT response
5801 */
Chuck Leverbf269552010-12-14 14:59:29 +00005802static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5803 struct xdr_stream *xdr,
5804 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806 struct compound_hdr hdr;
5807 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005808
Chuck Leverbf269552010-12-14 14:59:29 +00005809 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005810 if (status)
5811 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005812 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005813 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005815 status = decode_putrootfh(xdr);
5816 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_getfh(xdr, res->fh);
5819 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005820 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821out:
5822 return status;
5823}
5824
5825/*
5826 * Decode REMOVE response
5827 */
Chuck Leverbf269552010-12-14 14:59:29 +00005828static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5829 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 struct compound_hdr hdr;
5832 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005833
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005835 if (status)
5836 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005837 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005838 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_putfh(xdr);
5841 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005843 status = decode_remove(xdr, &res->cinfo);
5844 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005845 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005846 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847out:
5848 return status;
5849}
5850
5851/*
5852 * Decode RENAME response
5853 */
Chuck Leverbf269552010-12-14 14:59:29 +00005854static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5855 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 struct compound_hdr hdr;
5858 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005859
Chuck Leverbf269552010-12-14 14:59:29 +00005860 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005861 if (status)
5862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005864 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005866 status = decode_putfh(xdr);
5867 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_savefh(xdr);
5870 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_putfh(xdr);
5873 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5876 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005877 goto out;
5878 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005879 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005881 status = decode_restorefh(xdr);
5882 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005883 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005884 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885out:
5886 return status;
5887}
5888
5889/*
5890 * Decode LINK response
5891 */
Chuck Leverbf269552010-12-14 14:59:29 +00005892static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5893 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895 struct compound_hdr hdr;
5896 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005897
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005899 if (status)
5900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005902 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005904 status = decode_putfh(xdr);
5905 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005907 status = decode_savefh(xdr);
5908 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005910 status = decode_putfh(xdr);
5911 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_link(xdr, &res->cinfo);
5914 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005915 goto out;
5916 /*
5917 * Note order: OP_LINK leaves the directory as the current
5918 * filehandle.
5919 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005920 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_restorefh(xdr);
5923 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005924 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005925 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926out:
5927 return status;
5928}
5929
5930/*
5931 * Decode CREATE response
5932 */
Chuck Leverbf269552010-12-14 14:59:29 +00005933static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5934 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 struct compound_hdr hdr;
5937 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005938
Chuck Leverbf269552010-12-14 14:59:29 +00005939 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005940 if (status)
5941 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005942 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005943 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005945 status = decode_putfh(xdr);
5946 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_savefh(xdr);
5949 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005950 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_create(xdr, &res->dir_cinfo);
5952 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_getfh(xdr, res->fh);
5955 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005957 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005958 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_restorefh(xdr);
5960 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005961 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005962 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963out:
5964 return status;
5965}
5966
5967/*
5968 * Decode SYMLINK response
5969 */
Chuck Leverbf269552010-12-14 14:59:29 +00005970static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5971 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972{
Chuck Leverbf269552010-12-14 14:59:29 +00005973 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974}
5975
5976/*
5977 * Decode GETATTR response
5978 */
Chuck Leverbf269552010-12-14 14:59:29 +00005979static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5980 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982 struct compound_hdr hdr;
5983 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005984
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 if (status)
5987 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005989 if (status)
5990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992 if (status)
5993 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005994 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995out:
5996 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997}
5998
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005999/*
6000 * Encode an SETACL request
6001 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006002static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6003 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006004{
Andy Adamson05d564f2008-12-23 16:06:15 -05006005 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006006 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006007 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006008
Chuck Lever9f06c712010-12-14 14:59:18 +00006009 encode_compound_hdr(xdr, req, &hdr);
6010 encode_sequence(xdr, &args->seq_args, &hdr);
6011 encode_putfh(xdr, args->fh, &hdr);
6012 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006013 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006014}
Andy Adamson05d564f2008-12-23 16:06:15 -05006015
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006016/*
6017 * Decode SETACL response
6018 */
6019static int
Chuck Leverbf269552010-12-14 14:59:29 +00006020nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006021 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006022{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006023 struct compound_hdr hdr;
6024 int status;
6025
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006027 if (status)
6028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006030 if (status)
6031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006033 if (status)
6034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006036out:
6037 return status;
6038}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039
6040/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006041 * Decode GETACL response
6042 */
6043static int
Chuck Leverbf269552010-12-14 14:59:29 +00006044nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006045 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006046{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006047 struct compound_hdr hdr;
6048 int status;
6049
Trond Myklebust331818f2012-02-03 18:30:53 -05006050 if (res->acl_scratch != NULL) {
6051 void *p = page_address(res->acl_scratch);
6052 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6053 }
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006055 if (status)
6056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006058 if (status)
6059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006061 if (status)
6062 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006063 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006064
6065out:
6066 return status;
6067}
6068
6069/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 * Decode CLOSE response
6071 */
Chuck Leverbf269552010-12-14 14:59:29 +00006072static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6073 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074{
Andy Adamson05d564f2008-12-23 16:06:15 -05006075 struct compound_hdr hdr;
6076 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006079 if (status)
6080 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006082 if (status)
6083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006085 if (status)
6086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006088 if (status != 0)
6089 goto out;
6090 /*
6091 * Note: Server may do delete on close for this file
6092 * in which case the getattr call will fail with
6093 * an ESTALE error. Shouldn't be a problem,
6094 * though, since fattr->valid will remain unset.
6095 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006096 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006098 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099}
6100
6101/*
6102 * Decode OPEN response
6103 */
Chuck Leverbf269552010-12-14 14:59:29 +00006104static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6105 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106{
Andy Adamson05d564f2008-12-23 16:06:15 -05006107 struct compound_hdr hdr;
6108 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006111 if (status)
6112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006114 if (status)
6115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006117 if (status)
6118 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006119 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006120 if (status)
6121 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006123 if (status)
6124 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006125 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006127 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006130 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006131 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006133 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134}
6135
6136/*
6137 * Decode OPEN_CONFIRM response
6138 */
Chuck Leverbf269552010-12-14 14:59:29 +00006139static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6140 struct xdr_stream *xdr,
6141 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142{
Andy Adamson05d564f2008-12-23 16:06:15 -05006143 struct compound_hdr hdr;
6144 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006147 if (status)
6148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006150 if (status)
6151 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006152 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006154 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155}
6156
6157/*
6158 * Decode OPEN response
6159 */
Chuck Leverbf269552010-12-14 14:59:29 +00006160static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6161 struct xdr_stream *xdr,
6162 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163{
Andy Adamson05d564f2008-12-23 16:06:15 -05006164 struct compound_hdr hdr;
6165 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166
Chuck Leverbf269552010-12-14 14:59:29 +00006167 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006168 if (status)
6169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006171 if (status)
6172 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006174 if (status)
6175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006177 if (status)
6178 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006179 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006181 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182}
6183
6184/*
6185 * Decode SETATTR response
6186 */
Chuck Leverbf269552010-12-14 14:59:29 +00006187static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6188 struct xdr_stream *xdr,
6189 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190{
Andy Adamson05d564f2008-12-23 16:06:15 -05006191 struct compound_hdr hdr;
6192 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006195 if (status)
6196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006198 if (status)
6199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006201 if (status)
6202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006204 if (status)
6205 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006206 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006208 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209}
6210
6211/*
6212 * Decode LOCK response
6213 */
Chuck Leverbf269552010-12-14 14:59:29 +00006214static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6215 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 struct compound_hdr hdr;
6218 int status;
6219
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006224 if (status)
6225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 if (status)
6228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230out:
6231 return status;
6232}
6233
6234/*
6235 * Decode LOCKT response
6236 */
Chuck Leverbf269552010-12-14 14:59:29 +00006237static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6238 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 struct compound_hdr hdr;
6241 int status;
6242
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244 if (status)
6245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250 if (status)
6251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253out:
6254 return status;
6255}
6256
6257/*
6258 * Decode LOCKU response
6259 */
Chuck Leverbf269552010-12-14 14:59:29 +00006260static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6261 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 struct compound_hdr hdr;
6264 int status;
6265
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 if (status)
6274 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276out:
6277 return status;
6278}
6279
Chuck Leverbf269552010-12-14 14:59:29 +00006280static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6281 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006282{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006283 struct compound_hdr hdr;
6284 int status;
6285
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006287 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006289 return status;
6290}
6291
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292/*
6293 * Decode READLINK response
6294 */
Chuck Leverbf269552010-12-14 14:59:29 +00006295static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6296 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006297 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 struct compound_hdr hdr;
6300 int status;
6301
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 if (status)
6310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312out:
6313 return status;
6314}
6315
6316/*
6317 * Decode READDIR response
6318 */
Chuck Leverbf269552010-12-14 14:59:29 +00006319static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 struct compound_hdr hdr;
6323 int status;
6324
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335out:
6336 return status;
6337}
6338
6339/*
6340 * Decode Read response
6341 */
Chuck Leverbf269552010-12-14 14:59:29 +00006342static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6343 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 struct compound_hdr hdr;
6346 int status;
6347
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 if (status)
6356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 if (!status)
6359 status = res->count;
6360out:
6361 return status;
6362}
6363
6364/*
6365 * Decode WRITE response
6366 */
Chuck Leverbf269552010-12-14 14:59:29 +00006367static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6368 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370 struct compound_hdr hdr;
6371 int status;
6372
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374 if (status)
6375 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006377 if (status)
6378 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006379 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380 if (status)
6381 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006383 if (status)
6384 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006385 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006386 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387 if (!status)
6388 status = res->count;
6389out:
6390 return status;
6391}
6392
6393/*
6394 * Decode COMMIT response
6395 */
Chuck Leverbf269552010-12-14 14:59:29 +00006396static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6397 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399 struct compound_hdr hdr;
6400 int status;
6401
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403 if (status)
6404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006406 if (status)
6407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409 if (status)
6410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006412 if (status)
6413 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006414 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006415 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416out:
6417 return status;
6418}
6419
6420/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006421 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422 */
Chuck Leverbf269552010-12-14 14:59:29 +00006423static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006424 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 struct compound_hdr hdr;
6427 int status;
6428
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006432 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006435 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 return status;
6437}
6438
6439/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006440 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441 */
Chuck Leverbf269552010-12-14 14:59:29 +00006442static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006443 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 struct compound_hdr hdr;
6446 int status;
6447
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006451 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 return status;
6456}
6457
6458/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006459 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 */
Chuck Leverbf269552010-12-14 14:59:29 +00006461static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006462 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 struct compound_hdr hdr;
6465 int status;
6466
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006470 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474 return status;
6475}
6476
6477/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006478 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 */
Chuck Leverbf269552010-12-14 14:59:29 +00006480static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6481 struct xdr_stream *xdr,
6482 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 struct compound_hdr hdr;
6485 int status;
6486
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006488 if (status)
6489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006491 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_putfh(xdr);
6494 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497out:
6498 return status;
6499}
6500
6501/*
6502 * Decode RENEW response
6503 */
Chuck Leverbf269552010-12-14 14:59:29 +00006504static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6505 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 struct compound_hdr hdr;
6508 int status;
6509
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 return status;
6514}
6515
6516/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006517 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 */
Chuck Leverbf269552010-12-14 14:59:29 +00006519static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6520 struct xdr_stream *xdr,
6521 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 struct compound_hdr hdr;
6524 int status;
6525
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 return status;
6530}
6531
6532/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006533 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 */
Chuck Leverbf269552010-12-14 14:59:29 +00006535static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6536 struct xdr_stream *xdr,
6537 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 struct compound_hdr hdr;
6540 int status;
6541
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 return status;
6550}
6551
6552/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006553 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 */
Chuck Leverbf269552010-12-14 14:59:29 +00006555static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6556 struct xdr_stream *xdr,
6557 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 struct compound_hdr hdr;
6560 int status;
6561
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006563 if (status)
6564 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006566 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006569 if (status != 0)
6570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006572 if (status != 0)
6573 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006574 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006575out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576 return status;
6577}
6578
Trond Myklebust683b57b2006-06-09 09:34:22 -04006579/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006580 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006581 */
Chuck Leverbf269552010-12-14 14:59:29 +00006582static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6583 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006584 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006585{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006586 struct compound_hdr hdr;
6587 int status;
6588
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006590 if (status)
6591 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006593 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_putfh(xdr);
6596 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006597 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_lookup(xdr);
6599 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006602 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6603 NULL, res->fs_locations,
6604 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006605out:
6606 return status;
6607}
6608
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006609/*
6610 * Decode SECINFO response
6611 */
6612static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6613 struct xdr_stream *xdr,
6614 struct nfs4_secinfo_res *res)
6615{
6616 struct compound_hdr hdr;
6617 int status;
6618
6619 status = decode_compound_hdr(xdr, &hdr);
6620 if (status)
6621 goto out;
6622 status = decode_sequence(xdr, &res->seq_res, rqstp);
6623 if (status)
6624 goto out;
6625 status = decode_putfh(xdr);
6626 if (status)
6627 goto out;
6628 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006629out:
6630 return status;
6631}
6632
Benny Halevy99fe60d2009-04-01 09:22:29 -04006633#if defined(CONFIG_NFS_V4_1)
6634/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006635 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006636 */
Chuck Leverbf269552010-12-14 14:59:29 +00006637static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6638 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006639 void *res)
6640{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006641 struct compound_hdr hdr;
6642 int status;
6643
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006645 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006647 return status;
6648}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006649
6650/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006651 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006652 */
Chuck Leverbf269552010-12-14 14:59:29 +00006653static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6654 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006655 struct nfs41_create_session_res *res)
6656{
Andy Adamsonfc931582009-04-01 09:22:31 -04006657 struct compound_hdr hdr;
6658 int status;
6659
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006661 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006663 return status;
6664}
6665
6666/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006667 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006668 */
Chuck Leverbf269552010-12-14 14:59:29 +00006669static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6670 struct xdr_stream *xdr,
6671 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006672{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006673 struct compound_hdr hdr;
6674 int status;
6675
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006677 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006679 return status;
6680}
6681
6682/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006683 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006684 */
Chuck Leverbf269552010-12-14 14:59:29 +00006685static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6686 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006687 struct nfs4_sequence_res *res)
6688{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006689 struct compound_hdr hdr;
6690 int status;
6691
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006693 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006695 return status;
6696}
6697
6698/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006699 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006700 */
Chuck Leverbf269552010-12-14 14:59:29 +00006701static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6702 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006703 struct nfs4_get_lease_time_res *res)
6704{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006705 struct compound_hdr hdr;
6706 int status;
6707
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006709 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006711 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006713 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006715 return status;
6716}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006717
6718/*
6719 * Decode RECLAIM_COMPLETE response
6720 */
Chuck Leverbf269552010-12-14 14:59:29 +00006721static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6722 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006723 struct nfs41_reclaim_complete_res *res)
6724{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006725 struct compound_hdr hdr;
6726 int status;
6727
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006729 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006730 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006731 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006733 return status;
6734}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006735
6736/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006737 * Decode GETDEVICELIST response
6738 */
6739static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6740 struct xdr_stream *xdr,
6741 struct nfs4_getdevicelist_res *res)
6742{
6743 struct compound_hdr hdr;
6744 int status;
6745
6746 dprintk("encoding getdevicelist!\n");
6747
6748 status = decode_compound_hdr(xdr, &hdr);
6749 if (status != 0)
6750 goto out;
6751 status = decode_sequence(xdr, &res->seq_res, rqstp);
6752 if (status != 0)
6753 goto out;
6754 status = decode_putfh(xdr);
6755 if (status != 0)
6756 goto out;
6757 status = decode_getdevicelist(xdr, res->devlist);
6758out:
6759 return status;
6760}
6761
6762/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006763 * Decode GETDEVINFO response
6764 */
Chuck Leverbf269552010-12-14 14:59:29 +00006765static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6766 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006767 struct nfs4_getdeviceinfo_res *res)
6768{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006769 struct compound_hdr hdr;
6770 int status;
6771
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006773 if (status != 0)
6774 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006776 if (status != 0)
6777 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006778 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006779out:
6780 return status;
6781}
6782
6783/*
6784 * Decode LAYOUTGET response
6785 */
Chuck Leverbf269552010-12-14 14:59:29 +00006786static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6787 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006788 struct nfs4_layoutget_res *res)
6789{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006790 struct compound_hdr hdr;
6791 int status;
6792
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006794 if (status)
6795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006797 if (status)
6798 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006799 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006800 if (status)
6801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006802 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006803out:
6804 return status;
6805}
Andy Adamson863a3c62011-03-23 13:27:54 +00006806
6807/*
Benny Halevycbe82602011-05-22 19:52:37 +03006808 * Decode LAYOUTRETURN response
6809 */
6810static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6811 struct xdr_stream *xdr,
6812 struct nfs4_layoutreturn_res *res)
6813{
6814 struct compound_hdr hdr;
6815 int status;
6816
6817 status = decode_compound_hdr(xdr, &hdr);
6818 if (status)
6819 goto out;
6820 status = decode_sequence(xdr, &res->seq_res, rqstp);
6821 if (status)
6822 goto out;
6823 status = decode_putfh(xdr);
6824 if (status)
6825 goto out;
6826 status = decode_layoutreturn(xdr, res);
6827out:
6828 return status;
6829}
6830
6831/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006832 * Decode LAYOUTCOMMIT response
6833 */
6834static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6835 struct xdr_stream *xdr,
6836 struct nfs4_layoutcommit_res *res)
6837{
6838 struct compound_hdr hdr;
6839 int status;
6840
6841 status = decode_compound_hdr(xdr, &hdr);
6842 if (status)
6843 goto out;
6844 status = decode_sequence(xdr, &res->seq_res, rqstp);
6845 if (status)
6846 goto out;
6847 status = decode_putfh(xdr);
6848 if (status)
6849 goto out;
6850 status = decode_layoutcommit(xdr, rqstp, res);
6851 if (status)
6852 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006853 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006854out:
6855 return status;
6856}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006857
6858/*
6859 * Decode SECINFO_NO_NAME response
6860 */
6861static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6862 struct xdr_stream *xdr,
6863 struct nfs4_secinfo_res *res)
6864{
6865 struct compound_hdr hdr;
6866 int status;
6867
6868 status = decode_compound_hdr(xdr, &hdr);
6869 if (status)
6870 goto out;
6871 status = decode_sequence(xdr, &res->seq_res, rqstp);
6872 if (status)
6873 goto out;
6874 status = decode_putrootfh(xdr);
6875 if (status)
6876 goto out;
6877 status = decode_secinfo(xdr, res);
6878out:
6879 return status;
6880}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006881
6882/*
6883 * Decode TEST_STATEID response
6884 */
6885static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6886 struct xdr_stream *xdr,
6887 struct nfs41_test_stateid_res *res)
6888{
6889 struct compound_hdr hdr;
6890 int status;
6891
6892 status = decode_compound_hdr(xdr, &hdr);
6893 if (status)
6894 goto out;
6895 status = decode_sequence(xdr, &res->seq_res, rqstp);
6896 if (status)
6897 goto out;
6898 status = decode_test_stateid(xdr, res);
6899out:
6900 return status;
6901}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006902
6903/*
6904 * Decode FREE_STATEID response
6905 */
6906static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6907 struct xdr_stream *xdr,
6908 struct nfs41_free_stateid_res *res)
6909{
6910 struct compound_hdr hdr;
6911 int status;
6912
6913 status = decode_compound_hdr(xdr, &hdr);
6914 if (status)
6915 goto out;
6916 status = decode_sequence(xdr, &res->seq_res, rqstp);
6917 if (status)
6918 goto out;
6919 status = decode_free_stateid(xdr, res);
6920out:
6921 return status;
6922}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006923#endif /* CONFIG_NFS_V4_1 */
6924
Chuck Lever573c4e12010-12-14 14:58:11 +00006925/**
6926 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6927 * the local page cache.
6928 * @xdr: XDR stream where entry resides
6929 * @entry: buffer to fill in with entry data
6930 * @plus: boolean indicating whether this should be a readdirplus entry
6931 *
6932 * Returns zero if successful, otherwise a negative errno value is
6933 * returned.
6934 *
6935 * This function is not invoked during READDIR reply decoding, but
6936 * rather whenever an application invokes the getdents(2) system call
6937 * on a directory already in our cache.
6938 */
6939int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6940 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941{
Fred Isamandae100c2011-07-30 20:52:37 -04006942 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006944 __be32 *p = xdr_inline_decode(xdr, 4);
6945 if (unlikely(!p))
6946 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006947 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006948 p = xdr_inline_decode(xdr, 4);
6949 if (unlikely(!p))
6950 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006951 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006952 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006953 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006954 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006955 }
6956
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006957 p = xdr_inline_decode(xdr, 12);
6958 if (unlikely(!p))
6959 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960 entry->prev_cookie = entry->cookie;
6961 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006962 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006963
Trond Myklebust9af8c222010-10-24 11:52:55 -04006964 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006965 if (unlikely(!p))
6966 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006967 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006968
6969 /*
6970 * In case the server doesn't return an inode number,
6971 * we fake one here. (We don't use inode number 0,
6972 * since glibc seems to choke on it...)
6973 */
6974 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006975 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976
Trond Myklebust9af8c222010-10-24 11:52:55 -04006977 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006978 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006979
6980 if (decode_attr_length(xdr, &len, &p) < 0)
6981 goto out_overflow;
6982
Chuck Lever573c4e12010-12-14 14:58:11 +00006983 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006984 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006985 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006986 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6987 entry->ino = entry->fattr->mounted_on_fileid;
6988 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006989 entry->ino = entry->fattr->fileid;
6990
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006991 entry->d_type = DT_UNKNOWN;
6992 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6993 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6994
Chuck Lever573c4e12010-12-14 14:58:11 +00006995 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006996
6997out_overflow:
6998 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006999 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000}
7001
7002/*
7003 * We need to translate between nfs status return values and
7004 * the local errno values which may not be the same.
7005 */
7006static struct {
7007 int stat;
7008 int errno;
7009} nfs_errtbl[] = {
7010 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007011 { NFS4ERR_PERM, -EPERM },
7012 { NFS4ERR_NOENT, -ENOENT },
7013 { NFS4ERR_IO, -errno_NFSERR_IO},
7014 { NFS4ERR_NXIO, -ENXIO },
7015 { NFS4ERR_ACCESS, -EACCES },
7016 { NFS4ERR_EXIST, -EEXIST },
7017 { NFS4ERR_XDEV, -EXDEV },
7018 { NFS4ERR_NOTDIR, -ENOTDIR },
7019 { NFS4ERR_ISDIR, -EISDIR },
7020 { NFS4ERR_INVAL, -EINVAL },
7021 { NFS4ERR_FBIG, -EFBIG },
7022 { NFS4ERR_NOSPC, -ENOSPC },
7023 { NFS4ERR_ROFS, -EROFS },
7024 { NFS4ERR_MLINK, -EMLINK },
7025 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7026 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7027 { NFS4ERR_DQUOT, -EDQUOT },
7028 { NFS4ERR_STALE, -ESTALE },
7029 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007030 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7031 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7032 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007033 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007034 { NFS4ERR_BADTYPE, -EBADTYPE },
7035 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007036 { NFS4ERR_SYMLINK, -ELOOP },
7037 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7038 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007039 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040};
7041
7042/*
7043 * Convert an NFS error code to a local one.
7044 * This one is used jointly by NFSv2 and NFSv3.
7045 */
7046static int
David Howells0a8ea432006-08-22 20:06:08 -04007047nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048{
7049 int i;
7050 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7051 if (nfs_errtbl[i].stat == stat)
7052 return nfs_errtbl[i].errno;
7053 }
7054 if (stat <= 10000 || stat > 10100) {
7055 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007056 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007057 }
7058 /* If we cannot translate the error, the recovery routines should
7059 * handle it.
7060 * Note: remaining NFSv4 error codes have values > 10000, so should
7061 * not conflict with native Linux error codes.
7062 */
Benny Halevy856dff32008-03-31 17:39:06 +03007063 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064}
7065
Linus Torvalds1da177e2005-04-16 15:20:36 -07007066#define PROC(proc, argtype, restype) \
7067[NFSPROC4_CLNT_##proc] = { \
7068 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007069 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007070 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007071 .p_arglen = NFS4_##argtype##_sz, \
7072 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007073 .p_statidx = NFSPROC4_CLNT_##proc, \
7074 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007075}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007076
7077struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007078 PROC(READ, enc_read, dec_read),
7079 PROC(WRITE, enc_write, dec_write),
7080 PROC(COMMIT, enc_commit, dec_commit),
7081 PROC(OPEN, enc_open, dec_open),
7082 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7083 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7084 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7085 PROC(CLOSE, enc_close, dec_close),
7086 PROC(SETATTR, enc_setattr, dec_setattr),
7087 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7088 PROC(RENEW, enc_renew, dec_renew),
7089 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7090 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7091 PROC(LOCK, enc_lock, dec_lock),
7092 PROC(LOCKT, enc_lockt, dec_lockt),
7093 PROC(LOCKU, enc_locku, dec_locku),
7094 PROC(ACCESS, enc_access, dec_access),
7095 PROC(GETATTR, enc_getattr, dec_getattr),
7096 PROC(LOOKUP, enc_lookup, dec_lookup),
7097 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7098 PROC(REMOVE, enc_remove, dec_remove),
7099 PROC(RENAME, enc_rename, dec_rename),
7100 PROC(LINK, enc_link, dec_link),
7101 PROC(SYMLINK, enc_symlink, dec_symlink),
7102 PROC(CREATE, enc_create, dec_create),
7103 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7104 PROC(STATFS, enc_statfs, dec_statfs),
7105 PROC(READLINK, enc_readlink, dec_readlink),
7106 PROC(READDIR, enc_readdir, dec_readdir),
7107 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7108 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7109 PROC(GETACL, enc_getacl, dec_getacl),
7110 PROC(SETACL, enc_setacl, dec_setacl),
7111 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7112 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007113 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007114#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007115 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7116 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7117 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7118 PROC(SEQUENCE, enc_sequence, dec_sequence),
7119 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7120 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7121 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7122 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007123 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007124 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007125 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007126 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007127 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007128 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007129#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007130};
7131
Trond Myklebusta613fa12012-01-20 13:53:56 -05007132const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007133 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007134 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007135 .procs = nfs4_procedures
7136};
7137
7138/*
7139 * Local variables:
7140 * c-basic-offset: 8
7141 * End:
7142 */