blob: e4bb8e6409a7504d2443b96e7b8618a2d32a700c [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
Trond Myklebustff2eb682012-03-05 11:40:12 -0500912static void encode_uint64(struct xdr_stream *xdr, u64 n)
913{
914 __be32 *p;
915
916 p = reserve_space(xdr, 8);
917 xdr_encode_hyper(p, n);
918}
919
Trond Myklebust4ade9822012-03-04 18:13:57 -0500920static void encode_nfs4_seqid(struct xdr_stream *xdr,
921 const struct nfs_seqid *seqid)
922{
923 encode_uint32(xdr, seqid->sequence->counter);
924}
925
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400926static void encode_compound_hdr(struct xdr_stream *xdr,
927 struct rpc_rqst *req,
928 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Al Viro8687b632006-10-19 23:28:48 -0700930 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400931 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400932
933 /* initialize running count of expected bytes in reply.
934 * NOTE: the replied tag SHOULD be the same is the one sent,
935 * but this is not required as a MUST for the server to do so. */
936 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500939 encode_string(xdr, hdr->taglen, hdr->tag);
940 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300941 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500942 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300943 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500944}
945
Trond Myklebustab19b482012-03-04 18:13:57 -0500946static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
947 uint32_t replen,
948 struct compound_hdr *hdr)
949{
950 encode_uint32(xdr, op);
951 hdr->nops++;
952 hdr->replen += replen;
953}
954
Andy Adamsond0179312008-12-23 16:06:17 -0500955static void encode_nops(struct compound_hdr *hdr)
956{
Andy Adamsonfc931582009-04-01 09:22:31 -0400957 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500958 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500961static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
962{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500963 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500964}
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
967{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500968 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500971static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
973 char owner_name[IDMAP_NAMESZ];
974 char owner_group[IDMAP_NAMESZ];
975 int owner_namelen = 0;
976 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700977 __be32 *p;
978 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 int len;
980 uint32_t bmval0 = 0;
981 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 /*
984 * We reserve enough space to write the entire attribute buffer at once.
985 * In the worst-case, this would be
986 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
987 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000988 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 */
990 len = 16;
991
992 /* Sigh */
993 if (iap->ia_valid & ATTR_SIZE)
994 len += 8;
995 if (iap->ia_valid & ATTR_MODE)
996 len += 4;
997 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800998 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001000 dprintk("nfs: couldn't resolve uid %d to string\n",
1001 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 /* XXX */
1003 strcpy(owner_name, "nobody");
1004 owner_namelen = sizeof("nobody") - 1;
1005 /* goto out; */
1006 }
1007 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1008 }
1009 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001010 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001012 dprintk("nfs: couldn't resolve gid %d to string\n",
1013 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 strcpy(owner_group, "nobody");
1015 owner_grouplen = sizeof("nobody") - 1;
1016 /* goto out; */
1017 }
1018 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1019 }
1020 if (iap->ia_valid & ATTR_ATIME_SET)
1021 len += 16;
1022 else if (iap->ia_valid & ATTR_ATIME)
1023 len += 4;
1024 if (iap->ia_valid & ATTR_MTIME_SET)
1025 len += 16;
1026 else if (iap->ia_valid & ATTR_MTIME)
1027 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001028 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 /*
1031 * We write the bitmap length now, but leave the bitmap and the attribute
1032 * buffer length to be backfilled at the end of this routine.
1033 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001034 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 q = p;
1036 p += 3;
1037
1038 if (iap->ia_valid & ATTR_SIZE) {
1039 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001040 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 if (iap->ia_valid & ATTR_MODE) {
1043 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001044 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_UID) {
1047 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001048 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 if (iap->ia_valid & ATTR_GID) {
1051 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001052 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054 if (iap->ia_valid & ATTR_ATIME_SET) {
1055 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001056 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1057 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001058 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1059 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 else if (iap->ia_valid & ATTR_ATIME) {
1062 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 if (iap->ia_valid & ATTR_MTIME_SET) {
1066 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1068 *p++ = cpu_to_be32(0);
1069 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1070 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
1072 else if (iap->ia_valid & ATTR_MTIME) {
1073 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001074 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 /*
1078 * Now we backfill the bitmap and the attribute buffer length.
1079 */
1080 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001081 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 len, ((char *)p - (char *)q) + 4);
1083 BUG();
1084 }
1085 len = (char *)p - (char *)q - 12;
1086 *q++ = htonl(bmval0);
1087 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001088 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001095 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1096 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001099static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Trond Myklebustab19b482012-03-04 18:13:57 -05001101 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001102 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001103 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104}
1105
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001106static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Al Viro8687b632006-10-19 23:28:48 -07001108 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001109
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001110 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1111 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001112 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001113 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001116static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Al Viro8687b632006-10-19 23:28:48 -07001118 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001119
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001120 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1121 encode_uint32(xdr, 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 Adamsoncf8cdbe2008-12-23 16:06:18 -05001141 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Andy Adamson05d564f2008-12-23 16:06:15 -05001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001148 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1149 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001150 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001154static 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 -07001155{
Andy Adamson05d564f2008-12-23 16:06:15 -05001156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001158 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1159 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(2);
1161 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001162 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Fred Isamandae100c2011-07-30 20:52:37 -04001165static void
1166encode_getattr_three(struct xdr_stream *xdr,
1167 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1168 struct compound_hdr *hdr)
1169{
1170 __be32 *p;
1171
Trond Myklebustab19b482012-03-04 18:13:57 -05001172 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001173 if (bm2) {
1174 p = reserve_space(xdr, 16);
1175 *p++ = cpu_to_be32(3);
1176 *p++ = cpu_to_be32(bm0);
1177 *p++ = cpu_to_be32(bm1);
1178 *p = cpu_to_be32(bm2);
1179 } else if (bm1) {
1180 p = reserve_space(xdr, 12);
1181 *p++ = cpu_to_be32(2);
1182 *p++ = cpu_to_be32(bm0);
1183 *p = cpu_to_be32(bm1);
1184 } else {
1185 p = reserve_space(xdr, 8);
1186 *p++ = cpu_to_be32(1);
1187 *p = cpu_to_be32(bm0);
1188 }
Fred Isamandae100c2011-07-30 20:52:37 -04001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1194 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Fred Isamandae100c2011-07-30 20:52:37 -04001199 encode_getattr_three(xdr,
1200 bitmask[0] & nfs4_fsinfo_bitmap[0],
1201 bitmask[1] & nfs4_fsinfo_bitmap[1],
1202 bitmask[2] & nfs4_fsinfo_bitmap[2],
1203 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204}
1205
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001206static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001207{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001208 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1209 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Trond Myklebustab19b482012-03-04 18:13:57 -05001214 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001217static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
Trond Myklebustab19b482012-03-04 18:13:57 -05001219 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001220 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001223static inline int nfs4_lock_type(struct file_lock *fl, int block)
1224{
1225 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1226 return block ? NFS4_READW_LT : NFS4_READ_LT;
1227 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1228}
1229
1230static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1231{
1232 if (fl->fl_end == OFFSET_MAX)
1233 return ~(uint64_t)0;
1234 return fl->fl_end - fl->fl_start + 1;
1235}
1236
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1238{
1239 __be32 *p;
1240
Trond Myklebustd035c362010-12-21 10:45:27 -05001241 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001242 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001243 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001245 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001246 xdr_encode_hyper(p, lowner->id);
1247}
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249/*
1250 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1251 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1252 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Al Viro8687b632006-10-19 23:28:48 -07001255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001257 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1258 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001259 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1260 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001261 p = xdr_encode_hyper(p, args->fl->fl_start);
1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001263 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001264 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001265 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001266 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001267 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001268 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
1270 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001271 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001272 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001276static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Al Viro8687b632006-10-19 23:28:48 -07001278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001280 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1281 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001282 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001283 p = xdr_encode_hyper(p, args->fl->fl_start);
1284 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001285 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Al Viro8687b632006-10-19 23:28:48 -07001290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001292 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1293 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001294 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001295 encode_nfs4_stateid(xdr, args->stateid);
1296 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001297 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001298 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299}
1300
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001301static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1302{
Trond Myklebustab19b482012-03-04 18:13:57 -05001303 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001304 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001305}
1306
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001307static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
Trond Myklebustab19b482012-03-04 18:13:57 -05001309 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001310 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001313static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
Al Viro8687b632006-10-19 23:28:48 -07001315 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Benny Halevy13c65ce2009-08-14 17:19:25 +03001317 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001318 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001319 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 break;
1322 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001323 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001324 break;
1325 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001326 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001327 break;
1328 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001329 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
Benny Halevy34558512009-08-14 17:19:30 +03001331 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
1334static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1335{
Al Viro8687b632006-10-19 23:28:48 -07001336 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 /*
1338 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1339 * owner 4 = 32
1340 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001341 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001342 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001343 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001344 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001345 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001346 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001347 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001348 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
1351static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001354 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Benny Halevy13c65ce2009-08-14 17:19:25 +03001356 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001358 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001359 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001360 encode_attrs(xdr, arg->u.attrs, arg->server);
1361 break;
1362 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001363 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001364 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001365 if (nfs4_has_persistent_session(clp)) {
1366 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1367 encode_attrs(xdr, arg->u.attrs, arg->server);
1368 } else {
1369 struct iattr dummy;
1370
1371 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1372 encode_nfs4_verifier(xdr, &arg->u.verifier);
1373 dummy.ia_valid = 0;
1374 encode_attrs(xdr, &dummy, arg->server);
1375 }
1376 } else {
1377 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1378 encode_nfs4_verifier(xdr, &arg->u.verifier);
1379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 }
1381}
1382
1383static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1384{
Al Viro8687b632006-10-19 23:28:48 -07001385 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Benny Halevy13c65ce2009-08-14 17:19:25 +03001387 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001389 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001390 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001391 break;
1392 default:
1393 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001394 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001395 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001399static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 break;
1408 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 break;
1411 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001412 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001413 break;
1414 default:
1415 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 }
1417}
1418
1419static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1420{
Al Viro8687b632006-10-19 23:28:48 -07001421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Benny Halevy13c65ce2009-08-14 17:19:25 +03001423 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 encode_string(xdr, name->len, name->name);
1426}
1427
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001428static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429{
Al Viro8687b632006-10-19 23:28:48 -07001430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Benny Halevy13c65ce2009-08-14 17:19:25 +03001432 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 encode_delegation_type(xdr, type);
1435}
1436
1437static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1438{
Al Viro8687b632006-10-19 23:28:48 -07001439 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001441 p = reserve_space(xdr, 4);
1442 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1443 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 encode_string(xdr, name->len, name->name);
1445}
1446
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001447static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
Trond Myklebustab19b482012-03-04 18:13:57 -05001449 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 encode_openhdr(xdr, arg);
1451 encode_opentype(xdr, arg);
1452 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 case NFS4_OPEN_CLAIM_NULL:
1454 encode_claim_null(xdr, arg->name);
1455 break;
1456 case NFS4_OPEN_CLAIM_PREVIOUS:
1457 encode_claim_previous(xdr, arg->u.delegation_type);
1458 break;
1459 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1460 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1461 break;
1462 default:
1463 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465}
1466
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001467static 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 -07001468{
Trond Myklebustab19b482012-03-04 18:13:57 -05001469 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001470 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001471 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Trond Myklebustab19b482012-03-04 18:13:57 -05001476 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001477 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001478 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001479 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001482static void
Andy Adamsond0179312008-12-23 16:06:17 -05001483encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Trond Myklebustab19b482012-03-04 18:13:57 -05001485 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001486 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001489static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Trond Myklebustab19b482012-03-04 18:13:57 -05001491 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001494static 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 -07001495{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 if (ctx->state != NULL) {
Trond Myklebust1e3987c2012-03-04 18:13:56 -05001499 nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001500 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001501 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001502 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001504 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Trond Myklebustab19b482012-03-04 18:13:57 -05001511 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001512 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001513 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Benny Halevy13c65ce2009-08-14 17:19:25 +03001515 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001516 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001517 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520static 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 -07001521{
Trond Myklebust28331a42011-04-27 13:47:52 -04001522 uint32_t attrs[2] = {
1523 FATTR4_WORD0_RDATTR_ERROR,
1524 FATTR4_WORD1_MOUNTED_ON_FILEID,
1525 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001526 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001527 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001529 if (readdir->plus) {
1530 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001531 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001532 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1533 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1534 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1535 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001536 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001537 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001538 /* Use mounted_on_fileid only if the server supports it */
1539 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1540 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001541
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001542 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001543 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001544 encode_nfs4_verifier(xdr, &readdir->verifier);
1545 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001546 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001547 *p++ = cpu_to_be32(readdir->count);
1548 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001549
Benny Halevye75bc1c2009-08-14 17:18:54 +03001550 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001551 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001552 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001553 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1554 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001555 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001556 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001557 attrs[0] & readdir->bitmask[0],
1558 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001561static 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 -07001562{
Trond Myklebustab19b482012-03-04 18:13:57 -05001563 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Trond Myklebustab19b482012-03-04 18:13:57 -05001568 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001569 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static 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 -07001573{
Trond Myklebustab19b482012-03-04 18:13:57 -05001574 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001575 encode_string(xdr, oldname->len, oldname->name);
1576 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Chuck Leverbb4dae52012-03-01 17:01:48 -05001579static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1580 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001582 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001583 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001586static void
Andy Adamsond0179312008-12-23 16:06:17 -05001587encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001588{
Trond Myklebustab19b482012-03-04 18:13:57 -05001589 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001590}
1591
Chuck Lever9f06c712010-12-14 14:59:18 +00001592static void
Andy Adamsond0179312008-12-23 16:06:17 -05001593encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001594{
Al Viro8687b632006-10-19 23:28:48 -07001595 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001596
Trond Myklebustab19b482012-03-04 18:13:57 -05001597 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001598 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001599 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001600 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001601 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001602 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001603 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001604 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001605 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void
Andy Adamsond0179312008-12-23 16:06:17 -05001609encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static 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 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001617 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001621static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Al Viro8687b632006-10-19 23:28:48 -07001623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Trond Myklebust70019512012-03-04 20:49:32 -05001625 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001626 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001629 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001630 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1632 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001633 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001634 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001637static 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 -07001638{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001639 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1640 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001641 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001642 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Al Viro8687b632006-10-19 23:28:48 -07001647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Trond Myklebustab19b482012-03-04 18:13:57 -05001649 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001650 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001651 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
Benny Halevy13c65ce2009-08-14 17:19:25 +03001653 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001654 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001655 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001656 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001661static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Trond Myklebustab19b482012-03-04 18:13:57 -05001663 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001664 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001666
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001667static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1668{
Trond Myklebustab19b482012-03-04 18:13:57 -05001669 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001670 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001671}
1672
Benny Halevy99fe60d2009-04-01 09:22:29 -04001673#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001674/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001675static void encode_exchange_id(struct xdr_stream *xdr,
1676 struct nfs41_exchange_id_args *args,
1677 struct compound_hdr *hdr)
1678{
1679 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001680 char impl_name[NFS4_OPAQUE_LIMIT];
1681 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001682
Trond Myklebust70019512012-03-04 20:49:32 -05001683 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001684 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001685
1686 encode_string(xdr, args->id_len, args->id);
1687
Benny Halevy13c65ce2009-08-14 17:19:25 +03001688 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001689 *p++ = cpu_to_be32(args->flags);
1690 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001691
1692 if (send_implementation_id &&
1693 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1694 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1695 <= NFS4_OPAQUE_LIMIT + 1)
1696 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1697 utsname()->sysname, utsname()->release,
1698 utsname()->version, utsname()->machine);
1699
1700 if (len > 0) {
1701 *p = cpu_to_be32(1); /* implementation id array length=1 */
1702
1703 encode_string(xdr,
1704 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1705 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1706 encode_string(xdr, len, impl_name);
1707 /* just send zeros for nii_date - the date is in nii_name */
1708 p = reserve_space(xdr, 12);
1709 p = xdr_encode_hyper(p, 0);
1710 *p = cpu_to_be32(0);
1711 } else
1712 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001713}
Andy Adamsonfc931582009-04-01 09:22:31 -04001714
1715static void encode_create_session(struct xdr_stream *xdr,
1716 struct nfs41_create_session_args *args,
1717 struct compound_hdr *hdr)
1718{
1719 __be32 *p;
1720 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1721 uint32_t len;
1722 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001723 u32 max_resp_sz_cached;
1724
1725 /*
1726 * Assumes OPEN is the biggest non-idempotent compound.
1727 * 2 is the verifier.
1728 */
1729 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1730 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001731
Andy Adamsonfc931582009-04-01 09:22:31 -04001732 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1733 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001734
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001735 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1736 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001737 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001738 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1739 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001740
Andy Adamsonfc931582009-04-01 09:22:31 -04001741 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001742 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1744 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001745 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1747 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1748 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001749
1750 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001751 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1753 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1754 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1755 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1756 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1757 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001758
Benny Halevye75bc1c2009-08-14 17:18:54 +03001759 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001761 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001762
1763 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001764 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001765 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(0); /* UID */
1767 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001768 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001769}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001770
1771static void encode_destroy_session(struct xdr_stream *xdr,
1772 struct nfs4_session *session,
1773 struct compound_hdr *hdr)
1774{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001775 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1776 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001777}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001778
1779static void encode_reclaim_complete(struct xdr_stream *xdr,
1780 struct nfs41_reclaim_complete_args *args,
1781 struct compound_hdr *hdr)
1782{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001783 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1784 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001785}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001786#endif /* CONFIG_NFS_V4_1 */
1787
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001788static void encode_sequence(struct xdr_stream *xdr,
1789 const struct nfs4_sequence_args *args,
1790 struct compound_hdr *hdr)
1791{
1792#if defined(CONFIG_NFS_V4_1)
1793 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001794 struct nfs4_slot_table *tp;
1795 struct nfs4_slot *slot;
1796 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001797
1798 if (!session)
1799 return;
1800
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001801 tp = &session->fc_slot_table;
1802
1803 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1804 slot = tp->slots + args->sa_slotid;
1805
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001806 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001807
1808 /*
1809 * Sessionid + seqid + slotid + max slotid + cache_this
1810 */
1811 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1812 "max_slotid=%d cache_this=%d\n",
1813 __func__,
1814 ((u32 *)session->sess_id.data)[0],
1815 ((u32 *)session->sess_id.data)[1],
1816 ((u32 *)session->sess_id.data)[2],
1817 ((u32 *)session->sess_id.data)[3],
1818 slot->seq_nr, args->sa_slotid,
1819 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001820 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001821 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001822 *p++ = cpu_to_be32(slot->seq_nr);
1823 *p++ = cpu_to_be32(args->sa_slotid);
1824 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001825 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001826#endif /* CONFIG_NFS_V4_1 */
1827}
1828
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001829#ifdef CONFIG_NFS_V4_1
1830static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001831encode_getdevicelist(struct xdr_stream *xdr,
1832 const struct nfs4_getdevicelist_args *args,
1833 struct compound_hdr *hdr)
1834{
1835 __be32 *p;
1836 nfs4_verifier dummy = {
1837 .data = "dummmmmy",
1838 };
1839
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001840 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1841 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001842 *p++ = cpu_to_be32(args->layoutclass);
1843 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1844 xdr_encode_hyper(p, 0ULL); /* cookie */
1845 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001846}
1847
1848static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001849encode_getdeviceinfo(struct xdr_stream *xdr,
1850 const struct nfs4_getdeviceinfo_args *args,
1851 struct compound_hdr *hdr)
1852{
1853 __be32 *p;
1854
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001855 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1856 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001857 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1858 NFS4_DEVICEID4_SIZE);
1859 *p++ = cpu_to_be32(args->pdev->layout_type);
1860 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1861 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001862}
1863
1864static void
1865encode_layoutget(struct xdr_stream *xdr,
1866 const struct nfs4_layoutget_args *args,
1867 struct compound_hdr *hdr)
1868{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001869 __be32 *p;
1870
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001871 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1872 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001873 *p++ = cpu_to_be32(0); /* Signal layout available */
1874 *p++ = cpu_to_be32(args->type);
1875 *p++ = cpu_to_be32(args->range.iomode);
1876 p = xdr_encode_hyper(p, args->range.offset);
1877 p = xdr_encode_hyper(p, args->range.length);
1878 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001879 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001880 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001881
1882 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1883 __func__,
1884 args->type,
1885 args->range.iomode,
1886 (unsigned long)args->range.offset,
1887 (unsigned long)args->range.length,
1888 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001889}
Andy Adamson863a3c62011-03-23 13:27:54 +00001890
1891static int
1892encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001893 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001894 const struct nfs4_layoutcommit_args *args,
1895 struct compound_hdr *hdr)
1896{
1897 __be32 *p;
1898
1899 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1900 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1901
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001902 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1903 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001904 /* Only whole file layouts */
1905 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001906 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001907 *p = cpu_to_be32(0); /* reclaim */
1908 encode_nfs4_stateid(xdr, &args->stateid);
1909 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001910 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1911 p = xdr_encode_hyper(p, args->lastbytewritten);
1912 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1913 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001914
1915 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1916 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1917 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001918 else
1919 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001920
Andy Adamson863a3c62011-03-23 13:27:54 +00001921 return 0;
1922}
Benny Halevycbe82602011-05-22 19:52:37 +03001923
1924static void
1925encode_layoutreturn(struct xdr_stream *xdr,
1926 const struct nfs4_layoutreturn_args *args,
1927 struct compound_hdr *hdr)
1928{
1929 __be32 *p;
1930
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001931 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1932 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001933 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1934 *p++ = cpu_to_be32(args->layout_type);
1935 *p++ = cpu_to_be32(IOMODE_ANY);
1936 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001937 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001938 p = xdr_encode_hyper(p, 0);
1939 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1940 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001941 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001942 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001943 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1944 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1945 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001946 } else
1947 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001948}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001949
1950static int
1951encode_secinfo_no_name(struct xdr_stream *xdr,
1952 const struct nfs41_secinfo_no_name_args *args,
1953 struct compound_hdr *hdr)
1954{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001955 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1956 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001957 return 0;
1958}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001959
1960static void encode_test_stateid(struct xdr_stream *xdr,
1961 struct nfs41_test_stateid_args *args,
1962 struct compound_hdr *hdr)
1963{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001964 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1965 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001966 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001967}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001968
1969static void encode_free_stateid(struct xdr_stream *xdr,
1970 struct nfs41_free_stateid_args *args,
1971 struct compound_hdr *hdr)
1972{
Trond Myklebustab19b482012-03-04 18:13:57 -05001973 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001974 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001975}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001976#endif /* CONFIG_NFS_V4_1 */
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978/*
1979 * END OF "GENERIC" ENCODE ROUTINES.
1980 */
1981
Benny Halevy66cc0422009-04-01 09:22:10 -04001982static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1983{
1984#if defined(CONFIG_NFS_V4_1)
1985 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001986 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001987#endif /* CONFIG_NFS_V4_1 */
1988 return 0;
1989}
1990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991/*
1992 * Encode an ACCESS request
1993 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001994static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1995 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001998 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Chuck Lever9f06c712010-12-14 14:59:18 +00002001 encode_compound_hdr(xdr, req, &hdr);
2002 encode_sequence(xdr, &args->seq_args, &hdr);
2003 encode_putfh(xdr, args->fh, &hdr);
2004 encode_access(xdr, args->access, &hdr);
2005 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002006 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
2009/*
2010 * Encode LOOKUP request
2011 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002012static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2013 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002016 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Chuck Lever9f06c712010-12-14 14:59:18 +00002019 encode_compound_hdr(xdr, req, &hdr);
2020 encode_sequence(xdr, &args->seq_args, &hdr);
2021 encode_putfh(xdr, args->dir_fh, &hdr);
2022 encode_lookup(xdr, args->name, &hdr);
2023 encode_getfh(xdr, &hdr);
2024 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002025 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026}
2027
2028/*
2029 * Encode LOOKUP_ROOT request
2030 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002031static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2032 struct xdr_stream *xdr,
2033 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002036 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
Chuck Lever9f06c712010-12-14 14:59:18 +00002039 encode_compound_hdr(xdr, req, &hdr);
2040 encode_sequence(xdr, &args->seq_args, &hdr);
2041 encode_putrootfh(xdr, &hdr);
2042 encode_getfh(xdr, &hdr);
2043 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002044 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
2047/*
2048 * Encode REMOVE request
2049 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002050static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2051 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002054 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
Chuck Lever9f06c712010-12-14 14:59:18 +00002057 encode_compound_hdr(xdr, req, &hdr);
2058 encode_sequence(xdr, &args->seq_args, &hdr);
2059 encode_putfh(xdr, args->fh, &hdr);
2060 encode_remove(xdr, &args->name, &hdr);
2061 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002062 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063}
2064
2065/*
2066 * Encode RENAME request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2069 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002072 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Chuck Lever9f06c712010-12-14 14:59:18 +00002075 encode_compound_hdr(xdr, req, &hdr);
2076 encode_sequence(xdr, &args->seq_args, &hdr);
2077 encode_putfh(xdr, args->old_dir, &hdr);
2078 encode_savefh(xdr, &hdr);
2079 encode_putfh(xdr, args->new_dir, &hdr);
2080 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2081 encode_getfattr(xdr, args->bitmask, &hdr);
2082 encode_restorefh(xdr, &hdr);
2083 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002084 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085}
2086
2087/*
2088 * Encode LINK request
2089 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002090static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2091 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002094 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Chuck Lever9f06c712010-12-14 14:59:18 +00002097 encode_compound_hdr(xdr, req, &hdr);
2098 encode_sequence(xdr, &args->seq_args, &hdr);
2099 encode_putfh(xdr, args->fh, &hdr);
2100 encode_savefh(xdr, &hdr);
2101 encode_putfh(xdr, args->dir_fh, &hdr);
2102 encode_link(xdr, args->name, &hdr);
2103 encode_getfattr(xdr, args->bitmask, &hdr);
2104 encode_restorefh(xdr, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode CREATE request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2113 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->dir_fh, &hdr);
2122 encode_savefh(xdr, &hdr);
2123 encode_create(xdr, args, &hdr);
2124 encode_getfh(xdr, &hdr);
2125 encode_getfattr(xdr, args->bitmask, &hdr);
2126 encode_restorefh(xdr, &hdr);
2127 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode SYMLINK request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Chuck Lever9f06c712010-12-14 14:59:18 +00002137 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
2140/*
2141 * Encode GETATTR request
2142 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002143static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2144 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_sequence(xdr, &args->seq_args, &hdr);
2152 encode_putfh(xdr, args->fh, &hdr);
2153 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002154 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/*
2158 * Encode a CLOSE request
2159 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002160static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
Andy Adamson05d564f2008-12-23 16:06:15 -05002163 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002165 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Chuck Lever9f06c712010-12-14 14:59:18 +00002167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_close(xdr, args, &hdr);
2171 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002172 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
2175/*
2176 * Encode an OPEN request
2177 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002178static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->fh, &hdr);
2188 encode_savefh(xdr, &hdr);
2189 encode_open(xdr, args, &hdr);
2190 encode_getfh(xdr, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
2192 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002193 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
2198 * Encode an OPEN_CONFIRM request
2199 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002200static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2201 struct xdr_stream *xdr,
2202 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002205 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Chuck Lever9f06c712010-12-14 14:59:18 +00002208 encode_compound_hdr(xdr, req, &hdr);
2209 encode_putfh(xdr, args->fh, &hdr);
2210 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002211 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212}
2213
2214/*
2215 * Encode an OPEN request with no attributes.
2216 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002217static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2218 struct xdr_stream *xdr,
2219 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002222 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Chuck Lever9f06c712010-12-14 14:59:18 +00002225 encode_compound_hdr(xdr, req, &hdr);
2226 encode_sequence(xdr, &args->seq_args, &hdr);
2227 encode_putfh(xdr, args->fh, &hdr);
2228 encode_open(xdr, args, &hdr);
2229 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002230 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233/*
2234 * Encode an OPEN_DOWNGRADE request
2235 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002236static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2237 struct xdr_stream *xdr,
2238 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002241 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Chuck Lever9f06c712010-12-14 14:59:18 +00002244 encode_compound_hdr(xdr, req, &hdr);
2245 encode_sequence(xdr, &args->seq_args, &hdr);
2246 encode_putfh(xdr, args->fh, &hdr);
2247 encode_open_downgrade(xdr, args, &hdr);
2248 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002249 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
2252/*
2253 * Encode a LOCK request
2254 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002255static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2256 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Chuck Lever9f06c712010-12-14 14:59:18 +00002262 encode_compound_hdr(xdr, req, &hdr);
2263 encode_sequence(xdr, &args->seq_args, &hdr);
2264 encode_putfh(xdr, args->fh, &hdr);
2265 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode a LOCKT request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2273 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002276 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
Chuck Lever9f06c712010-12-14 14:59:18 +00002279 encode_compound_hdr(xdr, req, &hdr);
2280 encode_sequence(xdr, &args->seq_args, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
2282 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002283 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284}
2285
2286/*
2287 * Encode a LOCKU request
2288 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002289static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2290 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002293 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Chuck Lever9f06c712010-12-14 14:59:18 +00002296 encode_compound_hdr(xdr, req, &hdr);
2297 encode_sequence(xdr, &args->seq_args, &hdr);
2298 encode_putfh(xdr, args->fh, &hdr);
2299 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002300 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301}
2302
Chuck Lever9f06c712010-12-14 14:59:18 +00002303static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2304 struct xdr_stream *xdr,
2305 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002306{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002307 struct compound_hdr hdr = {
2308 .minorversion = 0,
2309 };
2310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002313 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002314}
2315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316/*
2317 * Encode a READLINK request
2318 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002319static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2320 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Chuck Lever9f06c712010-12-14 14:59:18 +00002326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002330
Benny Halevy28f56692009-04-01 09:22:09 -04002331 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002332 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * Encode a READDIR request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002350
Benny Halevy28f56692009-04-01 09:22:09 -04002351 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002352 args->pgbase, args->count);
2353 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002354 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002355 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002356 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
2359/*
2360 * Encode a READ request
2361 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002362static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2363 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002366 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
Chuck Lever9f06c712010-12-14 14:59:18 +00002369 encode_compound_hdr(xdr, req, &hdr);
2370 encode_sequence(xdr, &args->seq_args, &hdr);
2371 encode_putfh(xdr, args->fh, &hdr);
2372 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Benny Halevy28f56692009-04-01 09:22:09 -04002374 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002376 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002377 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
2380/*
2381 * Encode an SETATTR request
2382 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002383static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2384 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385{
Andy Adamson05d564f2008-12-23 16:06:15 -05002386 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002387 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002388 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Chuck Lever9f06c712010-12-14 14:59:18 +00002390 encode_compound_hdr(xdr, req, &hdr);
2391 encode_sequence(xdr, &args->seq_args, &hdr);
2392 encode_putfh(xdr, args->fh, &hdr);
2393 encode_setattr(xdr, args, args->server, &hdr);
2394 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002395 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396}
2397
2398/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002399 * Encode a GETACL request
2400 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002401static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2402 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002403{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002404 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002405 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002406 };
Benny Halevy28f56692009-04-01 09:22:09 -04002407 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002408
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);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002412 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002413 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002414
Benny Halevy28f56692009-04-01 09:22:09 -04002415 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002416 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002417
Andy Adamsond0179312008-12-23 16:06:17 -05002418 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002419}
2420
2421/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 * Encode a WRITE request
2423 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002424static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2425 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002428 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Chuck Lever9f06c712010-12-14 14:59:18 +00002431 encode_compound_hdr(xdr, req, &hdr);
2432 encode_sequence(xdr, &args->seq_args, &hdr);
2433 encode_putfh(xdr, args->fh, &hdr);
2434 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002435 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002436 if (args->bitmask)
2437 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002438 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
2440
2441/*
2442 * a COMMIT request
2443 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002444static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2445 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002448 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->fh, &hdr);
2454 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002455 if (args->bitmask)
2456 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002457 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458}
2459
2460/*
2461 * FSINFO request
2462 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002463static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2464 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002467 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
Chuck Lever9f06c712010-12-14 14:59:18 +00002470 encode_compound_hdr(xdr, req, &hdr);
2471 encode_sequence(xdr, &args->seq_args, &hdr);
2472 encode_putfh(xdr, args->fh, &hdr);
2473 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002474 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475}
2476
2477/*
2478 * a PATHCONF request
2479 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002480static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2481 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002484 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Chuck Lever9f06c712010-12-14 14:59:18 +00002487 encode_compound_hdr(xdr, req, &hdr);
2488 encode_sequence(xdr, &args->seq_args, &hdr);
2489 encode_putfh(xdr, args->fh, &hdr);
2490 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002491 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
2495/*
2496 * a STATFS request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2499 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
2508 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002509 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002510 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511}
2512
2513/*
2514 * GETATTR_BITMAP request
2515 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002516static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2517 struct xdr_stream *xdr,
2518 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002521 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
Chuck Lever9f06c712010-12-14 14:59:18 +00002524 encode_compound_hdr(xdr, req, &hdr);
2525 encode_sequence(xdr, &args->seq_args, &hdr);
2526 encode_putfh(xdr, args->fhandle, &hdr);
2527 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002528 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002529 FATTR4_WORD0_LINK_SUPPORT|
2530 FATTR4_WORD0_SYMLINK_SUPPORT|
2531 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * a RENEW request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2539 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002542 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 };
2544
Chuck Lever9f06c712010-12-14 14:59:18 +00002545 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002546 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002547 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
2550/*
2551 * a SETCLIENTID request
2552 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002553static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2554 struct xdr_stream *xdr,
2555 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002558 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 };
2560
Chuck Lever9f06c712010-12-14 14:59:18 +00002561 encode_compound_hdr(xdr, req, &hdr);
2562 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002563 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
2566/*
2567 * a SETCLIENTID_CONFIRM request
2568 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002569static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2570 struct xdr_stream *xdr,
2571 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002574 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 };
Fred Isamandae100c2011-07-30 20:52:37 -04002576 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
Chuck Lever9f06c712010-12-14 14:59:18 +00002578 encode_compound_hdr(xdr, req, &hdr);
2579 encode_setclientid_confirm(xdr, arg, &hdr);
2580 encode_putrootfh(xdr, &hdr);
2581 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002582 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/*
2586 * DELEGRETURN request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2589 struct xdr_stream *xdr,
2590 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002593 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->seq_args, &hdr);
2598 encode_putfh(xdr, args->fhandle, &hdr);
2599 encode_delegreturn(xdr, args->stateid, &hdr);
2600 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002601 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602}
2603
2604/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002605 * Encode FS_LOCATIONS request
2606 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002607static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2608 struct xdr_stream *xdr,
2609 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002610{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002611 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002612 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002613 };
Benny Halevy28f56692009-04-01 09:22:09 -04002614 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002615
Chuck Lever9f06c712010-12-14 14:59:18 +00002616 encode_compound_hdr(xdr, req, &hdr);
2617 encode_sequence(xdr, &args->seq_args, &hdr);
2618 encode_putfh(xdr, args->dir_fh, &hdr);
2619 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002620 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002621 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002622
Benny Halevy28f56692009-04-01 09:22:09 -04002623 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002624 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002625 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002626}
2627
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002628/*
2629 * Encode SECINFO request
2630 */
2631static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2632 struct xdr_stream *xdr,
2633 struct nfs4_secinfo_arg *args)
2634{
2635 struct compound_hdr hdr = {
2636 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2637 };
2638
2639 encode_compound_hdr(xdr, req, &hdr);
2640 encode_sequence(xdr, &args->seq_args, &hdr);
2641 encode_putfh(xdr, args->dir_fh, &hdr);
2642 encode_secinfo(xdr, args->name, &hdr);
2643 encode_nops(&hdr);
2644}
2645
Benny Halevy99fe60d2009-04-01 09:22:29 -04002646#if defined(CONFIG_NFS_V4_1)
2647/*
2648 * EXCHANGE_ID request
2649 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002650static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2651 struct xdr_stream *xdr,
2652 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002653{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002654 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002655 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002656 };
2657
Chuck Lever9f06c712010-12-14 14:59:18 +00002658 encode_compound_hdr(xdr, req, &hdr);
2659 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002660 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002661}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002662
2663/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002664 * a CREATE_SESSION request
2665 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002666static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002669{
Andy Adamsonfc931582009-04-01 09:22:31 -04002670 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002671 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002672 };
2673
Chuck Lever9f06c712010-12-14 14:59:18 +00002674 encode_compound_hdr(xdr, req, &hdr);
2675 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002676 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002677}
2678
2679/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002680 * a DESTROY_SESSION request
2681 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002682static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2683 struct xdr_stream *xdr,
2684 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002685{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002686 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002687 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002688 };
2689
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002692 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002693}
2694
2695/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002696 * a SEQUENCE request
2697 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002698static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2699 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002700{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002701 struct compound_hdr hdr = {
2702 .minorversion = nfs4_xdr_minorversion(args),
2703 };
2704
Chuck Lever9f06c712010-12-14 14:59:18 +00002705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002707 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002708}
2709
2710/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002711 * a GET_LEASE_TIME request
2712 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002713static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2714 struct xdr_stream *xdr,
2715 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002716{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002717 struct compound_hdr hdr = {
2718 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2719 };
Fred Isamandae100c2011-07-30 20:52:37 -04002720 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002721
Chuck Lever9f06c712010-12-14 14:59:18 +00002722 encode_compound_hdr(xdr, req, &hdr);
2723 encode_sequence(xdr, &args->la_seq_args, &hdr);
2724 encode_putrootfh(xdr, &hdr);
2725 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002726 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002727}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002728
2729/*
2730 * a RECLAIM_COMPLETE request
2731 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002732static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2733 struct xdr_stream *xdr,
2734 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002735{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002736 struct compound_hdr hdr = {
2737 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2738 };
2739
Chuck Lever9f06c712010-12-14 14:59:18 +00002740 encode_compound_hdr(xdr, req, &hdr);
2741 encode_sequence(xdr, &args->seq_args, &hdr);
2742 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002743 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002744}
2745
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002746/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002747 * Encode GETDEVICELIST request
2748 */
2749static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 struct nfs4_getdevicelist_args *args)
2752{
2753 struct compound_hdr hdr = {
2754 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2755 };
2756
2757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_sequence(xdr, &args->seq_args, &hdr);
2759 encode_putfh(xdr, args->fh, &hdr);
2760 encode_getdevicelist(xdr, args, &hdr);
2761 encode_nops(&hdr);
2762}
2763
2764/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002765 * Encode GETDEVICEINFO request
2766 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002767static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2768 struct xdr_stream *xdr,
2769 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002770{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002771 struct compound_hdr hdr = {
2772 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2773 };
2774
Chuck Lever9f06c712010-12-14 14:59:18 +00002775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_sequence(xdr, &args->seq_args, &hdr);
2777 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002778
2779 /* set up reply kvec. Subtract notification bitmap max size (2)
2780 * so that notification bitmap is put in xdr_buf tail */
2781 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2782 args->pdev->pages, args->pdev->pgbase,
2783 args->pdev->pglen);
2784
2785 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002786}
2787
2788/*
2789 * Encode LAYOUTGET request
2790 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002791static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2792 struct xdr_stream *xdr,
2793 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002794{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002795 struct compound_hdr hdr = {
2796 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2797 };
2798
Chuck Lever9f06c712010-12-14 14:59:18 +00002799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_sequence(xdr, &args->seq_args, &hdr);
2801 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2802 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002803
2804 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2805 args->layout.pages, 0, args->layout.pglen);
2806
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002807 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002808}
Andy Adamson863a3c62011-03-23 13:27:54 +00002809
2810/*
2811 * Encode LAYOUTCOMMIT request
2812 */
Benny Halevycbe82602011-05-22 19:52:37 +03002813static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2814 struct xdr_stream *xdr,
2815 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002816{
Benny Halevyac7db722011-05-22 19:53:48 +03002817 struct nfs4_layoutcommit_data *data =
2818 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002819 struct compound_hdr hdr = {
2820 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2821 };
2822
2823 encode_compound_hdr(xdr, req, &hdr);
2824 encode_sequence(xdr, &args->seq_args, &hdr);
2825 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002826 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002827 encode_getfattr(xdr, args->bitmask, &hdr);
2828 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002829}
2830
2831/*
2832 * Encode LAYOUTRETURN request
2833 */
2834static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs4_layoutreturn_args *args)
2837{
2838 struct compound_hdr hdr = {
2839 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2840 };
2841
2842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_sequence(xdr, &args->seq_args, &hdr);
2844 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2845 encode_layoutreturn(xdr, args, &hdr);
2846 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002847}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002848
2849/*
2850 * Encode SECINFO_NO_NAME request
2851 */
2852static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2853 struct xdr_stream *xdr,
2854 struct nfs41_secinfo_no_name_args *args)
2855{
2856 struct compound_hdr hdr = {
2857 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2858 };
2859
2860 encode_compound_hdr(xdr, req, &hdr);
2861 encode_sequence(xdr, &args->seq_args, &hdr);
2862 encode_putrootfh(xdr, &hdr);
2863 encode_secinfo_no_name(xdr, args, &hdr);
2864 encode_nops(&hdr);
2865 return 0;
2866}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002867
2868/*
2869 * Encode TEST_STATEID request
2870 */
2871static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2872 struct xdr_stream *xdr,
2873 struct nfs41_test_stateid_args *args)
2874{
2875 struct compound_hdr hdr = {
2876 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2877 };
2878
2879 encode_compound_hdr(xdr, req, &hdr);
2880 encode_sequence(xdr, &args->seq_args, &hdr);
2881 encode_test_stateid(xdr, args, &hdr);
2882 encode_nops(&hdr);
2883}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002884
2885/*
2886 * Encode FREE_STATEID request
2887 */
2888static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2889 struct xdr_stream *xdr,
2890 struct nfs41_free_stateid_args *args)
2891{
2892 struct compound_hdr hdr = {
2893 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2894 };
2895
2896 encode_compound_hdr(xdr, req, &hdr);
2897 encode_sequence(xdr, &args->seq_args, &hdr);
2898 encode_free_stateid(xdr, args, &hdr);
2899 encode_nops(&hdr);
2900}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002901#endif /* CONFIG_NFS_V4_1 */
2902
Benny Halevy686841b2009-08-14 17:19:48 +03002903static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2904{
2905 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2906 "Remaining buffer length is %tu words.\n",
2907 func, xdr->end - xdr->p);
2908}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909
Trond Myklebust683b57b2006-06-09 09:34:22 -04002910static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911{
Al Viro8687b632006-10-19 23:28:48 -07002912 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
Benny Halevyc0eae662009-08-14 17:20:14 +03002914 p = xdr_inline_decode(xdr, 4);
2915 if (unlikely(!p))
2916 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002917 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002918 p = xdr_inline_decode(xdr, *len);
2919 if (unlikely(!p))
2920 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 *string = (char *)p;
2922 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002923out_overflow:
2924 print_overflow_msg(__func__, xdr);
2925 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926}
2927
2928static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2929{
Al Viro8687b632006-10-19 23:28:48 -07002930 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
Benny Halevyc0eae662009-08-14 17:20:14 +03002932 p = xdr_inline_decode(xdr, 8);
2933 if (unlikely(!p))
2934 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002935 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002936 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002937
Benny Halevyc0eae662009-08-14 17:20:14 +03002938 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2939 if (unlikely(!p))
2940 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 hdr->tag = (char *)p;
2942 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002943 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002944 if (unlikely(hdr->nops < 1))
2945 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002947out_overflow:
2948 print_overflow_msg(__func__, xdr);
2949 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950}
2951
2952static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2953{
Al Viro8687b632006-10-19 23:28:48 -07002954 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 uint32_t opnum;
2956 int32_t nfserr;
2957
Benny Halevyc0eae662009-08-14 17:20:14 +03002958 p = xdr_inline_decode(xdr, 8);
2959 if (unlikely(!p))
2960 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002961 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002963 dprintk("nfs: Server returned operation"
2964 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 opnum, expected);
2966 return -EIO;
2967 }
Benny Halevycccddf42009-08-14 17:20:19 +03002968 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002970 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002972out_overflow:
2973 print_overflow_msg(__func__, xdr);
2974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975}
2976
2977/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002978static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979{
Al Viro8687b632006-10-19 23:28:48 -07002980 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002981 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 char *str;
2983
Benny Halevyc0eae662009-08-14 17:20:14 +03002984 p = xdr_inline_decode(xdr, 12);
2985 if (likely(p))
2986 return decode_opaque_inline(xdr, &strlen, &str);
2987 print_overflow_msg(__func__, xdr);
2988 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989}
2990
2991static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2992{
Al Viro8687b632006-10-19 23:28:48 -07002993 uint32_t bmlen;
2994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Benny Halevyc0eae662009-08-14 17:20:14 +03002996 p = xdr_inline_decode(xdr, 4);
2997 if (unlikely(!p))
2998 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002999 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
Fred Isamandae100c2011-07-30 20:52:37 -04003001 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003002 p = xdr_inline_decode(xdr, (bmlen << 2));
3003 if (unlikely(!p))
3004 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003006 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003007 if (bmlen > 1) {
3008 bitmap[1] = be32_to_cpup(p++);
3009 if (bmlen > 2)
3010 bitmap[2] = be32_to_cpup(p);
3011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
3013 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003014out_overflow:
3015 print_overflow_msg(__func__, xdr);
3016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017}
3018
Al Viro8687b632006-10-19 23:28:48 -07003019static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020{
Al Viro8687b632006-10-19 23:28:48 -07003021 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Benny Halevyc0eae662009-08-14 17:20:14 +03003023 p = xdr_inline_decode(xdr, 4);
3024 if (unlikely(!p))
3025 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003026 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 *savep = xdr->p;
3028 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003029out_overflow:
3030 print_overflow_msg(__func__, xdr);
3031 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032}
3033
3034static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3035{
3036 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003037 int ret;
3038 ret = decode_attr_bitmap(xdr, bitmask);
3039 if (unlikely(ret < 0))
3040 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3042 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003043 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3044 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3045 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 return 0;
3047}
3048
3049static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3050{
Al Viro8687b632006-10-19 23:28:48 -07003051 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003052 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053
3054 *type = 0;
3055 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3056 return -EIO;
3057 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003058 p = xdr_inline_decode(xdr, 4);
3059 if (unlikely(!p))
3060 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003061 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003063 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 return -EIO;
3065 }
3066 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003067 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003069 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003070 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003071out_overflow:
3072 print_overflow_msg(__func__, xdr);
3073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074}
3075
Chuck Lever264e6352012-03-01 17:02:05 -05003076static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3077 uint32_t *bitmap, uint32_t *type)
3078{
3079 __be32 *p;
3080
3081 *type = 0;
3082 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3083 return -EIO;
3084 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3085 p = xdr_inline_decode(xdr, 4);
3086 if (unlikely(!p))
3087 goto out_overflow;
3088 *type = be32_to_cpup(p);
3089 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3090 }
3091 dprintk("%s: expire type=0x%x\n", __func__, *type);
3092 return 0;
3093out_overflow:
3094 print_overflow_msg(__func__, xdr);
3095 return -EIO;
3096}
3097
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3099{
Al Viro8687b632006-10-19 23:28:48 -07003100 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003101 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102
3103 *change = 0;
3104 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3105 return -EIO;
3106 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003107 p = xdr_inline_decode(xdr, 8);
3108 if (unlikely(!p))
3109 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003110 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003112 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003114 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003116 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003117out_overflow:
3118 print_overflow_msg(__func__, xdr);
3119 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120}
3121
3122static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3123{
Al Viro8687b632006-10-19 23:28:48 -07003124 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003125 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
3127 *size = 0;
3128 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3129 return -EIO;
3130 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003131 p = xdr_inline_decode(xdr, 8);
3132 if (unlikely(!p))
3133 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003134 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003136 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003138 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003139 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003140out_overflow:
3141 print_overflow_msg(__func__, xdr);
3142 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143}
3144
3145static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3146{
Al Viro8687b632006-10-19 23:28:48 -07003147 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 *res = 0;
3150 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3151 return -EIO;
3152 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003153 p = xdr_inline_decode(xdr, 4);
3154 if (unlikely(!p))
3155 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003156 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3158 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003159 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003161out_overflow:
3162 print_overflow_msg(__func__, xdr);
3163 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164}
3165
3166static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3167{
Al Viro8687b632006-10-19 23:28:48 -07003168 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 *res = 0;
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3179 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003180 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003182out_overflow:
3183 print_overflow_msg(__func__, xdr);
3184 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185}
3186
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003187static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188{
Al Viro8687b632006-10-19 23:28:48 -07003189 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003190 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
3192 fsid->major = 0;
3193 fsid->minor = 0;
3194 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3195 return -EIO;
3196 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003197 p = xdr_inline_decode(xdr, 16);
3198 if (unlikely(!p))
3199 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003200 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003201 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003203 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003205 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 (unsigned long long)fsid->major,
3207 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003208 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003209out_overflow:
3210 print_overflow_msg(__func__, xdr);
3211 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212}
3213
3214static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3215{
Al Viro8687b632006-10-19 23:28:48 -07003216 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
3218 *res = 60;
3219 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3220 return -EIO;
3221 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003222 p = xdr_inline_decode(xdr, 4);
3223 if (unlikely(!p))
3224 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003225 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3227 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003228 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003230out_overflow:
3231 print_overflow_msg(__func__, xdr);
3232 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233}
3234
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003235static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003236{
3237 __be32 *p;
3238
3239 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3240 return -EIO;
3241 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3242 p = xdr_inline_decode(xdr, 4);
3243 if (unlikely(!p))
3244 goto out_overflow;
3245 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003246 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003247 }
3248 return 0;
3249out_overflow:
3250 print_overflow_msg(__func__, xdr);
3251 return -EIO;
3252}
3253
3254static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3255{
3256 __be32 *p;
3257 int len;
3258
Trond Myklebust7ad07352010-10-23 15:34:20 -04003259 if (fh != NULL)
3260 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003261
3262 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3263 return -EIO;
3264 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3265 p = xdr_inline_decode(xdr, 4);
3266 if (unlikely(!p))
3267 goto out_overflow;
3268 len = be32_to_cpup(p);
3269 if (len > NFS4_FHSIZE)
3270 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003271 p = xdr_inline_decode(xdr, len);
3272 if (unlikely(!p))
3273 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003274 if (fh != NULL) {
3275 memcpy(fh->data, p, len);
3276 fh->size = len;
3277 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003278 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3279 }
3280 return 0;
3281out_overflow:
3282 print_overflow_msg(__func__, xdr);
3283 return -EIO;
3284}
3285
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3287{
Al Viro8687b632006-10-19 23:28:48 -07003288 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289
3290 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3291 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3292 return -EIO;
3293 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003294 p = xdr_inline_decode(xdr, 4);
3295 if (unlikely(!p))
3296 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003297 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3299 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003300 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003302out_overflow:
3303 print_overflow_msg(__func__, xdr);
3304 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305}
3306
3307static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3308{
Al Viro8687b632006-10-19 23:28:48 -07003309 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003310 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
3312 *fileid = 0;
3313 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3314 return -EIO;
3315 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003316 p = xdr_inline_decode(xdr, 8);
3317 if (unlikely(!p))
3318 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003319 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003321 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003323 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003324 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328}
3329
Manoj Naik99baf622006-06-09 09:34:24 -04003330static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003333 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003334
3335 *fileid = 0;
3336 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3337 return -EIO;
3338 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003339 p = xdr_inline_decode(xdr, 8);
3340 if (unlikely(!p))
3341 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003342 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003343 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003344 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003345 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003346 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003347 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003348out_overflow:
3349 print_overflow_msg(__func__, xdr);
3350 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003351}
3352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3354{
Al Viro8687b632006-10-19 23:28:48 -07003355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 int status = 0;
3357
3358 *res = 0;
3359 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3360 return -EIO;
3361 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003362 p = xdr_inline_decode(xdr, 8);
3363 if (unlikely(!p))
3364 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003365 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3367 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003368 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003370out_overflow:
3371 print_overflow_msg(__func__, xdr);
3372 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373}
3374
3375static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3376{
Al Viro8687b632006-10-19 23:28:48 -07003377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 int status = 0;
3379
3380 *res = 0;
3381 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3382 return -EIO;
3383 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003384 p = xdr_inline_decode(xdr, 8);
3385 if (unlikely(!p))
3386 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003387 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
3396
3397static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3398{
Al Viro8687b632006-10-19 23:28:48 -07003399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 int status = 0;
3401
3402 *res = 0;
3403 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3404 return -EIO;
3405 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003406 p = xdr_inline_decode(xdr, 8);
3407 if (unlikely(!p))
3408 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003409 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3411 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003412 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003414out_overflow:
3415 print_overflow_msg(__func__, xdr);
3416 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417}
3418
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003419static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3420{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003421 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003422 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003423 int status = 0;
3424
Benny Halevyc0eae662009-08-14 17:20:14 +03003425 p = xdr_inline_decode(xdr, 4);
3426 if (unlikely(!p))
3427 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003428 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003429 if (n == 0)
3430 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003431 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003432 path->ncomponents = 0;
3433 while (path->ncomponents < n) {
3434 struct nfs4_string *component = &path->components[path->ncomponents];
3435 status = decode_opaque_inline(xdr, &component->len, &component->data);
3436 if (unlikely(status != 0))
3437 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003438 if (unlikely(nfs_debug & NFSDBG_XDR))
3439 pr_cont("%s%.*s ",
3440 (path->ncomponents != n ? "/ " : ""),
3441 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003442 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3443 path->ncomponents++;
3444 else {
3445 dprintk("cannot parse %d components in path\n", n);
3446 goto out_eio;
3447 }
3448 }
3449out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003450 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003451root_path:
3452/* a root pathname is sent as a zero component4 */
3453 path->ncomponents = 1;
3454 path->components[0].len=0;
3455 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003456 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003457 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003458out_eio:
3459 dprintk(" status %d", status);
3460 status = -EIO;
3461 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003462out_overflow:
3463 print_overflow_msg(__func__, xdr);
3464 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003465}
3466
3467static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003468{
3469 int n;
Al Viro8687b632006-10-19 23:28:48 -07003470 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003471 int status = -EIO;
3472
3473 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3474 goto out;
3475 status = 0;
3476 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3477 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003478 status = -EIO;
3479 /* Ignore borken servers that return unrequested attrs */
3480 if (unlikely(res == NULL))
3481 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003482 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003483 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003484 if (unlikely(status != 0))
3485 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003486 p = xdr_inline_decode(xdr, 4);
3487 if (unlikely(!p))
3488 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003489 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003490 if (n <= 0)
3491 goto out_eio;
3492 res->nlocations = 0;
3493 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003494 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003495 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003496
Benny Halevyc0eae662009-08-14 17:20:14 +03003497 p = xdr_inline_decode(xdr, 4);
3498 if (unlikely(!p))
3499 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003500 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003501
3502 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003503 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 while (loc->nservers < m) {
3505 struct nfs4_string *server = &loc->servers[loc->nservers];
3506 status = decode_opaque_inline(xdr, &server->len, &server->data);
3507 if (unlikely(status != 0))
3508 goto out_eio;
3509 dprintk("%s ", server->data);
3510 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3511 loc->nservers++;
3512 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003513 unsigned int i;
3514 dprintk("%s: using first %u of %u servers "
3515 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003516 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003517 NFS4_FS_LOCATION_MAXSERVERS,
3518 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003519 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003520 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003521 char *data;
3522 status = decode_opaque_inline(xdr, &len, &data);
3523 if (unlikely(status != 0))
3524 goto out_eio;
3525 }
3526 }
3527 }
3528 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003529 if (unlikely(status != 0))
3530 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003531 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003532 res->nlocations++;
3533 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003534 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003535 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003536out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003537 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003538 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003539out_overflow:
3540 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003541out_eio:
3542 status = -EIO;
3543 goto out;
3544}
3545
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3547{
Al Viro8687b632006-10-19 23:28:48 -07003548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 int status = 0;
3550
3551 *res = 0;
3552 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3553 return -EIO;
3554 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003555 p = xdr_inline_decode(xdr, 8);
3556 if (unlikely(!p))
3557 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003558 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3560 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003561 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003563out_overflow:
3564 print_overflow_msg(__func__, xdr);
3565 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566}
3567
3568static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3569{
Al Viro8687b632006-10-19 23:28:48 -07003570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 int status = 0;
3572
3573 *maxlink = 1;
3574 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3575 return -EIO;
3576 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003577 p = xdr_inline_decode(xdr, 4);
3578 if (unlikely(!p))
3579 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003580 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3582 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003583 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003585out_overflow:
3586 print_overflow_msg(__func__, xdr);
3587 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588}
3589
3590static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3591{
Al Viro8687b632006-10-19 23:28:48 -07003592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 int status = 0;
3594
3595 *maxname = 1024;
3596 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3597 return -EIO;
3598 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003599 p = xdr_inline_decode(xdr, 4);
3600 if (unlikely(!p))
3601 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003602 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3604 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003605 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003607out_overflow:
3608 print_overflow_msg(__func__, xdr);
3609 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610}
3611
3612static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3613{
Al Viro8687b632006-10-19 23:28:48 -07003614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 int status = 0;
3616
3617 *res = 1024;
3618 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3619 return -EIO;
3620 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3621 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003622 p = xdr_inline_decode(xdr, 8);
3623 if (unlikely(!p))
3624 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003625 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 if (maxread > 0x7FFFFFFF)
3627 maxread = 0x7FFFFFFF;
3628 *res = (uint32_t)maxread;
3629 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3630 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003631 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003633out_overflow:
3634 print_overflow_msg(__func__, xdr);
3635 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636}
3637
3638static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3639{
Al Viro8687b632006-10-19 23:28:48 -07003640 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 int status = 0;
3642
3643 *res = 1024;
3644 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3645 return -EIO;
3646 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3647 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003648 p = xdr_inline_decode(xdr, 8);
3649 if (unlikely(!p))
3650 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003651 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 if (maxwrite > 0x7FFFFFFF)
3653 maxwrite = 0x7FFFFFFF;
3654 *res = (uint32_t)maxwrite;
3655 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3656 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003657 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003659out_overflow:
3660 print_overflow_msg(__func__, xdr);
3661 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662}
3663
Trond Myklebustbca79472009-03-11 14:10:26 -04003664static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665{
Trond Myklebustbca79472009-03-11 14:10:26 -04003666 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003667 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003668 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 *mode = 0;
3671 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3672 return -EIO;
3673 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003674 p = xdr_inline_decode(xdr, 4);
3675 if (unlikely(!p))
3676 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003677 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003678 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003680 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003682 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003683 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003684out_overflow:
3685 print_overflow_msg(__func__, xdr);
3686 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687}
3688
3689static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3690{
Al Viro8687b632006-10-19 23:28:48 -07003691 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003692 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693
3694 *nlink = 1;
3695 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3696 return -EIO;
3697 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003698 p = xdr_inline_decode(xdr, 4);
3699 if (unlikely(!p))
3700 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003701 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003703 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003705 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003706 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003707out_overflow:
3708 print_overflow_msg(__func__, xdr);
3709 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710}
3711
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003712static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003713 const struct nfs_server *server, uint32_t *uid,
3714 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715{
Al Viro8687b632006-10-19 23:28:48 -07003716 uint32_t len;
3717 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003718 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719
3720 *uid = -2;
3721 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3722 return -EIO;
3723 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003724 p = xdr_inline_decode(xdr, 4);
3725 if (unlikely(!p))
3726 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003727 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003728 p = xdr_inline_decode(xdr, len);
3729 if (unlikely(!p))
3730 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003731 if (owner_name != NULL) {
3732 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3733 if (owner_name->data != NULL) {
3734 owner_name->len = len;
3735 ret = NFS_ATTR_FATTR_OWNER_NAME;
3736 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003737 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003738 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003739 ret = NFS_ATTR_FATTR_OWNER;
3740 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003742 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003744 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3747 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003748 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003750out_overflow:
3751 print_overflow_msg(__func__, xdr);
3752 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753}
3754
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003755static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003756 const struct nfs_server *server, uint32_t *gid,
3757 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758{
Al Viro8687b632006-10-19 23:28:48 -07003759 uint32_t len;
3760 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003761 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762
3763 *gid = -2;
3764 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3765 return -EIO;
3766 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003767 p = xdr_inline_decode(xdr, 4);
3768 if (unlikely(!p))
3769 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003770 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003771 p = xdr_inline_decode(xdr, len);
3772 if (unlikely(!p))
3773 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003774 if (group_name != NULL) {
3775 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3776 if (group_name->data != NULL) {
3777 group_name->len = len;
3778 ret = NFS_ATTR_FATTR_GROUP_NAME;
3779 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003780 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003781 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003782 ret = NFS_ATTR_FATTR_GROUP;
3783 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003785 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003787 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003788 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3790 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003791 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003793out_overflow:
3794 print_overflow_msg(__func__, xdr);
3795 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796}
3797
3798static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3799{
Al Viro8687b632006-10-19 23:28:48 -07003800 uint32_t major = 0, minor = 0;
3801 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003802 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803
3804 *rdev = MKDEV(0,0);
3805 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3806 return -EIO;
3807 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3808 dev_t tmp;
3809
Benny Halevyc0eae662009-08-14 17:20:14 +03003810 p = xdr_inline_decode(xdr, 8);
3811 if (unlikely(!p))
3812 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003813 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003814 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 tmp = MKDEV(major, minor);
3816 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3817 *rdev = tmp;
3818 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003822 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823out_overflow:
3824 print_overflow_msg(__func__, xdr);
3825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826}
3827
3828static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3829{
Al Viro8687b632006-10-19 23:28:48 -07003830 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 int status = 0;
3832
3833 *res = 0;
3834 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3835 return -EIO;
3836 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003837 p = xdr_inline_decode(xdr, 8);
3838 if (unlikely(!p))
3839 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003840 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3842 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003843 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003845out_overflow:
3846 print_overflow_msg(__func__, xdr);
3847 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848}
3849
3850static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3851{
Al Viro8687b632006-10-19 23:28:48 -07003852 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 int status = 0;
3854
3855 *res = 0;
3856 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3857 return -EIO;
3858 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003859 p = xdr_inline_decode(xdr, 8);
3860 if (unlikely(!p))
3861 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003862 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3864 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003865 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003867out_overflow:
3868 print_overflow_msg(__func__, xdr);
3869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870}
3871
3872static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3873{
Al Viro8687b632006-10-19 23:28:48 -07003874 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 int status = 0;
3876
3877 *res = 0;
3878 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3879 return -EIO;
3880 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003881 p = xdr_inline_decode(xdr, 8);
3882 if (unlikely(!p))
3883 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003884 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3886 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003887 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003889out_overflow:
3890 print_overflow_msg(__func__, xdr);
3891 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
3894static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3895{
Al Viro8687b632006-10-19 23:28:48 -07003896 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898
3899 *used = 0;
3900 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3901 return -EIO;
3902 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003903 p = xdr_inline_decode(xdr, 8);
3904 if (unlikely(!p))
3905 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003906 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003908 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003910 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003912 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003913out_overflow:
3914 print_overflow_msg(__func__, xdr);
3915 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916}
3917
3918static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3919{
Al Viro8687b632006-10-19 23:28:48 -07003920 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 uint64_t sec;
3922 uint32_t nsec;
3923
Benny Halevyc0eae662009-08-14 17:20:14 +03003924 p = xdr_inline_decode(xdr, 12);
3925 if (unlikely(!p))
3926 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003927 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003928 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 time->tv_sec = (time_t)sec;
3930 time->tv_nsec = (long)nsec;
3931 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003932out_overflow:
3933 print_overflow_msg(__func__, xdr);
3934 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935}
3936
3937static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3938{
3939 int status = 0;
3940
3941 time->tv_sec = 0;
3942 time->tv_nsec = 0;
3943 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3944 return -EIO;
3945 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3946 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003947 if (status == 0)
3948 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3950 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003951 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 return status;
3953}
3954
3955static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3956{
3957 int status = 0;
3958
3959 time->tv_sec = 0;
3960 time->tv_nsec = 0;
3961 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3962 return -EIO;
3963 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3964 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003965 if (status == 0)
3966 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3968 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003969 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 return status;
3971}
3972
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003973static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3974 struct timespec *time)
3975{
3976 int status = 0;
3977
3978 time->tv_sec = 0;
3979 time->tv_nsec = 0;
3980 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3981 return -EIO;
3982 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3983 status = decode_attr_time(xdr, time);
3984 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3985 }
3986 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3987 (long)time->tv_nsec);
3988 return status;
3989}
3990
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3992{
3993 int status = 0;
3994
3995 time->tv_sec = 0;
3996 time->tv_nsec = 0;
3997 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3998 return -EIO;
3999 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4000 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004001 if (status == 0)
4002 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4004 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004005 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 return status;
4007}
4008
Al Viro8687b632006-10-19 23:28:48 -07004009static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010{
4011 unsigned int attrwords = XDR_QUADLEN(attrlen);
4012 unsigned int nwords = xdr->p - savep;
4013
4014 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004015 dprintk("%s: server returned incorrect attribute length: "
4016 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004017 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 attrwords << 2,
4019 (attrwords < nwords) ? '<' : '>',
4020 nwords << 2);
4021 return -EIO;
4022 }
4023 return 0;
4024}
4025
4026static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4027{
Al Viro8687b632006-10-19 23:28:48 -07004028 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029
Benny Halevyc0eae662009-08-14 17:20:14 +03004030 p = xdr_inline_decode(xdr, 20);
4031 if (unlikely(!p))
4032 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004033 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004034 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004035 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004037out_overflow:
4038 print_overflow_msg(__func__, xdr);
4039 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040}
4041
4042static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4043{
Al Viro8687b632006-10-19 23:28:48 -07004044 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 uint32_t supp, acc;
4046 int status;
4047
4048 status = decode_op_hdr(xdr, OP_ACCESS);
4049 if (status)
4050 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004051 p = xdr_inline_decode(xdr, 8);
4052 if (unlikely(!p))
4053 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004054 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004055 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 access->supported = supp;
4057 access->access = acc;
4058 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004059out_overflow:
4060 print_overflow_msg(__func__, xdr);
4061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062}
4063
Benny Halevy07d30432009-08-14 17:19:52 +03004064static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065{
Al Viro8687b632006-10-19 23:28:48 -07004066 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004067
4068 p = xdr_inline_decode(xdr, len);
4069 if (likely(p)) {
4070 memcpy(buf, p, len);
4071 return 0;
4072 }
4073 print_overflow_msg(__func__, xdr);
4074 return -EIO;
4075}
4076
4077static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4078{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004079 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4083{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 int status;
4085
4086 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004087 if (status != -EIO)
4088 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004089 if (!status)
4090 status = decode_stateid(xdr, &res->stateid);
4091 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092}
4093
Benny Halevydb942bb2009-08-14 17:19:56 +03004094static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4095{
Chuck Levercd937102012-03-02 17:14:31 -05004096 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097}
4098
4099static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4100{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 int status;
4102
4103 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004104 if (!status)
4105 status = decode_verifier(xdr, res->verf->verifier);
4106 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107}
4108
4109static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4110{
Al Viro8687b632006-10-19 23:28:48 -07004111 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 uint32_t bmlen;
4113 int status;
4114
4115 status = decode_op_hdr(xdr, OP_CREATE);
4116 if (status)
4117 return status;
4118 if ((status = decode_change_info(xdr, cinfo)))
4119 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004120 p = xdr_inline_decode(xdr, 4);
4121 if (unlikely(!p))
4122 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004123 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004124 p = xdr_inline_decode(xdr, bmlen << 2);
4125 if (likely(p))
4126 return 0;
4127out_overflow:
4128 print_overflow_msg(__func__, xdr);
4129 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130}
4131
4132static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4133{
Al Viro8687b632006-10-19 23:28:48 -07004134 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004135 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 int status;
4137
4138 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4139 goto xdr_error;
4140 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4141 goto xdr_error;
4142 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4143 goto xdr_error;
4144 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4145 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004146 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4147 &res->fh_expire_type)) != 0)
4148 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4150 goto xdr_error;
4151 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4152 goto xdr_error;
4153 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4154 goto xdr_error;
4155 status = verify_attr_len(xdr, savep, attrlen);
4156xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004157 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 return status;
4159}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004160
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4162{
Al Viro8687b632006-10-19 23:28:48 -07004163 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004164 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004166
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4168 goto xdr_error;
4169 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4170 goto xdr_error;
4171 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4172 goto xdr_error;
4173
4174 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4175 goto xdr_error;
4176 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4177 goto xdr_error;
4178 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4179 goto xdr_error;
4180 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4181 goto xdr_error;
4182 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4183 goto xdr_error;
4184 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4185 goto xdr_error;
4186
4187 status = verify_attr_len(xdr, savep, attrlen);
4188xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004189 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 return status;
4191}
4192
4193static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4194{
Al Viro8687b632006-10-19 23:28:48 -07004195 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004196 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004198
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4200 goto xdr_error;
4201 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4202 goto xdr_error;
4203 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4204 goto xdr_error;
4205
4206 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4207 goto xdr_error;
4208 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4209 goto xdr_error;
4210
4211 status = verify_attr_len(xdr, savep, attrlen);
4212xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004213 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 return status;
4215}
4216
Bryan Schumakerae42c702010-10-21 16:33:17 -04004217static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4218 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004219 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004220 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221{
Trond Myklebustbca79472009-03-11 14:10:26 -04004222 int status;
4223 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004224 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004225 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004227 status = decode_attr_type(xdr, bitmap, &type);
4228 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004230 fattr->mode = 0;
4231 if (status != 0) {
4232 fattr->mode |= nfs_type2fmt[type];
4233 fattr->valid |= status;
4234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004236 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4237 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004239 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004240
4241 status = decode_attr_size(xdr, bitmap, &fattr->size);
4242 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004244 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004245
4246 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4247 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004249 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004250
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004251 err = 0;
4252 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004253 if (status < 0)
4254 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004255 if (err == -NFS4ERR_WRONGSEC)
4256 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004257
4258 status = decode_attr_filehandle(xdr, bitmap, fh);
4259 if (status < 0)
4260 goto xdr_error;
4261
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004262 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4263 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004265 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004266
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004267 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004268 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004269 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004270 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004271
4272 status = decode_attr_mode(xdr, bitmap, &fmode);
4273 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004275 if (status != 0) {
4276 fattr->mode |= fmode;
4277 fattr->valid |= status;
4278 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004279
4280 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4281 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004283 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004284
Trond Myklebust6926afd2012-01-07 13:22:46 -05004285 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004286 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004288 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004289
Trond Myklebust6926afd2012-01-07 13:22:46 -05004290 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004291 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004293 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004294
4295 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4296 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004298 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004299
4300 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4301 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004303 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004304
4305 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4306 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004308 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004309
4310 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4311 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004313 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004314
4315 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4316 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004318 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004319
Trond Myklebust28331a42011-04-27 13:47:52 -04004320 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004321 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004322 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004323 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004324
Bryan Schumakerae42c702010-10-21 16:33:17 -04004325xdr_error:
4326 dprintk("%s: xdr returned %d\n", __func__, -status);
4327 return status;
4328}
4329
4330static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004331 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4332 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004333{
4334 __be32 *savep;
4335 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004336 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004337 int status;
4338
4339 status = decode_op_hdr(xdr, OP_GETATTR);
4340 if (status < 0)
4341 goto xdr_error;
4342
4343 status = decode_attr_bitmap(xdr, bitmap);
4344 if (status < 0)
4345 goto xdr_error;
4346
4347 status = decode_attr_length(xdr, &attrlen, &savep);
4348 if (status < 0)
4349 goto xdr_error;
4350
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004351 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004352 if (status < 0)
4353 goto xdr_error;
4354
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004355 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004357 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 return status;
4359}
4360
Bryan Schumakerae42c702010-10-21 16:33:17 -04004361static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004362 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004363{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004364 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004365}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366
Andy Adamson504913f2010-10-20 00:17:57 -04004367/*
4368 * Decode potentially multiple layout types. Currently we only support
4369 * one layout driver per file system.
4370 */
4371static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4372 uint32_t *layouttype)
4373{
4374 uint32_t *p;
4375 int num;
4376
4377 p = xdr_inline_decode(xdr, 4);
4378 if (unlikely(!p))
4379 goto out_overflow;
4380 num = be32_to_cpup(p);
4381
4382 /* pNFS is not supported by the underlying file system */
4383 if (num == 0) {
4384 *layouttype = 0;
4385 return 0;
4386 }
4387 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004388 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4389 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004390
4391 /* Decode and set first layout type, move xdr->p past unused types */
4392 p = xdr_inline_decode(xdr, num * 4);
4393 if (unlikely(!p))
4394 goto out_overflow;
4395 *layouttype = be32_to_cpup(p);
4396 return 0;
4397out_overflow:
4398 print_overflow_msg(__func__, xdr);
4399 return -EIO;
4400}
4401
4402/*
4403 * The type of file system exported.
4404 * Note we must ensure that layouttype is set in any non-error case.
4405 */
4406static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4407 uint32_t *layouttype)
4408{
4409 int status = 0;
4410
4411 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4412 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4413 return -EIO;
4414 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4415 status = decode_first_pnfs_layout_type(xdr, layouttype);
4416 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4417 } else
4418 *layouttype = 0;
4419 return status;
4420}
4421
Fred Isamandae100c2011-07-30 20:52:37 -04004422/*
4423 * The prefered block size for layout directed io
4424 */
4425static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4426 uint32_t *res)
4427{
4428 __be32 *p;
4429
4430 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4431 *res = 0;
4432 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4433 p = xdr_inline_decode(xdr, 4);
4434 if (unlikely(!p)) {
4435 print_overflow_msg(__func__, xdr);
4436 return -EIO;
4437 }
4438 *res = be32_to_cpup(p);
4439 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4440 }
4441 return 0;
4442}
4443
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4445{
Al Viro8687b632006-10-19 23:28:48 -07004446 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004447 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 int status;
4449
4450 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4451 goto xdr_error;
4452 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4453 goto xdr_error;
4454 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4455 goto xdr_error;
4456
4457 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4458
4459 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4460 goto xdr_error;
4461 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4462 goto xdr_error;
4463 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4464 goto xdr_error;
4465 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4466 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4467 goto xdr_error;
4468 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004469 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4470 if (status != 0)
4471 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004472 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4473 if (status != 0)
4474 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004475 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4476 if (status)
4477 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478
4479 status = verify_attr_len(xdr, savep, attrlen);
4480xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004481 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 return status;
4483}
4484
4485static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4486{
Al Viro8687b632006-10-19 23:28:48 -07004487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 uint32_t len;
4489 int status;
4490
Trond Myklebust99367812007-07-17 21:52:41 -04004491 /* Zero handle first to allow comparisons */
4492 memset(fh, 0, sizeof(*fh));
4493
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 status = decode_op_hdr(xdr, OP_GETFH);
4495 if (status)
4496 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497
Benny Halevyc0eae662009-08-14 17:20:14 +03004498 p = xdr_inline_decode(xdr, 4);
4499 if (unlikely(!p))
4500 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004501 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 if (len > NFS4_FHSIZE)
4503 return -EIO;
4504 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004505 p = xdr_inline_decode(xdr, len);
4506 if (unlikely(!p))
4507 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004508 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004510out_overflow:
4511 print_overflow_msg(__func__, xdr);
4512 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513}
4514
4515static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4516{
4517 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004518
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 status = decode_op_hdr(xdr, OP_LINK);
4520 if (status)
4521 return status;
4522 return decode_change_info(xdr, cinfo);
4523}
4524
4525/*
4526 * We create the owner, so we know a proper owner.id length is 4.
4527 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004528static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004530 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004531 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004532 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004534 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004535 if (unlikely(!p))
4536 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004537 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004538 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004539 type = be32_to_cpup(p++); /* 4 byte read */
4540 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004541 fl->fl_start = (loff_t)offset;
4542 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4543 if (length == ~(uint64_t)0)
4544 fl->fl_end = OFFSET_MAX;
4545 fl->fl_type = F_WRLCK;
4546 if (type & 1)
4547 fl->fl_type = F_RDLCK;
4548 fl->fl_pid = 0;
4549 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004550 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4551 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4552 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004553 if (likely(p))
4554 return -NFS4ERR_DENIED;
4555out_overflow:
4556 print_overflow_msg(__func__, xdr);
4557 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558}
4559
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004560static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 int status;
4563
4564 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004565 if (status == -EIO)
4566 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004568 status = decode_stateid(xdr, &res->stateid);
4569 if (unlikely(status))
4570 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004572 status = decode_lock_denied(xdr, NULL);
4573 if (res->open_seqid != NULL)
4574 nfs_increment_open_seqid(status, res->open_seqid);
4575 nfs_increment_lock_seqid(status, res->lock_seqid);
4576out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 return status;
4578}
4579
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004580static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581{
4582 int status;
4583 status = decode_op_hdr(xdr, OP_LOCKT);
4584 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004585 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 return status;
4587}
4588
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004589static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 int status;
4592
4593 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004594 if (status != -EIO)
4595 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004596 if (status == 0)
4597 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 return status;
4599}
4600
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004601static int decode_release_lockowner(struct xdr_stream *xdr)
4602{
4603 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4604}
4605
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606static int decode_lookup(struct xdr_stream *xdr)
4607{
4608 return decode_op_hdr(xdr, OP_LOOKUP);
4609}
4610
4611/* This is too sick! */
4612static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4613{
Andy Adamson05d564f2008-12-23 16:06:15 -05004614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615 uint32_t limit_type, nblocks, blocksize;
4616
Benny Halevyc0eae662009-08-14 17:20:14 +03004617 p = xdr_inline_decode(xdr, 12);
4618 if (unlikely(!p))
4619 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004620 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004622 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004623 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004624 break;
4625 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004626 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004627 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004628 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 }
4630 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004631out_overflow:
4632 print_overflow_msg(__func__, xdr);
4633 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634}
4635
4636static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4637{
Andy Adamson05d564f2008-12-23 16:06:15 -05004638 __be32 *p;
4639 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004640 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641
Benny Halevyc0eae662009-08-14 17:20:14 +03004642 p = xdr_inline_decode(xdr, 4);
4643 if (unlikely(!p))
4644 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004645 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4647 res->delegation_type = 0;
4648 return 0;
4649 }
Benny Halevy07d30432009-08-14 17:19:52 +03004650 status = decode_stateid(xdr, &res->delegation);
4651 if (unlikely(status))
4652 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004653 p = xdr_inline_decode(xdr, 4);
4654 if (unlikely(!p))
4655 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004656 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004657
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004659 case NFS4_OPEN_DELEGATE_READ:
4660 res->delegation_type = FMODE_READ;
4661 break;
4662 case NFS4_OPEN_DELEGATE_WRITE:
4663 res->delegation_type = FMODE_WRITE|FMODE_READ;
4664 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 return -EIO;
4666 }
David Howells7539bba2006-08-22 20:06:09 -04004667 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004668out_overflow:
4669 print_overflow_msg(__func__, xdr);
4670 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671}
4672
4673static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4674{
Andy Adamson05d564f2008-12-23 16:06:15 -05004675 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004676 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004677 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678
Andy Adamson05d564f2008-12-23 16:06:15 -05004679 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004680 if (status != -EIO)
4681 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004682 if (!status)
4683 status = decode_stateid(xdr, &res->stateid);
4684 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004685 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686
Andy Adamson05d564f2008-12-23 16:06:15 -05004687 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688
Benny Halevyc0eae662009-08-14 17:20:14 +03004689 p = xdr_inline_decode(xdr, 8);
4690 if (unlikely(!p))
4691 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004692 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004693 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004694 if (bmlen > 10)
4695 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696
Benny Halevyc0eae662009-08-14 17:20:14 +03004697 p = xdr_inline_decode(xdr, bmlen << 2);
4698 if (unlikely(!p))
4699 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004700 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4701 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004702 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004703 for (; i < NFS4_BITMAP_SIZE; i++)
4704 res->attrset[i] = 0;
4705
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 return decode_delegation(xdr, res);
4707xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004708 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004710out_overflow:
4711 print_overflow_msg(__func__, xdr);
4712 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713}
4714
4715static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4716{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 int status;
4718
Andy Adamson05d564f2008-12-23 16:06:15 -05004719 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004720 if (status != -EIO)
4721 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004722 if (!status)
4723 status = decode_stateid(xdr, &res->stateid);
4724 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725}
4726
4727static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4728{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 int status;
4730
4731 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004732 if (status != -EIO)
4733 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004734 if (!status)
4735 status = decode_stateid(xdr, &res->stateid);
4736 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737}
4738
4739static int decode_putfh(struct xdr_stream *xdr)
4740{
4741 return decode_op_hdr(xdr, OP_PUTFH);
4742}
4743
4744static int decode_putrootfh(struct xdr_stream *xdr)
4745{
4746 return decode_op_hdr(xdr, OP_PUTROOTFH);
4747}
4748
4749static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4750{
4751 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 uint32_t count, eof, recvd, hdrlen;
4754 int status;
4755
4756 status = decode_op_hdr(xdr, OP_READ);
4757 if (status)
4758 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004759 p = xdr_inline_decode(xdr, 8);
4760 if (unlikely(!p))
4761 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004762 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004763 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004764 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 recvd = req->rq_rcv_buf.len - hdrlen;
4766 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004767 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 "count %u > recvd %u\n", count, recvd);
4769 count = recvd;
4770 eof = 0;
4771 }
4772 xdr_read_pages(xdr, count);
4773 res->eof = eof;
4774 res->count = count;
4775 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004776out_overflow:
4777 print_overflow_msg(__func__, xdr);
4778 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779}
4780
4781static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4782{
4783 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004785 size_t hdrlen;
4786 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004787 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004788 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789
4790 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004791 if (!status)
4792 status = decode_verifier(xdr, readdir->verifier.data);
4793 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004795 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004796 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004797 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798
Benny Halevydb942bb2009-08-14 17:19:56 +03004799 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 recvd = rcvbuf->len - hdrlen;
4801 if (pglen > recvd)
4802 pglen = recvd;
4803 xdr_read_pages(xdr, pglen);
4804
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004805
Trond Myklebustac396122010-11-15 20:26:22 -05004806 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807}
4808
4809static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4810{
4811 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4812 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004813 size_t hdrlen;
4814 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 int status;
4817
4818 status = decode_op_hdr(xdr, OP_READLINK);
4819 if (status)
4820 return status;
4821
4822 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004823 p = xdr_inline_decode(xdr, 4);
4824 if (unlikely(!p))
4825 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004826 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004828 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829 return -ENAMETOOLONG;
4830 }
4831 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4832 recvd = req->rq_rcv_buf.len - hdrlen;
4833 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004834 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 "count %u > recvd %u\n", len, recvd);
4836 return -EIO;
4837 }
4838 xdr_read_pages(xdr, len);
4839 /*
4840 * The XDR encode routine has set things up so that
4841 * the link text will be copied directly into the
4842 * buffer. We just have to do overflow-checking,
4843 * and and null-terminate the text (the VFS expects
4844 * null-termination).
4845 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004846 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004848out_overflow:
4849 print_overflow_msg(__func__, xdr);
4850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851}
4852
4853static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4854{
4855 int status;
4856
4857 status = decode_op_hdr(xdr, OP_REMOVE);
4858 if (status)
4859 goto out;
4860 status = decode_change_info(xdr, cinfo);
4861out:
4862 return status;
4863}
4864
4865static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4866 struct nfs4_change_info *new_cinfo)
4867{
4868 int status;
4869
4870 status = decode_op_hdr(xdr, OP_RENAME);
4871 if (status)
4872 goto out;
4873 if ((status = decode_change_info(xdr, old_cinfo)))
4874 goto out;
4875 status = decode_change_info(xdr, new_cinfo);
4876out:
4877 return status;
4878}
4879
4880static int decode_renew(struct xdr_stream *xdr)
4881{
4882 return decode_op_hdr(xdr, OP_RENEW);
4883}
4884
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004885static int
4886decode_restorefh(struct xdr_stream *xdr)
4887{
4888 return decode_op_hdr(xdr, OP_RESTOREFH);
4889}
4890
J. Bruce Fields029d1052005-06-22 17:16:22 +00004891static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004892 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004893{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004894 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004895 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004896 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004897 struct kvec *iov = req->rq_rcv_buf.head;
4898 int status;
4899
Andy Adamsonbf118a32011-12-07 11:55:27 -05004900 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004901 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4902 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004903 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004904 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4905 goto out;
4906 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4907 goto out;
4908
4909 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4910 return -EIO;
4911 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004912 size_t hdrlen;
4913 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004914
Andy Adamsonbf118a32011-12-07 11:55:27 -05004915 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4916 * are stored with the acl data to handle the problem of
4917 * variable length bitmaps.*/
4918 xdr->p = bm_p;
4919 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4920 res->acl_data_offset <<= 2;
4921
J. Bruce Fields029d1052005-06-22 17:16:22 +00004922 /* We ignore &savep and don't do consistency checks on
4923 * the attr length. Let userspace figure it out.... */
4924 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004925 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004926 recvd = req->rq_rcv_buf.len - hdrlen;
4927 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004928 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4929 /* getxattr interface called with a NULL buf */
4930 res->acl_len = attrlen;
4931 goto out;
4932 }
4933 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00004934 attrlen, recvd);
4935 return -EINVAL;
4936 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004937 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004938 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004939 } else
4940 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004941
4942out:
4943 return status;
4944}
4945
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946static int
4947decode_savefh(struct xdr_stream *xdr)
4948{
4949 return decode_op_hdr(xdr, OP_SAVEFH);
4950}
4951
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004952static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953{
Al Viro8687b632006-10-19 23:28:48 -07004954 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 uint32_t bmlen;
4956 int status;
4957
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 status = decode_op_hdr(xdr, OP_SETATTR);
4959 if (status)
4960 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004961 p = xdr_inline_decode(xdr, 4);
4962 if (unlikely(!p))
4963 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004964 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004965 p = xdr_inline_decode(xdr, bmlen << 2);
4966 if (likely(p))
4967 return 0;
4968out_overflow:
4969 print_overflow_msg(__func__, xdr);
4970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971}
4972
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004973static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974{
Al Viro8687b632006-10-19 23:28:48 -07004975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 uint32_t opnum;
4977 int32_t nfserr;
4978
Benny Halevyc0eae662009-08-14 17:20:14 +03004979 p = xdr_inline_decode(xdr, 8);
4980 if (unlikely(!p))
4981 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004982 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004984 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004985 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 return -EIO;
4987 }
Benny Halevycccddf42009-08-14 17:20:19 +03004988 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004990 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4991 if (unlikely(!p))
4992 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004993 p = xdr_decode_hyper(p, &res->clientid);
4994 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 } else if (nfserr == NFSERR_CLID_INUSE) {
4996 uint32_t len;
4997
4998 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004999 p = xdr_inline_decode(xdr, 4);
5000 if (unlikely(!p))
5001 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005002 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005003 p = xdr_inline_decode(xdr, len);
5004 if (unlikely(!p))
5005 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006
5007 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005008 p = xdr_inline_decode(xdr, 4);
5009 if (unlikely(!p))
5010 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005011 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005012 p = xdr_inline_decode(xdr, len);
5013 if (unlikely(!p))
5014 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 return -NFSERR_CLID_INUSE;
5016 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005017 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018
5019 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005020out_overflow:
5021 print_overflow_msg(__func__, xdr);
5022 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023}
5024
5025static int decode_setclientid_confirm(struct xdr_stream *xdr)
5026{
5027 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5028}
5029
5030static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5031{
Al Viro8687b632006-10-19 23:28:48 -07005032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 int status;
5034
5035 status = decode_op_hdr(xdr, OP_WRITE);
5036 if (status)
5037 return status;
5038
Benny Halevyc0eae662009-08-14 17:20:14 +03005039 p = xdr_inline_decode(xdr, 16);
5040 if (unlikely(!p))
5041 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005042 res->count = be32_to_cpup(p++);
5043 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005044 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005046out_overflow:
5047 print_overflow_msg(__func__, xdr);
5048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049}
5050
5051static int decode_delegreturn(struct xdr_stream *xdr)
5052{
5053 return decode_op_hdr(xdr, OP_DELEGRETURN);
5054}
5055
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005056static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5057{
5058 __be32 *p;
5059
5060 p = xdr_inline_decode(xdr, 4);
5061 if (unlikely(!p))
5062 goto out_overflow;
5063 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5064 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5065 goto out_err;
5066
5067 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5068 if (unlikely(!p))
5069 goto out_overflow;
5070 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5071
5072 p = xdr_inline_decode(xdr, 8);
5073 if (unlikely(!p))
5074 goto out_overflow;
5075 flavor->gss.qop4 = be32_to_cpup(p++);
5076 flavor->gss.service = be32_to_cpup(p);
5077
5078 return 0;
5079
5080out_overflow:
5081 print_overflow_msg(__func__, xdr);
5082 return -EIO;
5083out_err:
5084 return -EINVAL;
5085}
5086
5087static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5088{
5089 struct nfs4_secinfo_flavor *sec_flavor;
5090 int status;
5091 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005092 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005093
5094 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005095 if (status)
5096 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005097 p = xdr_inline_decode(xdr, 4);
5098 if (unlikely(!p))
5099 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005100
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005101 res->flavors->num_flavors = 0;
5102 num_flavors = be32_to_cpup(p);
5103
5104 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005105 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005106 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005107 break;
5108
5109 p = xdr_inline_decode(xdr, 4);
5110 if (unlikely(!p))
5111 goto out_overflow;
5112 sec_flavor->flavor = be32_to_cpup(p);
5113
5114 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005115 status = decode_secinfo_gss(xdr, sec_flavor);
5116 if (status)
5117 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005118 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005119 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005120 }
5121
Bryan Schumaker613e9012011-04-27 15:28:44 -04005122out:
5123 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005124out_overflow:
5125 print_overflow_msg(__func__, xdr);
5126 return -EIO;
5127}
5128
Benny Halevy99fe60d2009-04-01 09:22:29 -04005129#if defined(CONFIG_NFS_V4_1)
5130static int decode_exchange_id(struct xdr_stream *xdr,
5131 struct nfs41_exchange_id_res *res)
5132{
5133 __be32 *p;
5134 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005135 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005136 int status;
5137 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005138 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005139
5140 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5141 if (status)
5142 return status;
5143
Benny Halevyc0eae662009-08-14 17:20:14 +03005144 p = xdr_inline_decode(xdr, 8);
5145 if (unlikely(!p))
5146 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005147 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005148 p = xdr_inline_decode(xdr, 12);
5149 if (unlikely(!p))
5150 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005151 clp->cl_seqid = be32_to_cpup(p++);
5152 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005153
5154 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005155 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005156 if (dummy != SP4_NONE)
5157 return -EIO;
5158
5159 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005160 p = xdr_inline_decode(xdr, 8);
5161 if (unlikely(!p))
5162 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005163
5164 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005165 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5166 if (unlikely(status))
5167 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005168
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005169 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005170 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5171 if (unlikely(status))
5172 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005173
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005174 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5175 return -EIO;
5176
5177 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5178 res->server_scope->server_scope_sz = dummy;
5179
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005180 /* Implementation Id */
5181 p = xdr_inline_decode(xdr, 4);
5182 if (unlikely(!p))
5183 goto out_overflow;
5184 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005185
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005186 if (impl_id_count) {
5187 /* nii_domain */
5188 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5189 if (unlikely(status))
5190 return status;
5191 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5192 return -EIO;
5193 memcpy(res->impl_id->domain, dummy_str, dummy);
5194
5195 /* nii_name */
5196 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5197 if (unlikely(status))
5198 return status;
5199 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5200 return -EIO;
5201 memcpy(res->impl_id->name, dummy_str, dummy);
5202
5203 /* nii_date */
5204 p = xdr_inline_decode(xdr, 12);
5205 if (unlikely(!p))
5206 goto out_overflow;
5207 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5208 res->impl_id->date.nseconds = be32_to_cpup(p);
5209
5210 /* if there's more than one entry, ignore the rest */
5211 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005212 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005213out_overflow:
5214 print_overflow_msg(__func__, xdr);
5215 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005216}
Andy Adamsonfc931582009-04-01 09:22:31 -04005217
5218static int decode_chan_attrs(struct xdr_stream *xdr,
5219 struct nfs4_channel_attrs *attrs)
5220{
5221 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005222 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005223
Benny Halevyc0eae662009-08-14 17:20:14 +03005224 p = xdr_inline_decode(xdr, 28);
5225 if (unlikely(!p))
5226 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005227 val = be32_to_cpup(p++); /* headerpadsz */
5228 if (val)
5229 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005230 attrs->max_rqst_sz = be32_to_cpup(p++);
5231 attrs->max_resp_sz = be32_to_cpup(p++);
5232 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5233 attrs->max_ops = be32_to_cpup(p++);
5234 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005235 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005236 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005237 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5238 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005239 return -EINVAL;
5240 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005241 if (nr_attrs == 1) {
5242 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5243 if (unlikely(!p))
5244 goto out_overflow;
5245 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005246 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005247out_overflow:
5248 print_overflow_msg(__func__, xdr);
5249 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005250}
5251
Benny Halevye78291e2009-08-14 17:20:00 +03005252static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5253{
5254 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005255}
5256
5257static int decode_create_session(struct xdr_stream *xdr,
5258 struct nfs41_create_session_res *res)
5259{
5260 __be32 *p;
5261 int status;
5262 struct nfs_client *clp = res->client;
5263 struct nfs4_session *session = clp->cl_session;
5264
5265 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005266 if (!status)
5267 status = decode_sessionid(xdr, &session->sess_id);
5268 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005269 return status;
5270
Andy Adamsonfc931582009-04-01 09:22:31 -04005271 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005272 p = xdr_inline_decode(xdr, 8);
5273 if (unlikely(!p))
5274 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005275 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005276 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005277
5278 /* Channel attributes */
5279 status = decode_chan_attrs(xdr, &session->fc_attrs);
5280 if (!status)
5281 status = decode_chan_attrs(xdr, &session->bc_attrs);
5282 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005283out_overflow:
5284 print_overflow_msg(__func__, xdr);
5285 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005286}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005287
5288static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5289{
5290 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5291}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005292
5293static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5294{
5295 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5296}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005297#endif /* CONFIG_NFS_V4_1 */
5298
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005299static int decode_sequence(struct xdr_stream *xdr,
5300 struct nfs4_sequence_res *res,
5301 struct rpc_rqst *rqstp)
5302{
5303#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005304 struct nfs4_sessionid id;
5305 u32 dummy;
5306 int status;
5307 __be32 *p;
5308
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005309 if (!res->sr_session)
5310 return 0;
5311
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005312 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005313 if (!status)
5314 status = decode_sessionid(xdr, &id);
5315 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005316 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005317
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005318 /*
5319 * If the server returns different values for sessionID, slotID or
5320 * sequence number, the server is looney tunes.
5321 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005322 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005323
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005324 if (memcmp(id.data, res->sr_session->sess_id.data,
5325 NFS4_MAX_SESSIONID_LEN)) {
5326 dprintk("%s Invalid session id\n", __func__);
5327 goto out_err;
5328 }
Benny Halevye78291e2009-08-14 17:20:00 +03005329
Benny Halevyc0eae662009-08-14 17:20:14 +03005330 p = xdr_inline_decode(xdr, 20);
5331 if (unlikely(!p))
5332 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005333
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005334 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005335 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005336 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005337 dprintk("%s Invalid sequence number\n", __func__);
5338 goto out_err;
5339 }
5340 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005341 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005342 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005343 dprintk("%s Invalid slot id\n", __func__);
5344 goto out_err;
5345 }
5346 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005347 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005348 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005349 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005350 /* result flags */
5351 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005352 status = 0;
5353out_err:
5354 res->sr_status = status;
5355 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005356out_overflow:
5357 print_overflow_msg(__func__, xdr);
5358 status = -EIO;
5359 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005360#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005361 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005362#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005363}
5364
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005365#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005366/*
5367 * TODO: Need to handle case when EOF != true;
5368 */
5369static int decode_getdevicelist(struct xdr_stream *xdr,
5370 struct pnfs_devicelist *res)
5371{
5372 __be32 *p;
5373 int status, i;
5374 struct nfs_writeverf verftemp;
5375
5376 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5377 if (status)
5378 return status;
5379
5380 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5381 if (unlikely(!p))
5382 goto out_overflow;
5383
5384 /* TODO: Skip cookie for now */
5385 p += 2;
5386
5387 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005388 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005389
5390 res->num_devs = be32_to_cpup(p);
5391
5392 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5393
5394 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005395 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005396 __func__, res->num_devs);
5397 return -EIO;
5398 }
5399
5400 p = xdr_inline_decode(xdr,
5401 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5402 if (unlikely(!p))
5403 goto out_overflow;
5404 for (i = 0; i < res->num_devs; i++)
5405 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5406 NFS4_DEVICEID4_SIZE);
5407 res->eof = be32_to_cpup(p);
5408 return 0;
5409out_overflow:
5410 print_overflow_msg(__func__, xdr);
5411 return -EIO;
5412}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005413
5414static int decode_getdeviceinfo(struct xdr_stream *xdr,
5415 struct pnfs_device *pdev)
5416{
5417 __be32 *p;
5418 uint32_t len, type;
5419 int status;
5420
5421 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5422 if (status) {
5423 if (status == -ETOOSMALL) {
5424 p = xdr_inline_decode(xdr, 4);
5425 if (unlikely(!p))
5426 goto out_overflow;
5427 pdev->mincount = be32_to_cpup(p);
5428 dprintk("%s: Min count too small. mincnt = %u\n",
5429 __func__, pdev->mincount);
5430 }
5431 return status;
5432 }
5433
5434 p = xdr_inline_decode(xdr, 8);
5435 if (unlikely(!p))
5436 goto out_overflow;
5437 type = be32_to_cpup(p++);
5438 if (type != pdev->layout_type) {
5439 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5440 __func__, pdev->layout_type, type);
5441 return -EINVAL;
5442 }
5443 /*
5444 * Get the length of the opaque device_addr4. xdr_read_pages places
5445 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5446 * and places the remaining xdr data in xdr_buf->tail
5447 */
5448 pdev->mincount = be32_to_cpup(p);
5449 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5450
5451 /* Parse notification bitmap, verifying that it is zero. */
5452 p = xdr_inline_decode(xdr, 4);
5453 if (unlikely(!p))
5454 goto out_overflow;
5455 len = be32_to_cpup(p);
5456 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005457 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005458
5459 p = xdr_inline_decode(xdr, 4 * len);
5460 if (unlikely(!p))
5461 goto out_overflow;
5462 for (i = 0; i < len; i++, p++) {
5463 if (be32_to_cpup(p)) {
5464 dprintk("%s: notifications not supported\n",
5465 __func__);
5466 return -EIO;
5467 }
5468 }
5469 }
5470 return 0;
5471out_overflow:
5472 print_overflow_msg(__func__, xdr);
5473 return -EIO;
5474}
5475
5476static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5477 struct nfs4_layoutget_res *res)
5478{
5479 __be32 *p;
5480 int status;
5481 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005482 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5483 struct kvec *iov = rcvbuf->head;
5484 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005485
5486 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5487 if (status)
5488 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005489 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005490 if (unlikely(!p))
5491 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005492 res->return_on_close = be32_to_cpup(p);
5493 decode_stateid(xdr, &res->stateid);
5494 p = xdr_inline_decode(xdr, 4);
5495 if (unlikely(!p))
5496 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005497 layout_count = be32_to_cpup(p);
5498 if (!layout_count) {
5499 dprintk("%s: server responded with empty layout array\n",
5500 __func__);
5501 return -EINVAL;
5502 }
5503
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005504 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005505 if (unlikely(!p))
5506 goto out_overflow;
5507 p = xdr_decode_hyper(p, &res->range.offset);
5508 p = xdr_decode_hyper(p, &res->range.length);
5509 res->range.iomode = be32_to_cpup(p++);
5510 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005511 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005512
5513 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5514 __func__,
5515 (unsigned long)res->range.offset,
5516 (unsigned long)res->range.length,
5517 res->range.iomode,
5518 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005519 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005520
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005521 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5522 recvd = req->rq_rcv_buf.len - hdrlen;
5523 if (res->layoutp->len > recvd) {
5524 dprintk("NFS: server cheating in layoutget reply: "
5525 "layout len %u > recvd %u\n",
5526 res->layoutp->len, recvd);
5527 return -EINVAL;
5528 }
5529
5530 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005531
5532 if (layout_count > 1) {
5533 /* We only handle a length one array at the moment. Any
5534 * further entries are just ignored. Note that this means
5535 * the client may see a response that is less than the
5536 * minimum it requested.
5537 */
5538 dprintk("%s: server responded with %d layouts, dropping tail\n",
5539 __func__, layout_count);
5540 }
5541
5542 return 0;
5543out_overflow:
5544 print_overflow_msg(__func__, xdr);
5545 return -EIO;
5546}
Andy Adamson863a3c62011-03-23 13:27:54 +00005547
Benny Halevycbe82602011-05-22 19:52:37 +03005548static int decode_layoutreturn(struct xdr_stream *xdr,
5549 struct nfs4_layoutreturn_res *res)
5550{
5551 __be32 *p;
5552 int status;
5553
5554 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5555 if (status)
5556 return status;
5557 p = xdr_inline_decode(xdr, 4);
5558 if (unlikely(!p))
5559 goto out_overflow;
5560 res->lrs_present = be32_to_cpup(p);
5561 if (res->lrs_present)
5562 status = decode_stateid(xdr, &res->stateid);
5563 return status;
5564out_overflow:
5565 print_overflow_msg(__func__, xdr);
5566 return -EIO;
5567}
5568
Andy Adamson863a3c62011-03-23 13:27:54 +00005569static int decode_layoutcommit(struct xdr_stream *xdr,
5570 struct rpc_rqst *req,
5571 struct nfs4_layoutcommit_res *res)
5572{
5573 __be32 *p;
5574 __u32 sizechanged;
5575 int status;
5576
5577 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005578 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005579 if (status)
5580 return status;
5581
5582 p = xdr_inline_decode(xdr, 4);
5583 if (unlikely(!p))
5584 goto out_overflow;
5585 sizechanged = be32_to_cpup(p);
5586
5587 if (sizechanged) {
5588 /* throw away new size */
5589 p = xdr_inline_decode(xdr, 8);
5590 if (unlikely(!p))
5591 goto out_overflow;
5592 }
5593 return 0;
5594out_overflow:
5595 print_overflow_msg(__func__, xdr);
5596 return -EIO;
5597}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005598
5599static int decode_test_stateid(struct xdr_stream *xdr,
5600 struct nfs41_test_stateid_res *res)
5601{
5602 __be32 *p;
5603 int status;
5604 int num_res;
5605
5606 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5607 if (status)
5608 return status;
5609
5610 p = xdr_inline_decode(xdr, 4);
5611 if (unlikely(!p))
5612 goto out_overflow;
5613 num_res = be32_to_cpup(p++);
5614 if (num_res != 1)
5615 goto out;
5616
5617 p = xdr_inline_decode(xdr, 4);
5618 if (unlikely(!p))
5619 goto out_overflow;
5620 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005621
5622 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005623out_overflow:
5624 print_overflow_msg(__func__, xdr);
5625out:
5626 return -EIO;
5627}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005628
5629static int decode_free_stateid(struct xdr_stream *xdr,
5630 struct nfs41_free_stateid_res *res)
5631{
5632 __be32 *p;
5633 int status;
5634
5635 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5636 if (status)
5637 return status;
5638
5639 p = xdr_inline_decode(xdr, 4);
5640 if (unlikely(!p))
5641 goto out_overflow;
5642 res->status = be32_to_cpup(p++);
5643 return res->status;
5644out_overflow:
5645 print_overflow_msg(__func__, xdr);
5646 return -EIO;
5647}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005648#endif /* CONFIG_NFS_V4_1 */
5649
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650/*
Benny Halevy49c25592008-12-23 16:06:16 -05005651 * END OF "GENERIC" DECODE ROUTINES.
5652 */
5653
5654/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655 * Decode OPEN_DOWNGRADE response
5656 */
Chuck Leverbf269552010-12-14 14:59:29 +00005657static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5658 struct xdr_stream *xdr,
5659 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660{
Andy Adamson05d564f2008-12-23 16:06:15 -05005661 struct compound_hdr hdr;
5662 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663
Chuck Leverbf269552010-12-14 14:59:29 +00005664 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005665 if (status)
5666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005667 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005668 if (status)
5669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005670 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005671 if (status)
5672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005673 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005674 if (status != 0)
5675 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005676 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005678 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679}
5680
5681/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682 * Decode ACCESS response
5683 */
Chuck Leverbf269552010-12-14 14:59:29 +00005684static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5685 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687 struct compound_hdr hdr;
5688 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005689
Chuck Leverbf269552010-12-14 14:59:29 +00005690 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005691 if (status)
5692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005693 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005694 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005696 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005697 if (status != 0)
5698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005699 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005700 if (status != 0)
5701 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005702 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703out:
5704 return status;
5705}
5706
5707/*
5708 * Decode LOOKUP response
5709 */
Chuck Leverbf269552010-12-14 14:59:29 +00005710static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5711 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 struct compound_hdr hdr;
5714 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005715
Chuck Leverbf269552010-12-14 14:59:29 +00005716 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005717 if (status)
5718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005719 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005720 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005722 status = decode_putfh(xdr);
5723 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005725 status = decode_lookup(xdr);
5726 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005728 status = decode_getfh(xdr, res->fh);
5729 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005731 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732out:
5733 return status;
5734}
5735
5736/*
5737 * Decode LOOKUP_ROOT response
5738 */
Chuck Leverbf269552010-12-14 14:59:29 +00005739static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5740 struct xdr_stream *xdr,
5741 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743 struct compound_hdr hdr;
5744 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005745
Chuck Leverbf269552010-12-14 14:59:29 +00005746 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005747 if (status)
5748 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005749 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005750 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005752 status = decode_putrootfh(xdr);
5753 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005755 status = decode_getfh(xdr, res->fh);
5756 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005757 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758out:
5759 return status;
5760}
5761
5762/*
5763 * Decode REMOVE response
5764 */
Chuck Leverbf269552010-12-14 14:59:29 +00005765static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5766 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768 struct compound_hdr hdr;
5769 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005770
Chuck Leverbf269552010-12-14 14:59:29 +00005771 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005772 if (status)
5773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005774 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005775 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005777 status = decode_putfh(xdr);
5778 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005779 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005780 status = decode_remove(xdr, &res->cinfo);
5781 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005782 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005783 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784out:
5785 return status;
5786}
5787
5788/*
5789 * Decode RENAME response
5790 */
Chuck Leverbf269552010-12-14 14:59:29 +00005791static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5792 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 struct compound_hdr hdr;
5795 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005796
Chuck Leverbf269552010-12-14 14:59:29 +00005797 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005798 if (status)
5799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005800 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005801 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005803 status = decode_putfh(xdr);
5804 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005806 status = decode_savefh(xdr);
5807 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005809 status = decode_putfh(xdr);
5810 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005812 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5813 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005814 goto out;
5815 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005816 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_restorefh(xdr);
5819 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005820 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005821 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822out:
5823 return status;
5824}
5825
5826/*
5827 * Decode LINK response
5828 */
Chuck Leverbf269552010-12-14 14:59:29 +00005829static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5830 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832 struct compound_hdr hdr;
5833 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005834
Chuck Leverbf269552010-12-14 14:59:29 +00005835 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005836 if (status)
5837 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005838 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005839 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005841 status = decode_putfh(xdr);
5842 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005844 status = decode_savefh(xdr);
5845 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_putfh(xdr);
5848 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_link(xdr, &res->cinfo);
5851 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005852 goto out;
5853 /*
5854 * Note order: OP_LINK leaves the directory as the current
5855 * filehandle.
5856 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005857 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_restorefh(xdr);
5860 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005861 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005862 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863out:
5864 return status;
5865}
5866
5867/*
5868 * Decode CREATE response
5869 */
Chuck Leverbf269552010-12-14 14:59:29 +00005870static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5871 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 struct compound_hdr hdr;
5874 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005875
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005877 if (status)
5878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005880 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005882 status = decode_putfh(xdr);
5883 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_savefh(xdr);
5886 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005887 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005888 status = decode_create(xdr, &res->dir_cinfo);
5889 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005891 status = decode_getfh(xdr, res->fh);
5892 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005894 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_restorefh(xdr);
5897 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005898 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005899 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900out:
5901 return status;
5902}
5903
5904/*
5905 * Decode SYMLINK response
5906 */
Chuck Leverbf269552010-12-14 14:59:29 +00005907static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5908 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909{
Chuck Leverbf269552010-12-14 14:59:29 +00005910 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005911}
5912
5913/*
5914 * Decode GETATTR response
5915 */
Chuck Leverbf269552010-12-14 14:59:29 +00005916static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5917 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 struct compound_hdr hdr;
5920 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005921
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 if (status)
5924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005926 if (status)
5927 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929 if (status)
5930 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005931 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932out:
5933 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934}
5935
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005936/*
5937 * Encode an SETACL request
5938 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005939static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5940 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005941{
Andy Adamson05d564f2008-12-23 16:06:15 -05005942 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005943 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005944 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005945
Chuck Lever9f06c712010-12-14 14:59:18 +00005946 encode_compound_hdr(xdr, req, &hdr);
5947 encode_sequence(xdr, &args->seq_args, &hdr);
5948 encode_putfh(xdr, args->fh, &hdr);
5949 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005950 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005951}
Andy Adamson05d564f2008-12-23 16:06:15 -05005952
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005953/*
5954 * Decode SETACL response
5955 */
5956static int
Chuck Leverbf269552010-12-14 14:59:29 +00005957nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005958 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005959{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005960 struct compound_hdr hdr;
5961 int status;
5962
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005964 if (status)
5965 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005967 if (status)
5968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005970 if (status)
5971 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005973out:
5974 return status;
5975}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976
5977/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005978 * Decode GETACL response
5979 */
5980static int
Chuck Leverbf269552010-12-14 14:59:29 +00005981nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005982 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005983{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005984 struct compound_hdr hdr;
5985 int status;
5986
Trond Myklebust331818f2012-02-03 18:30:53 -05005987 if (res->acl_scratch != NULL) {
5988 void *p = page_address(res->acl_scratch);
5989 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5990 }
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005992 if (status)
5993 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005994 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005995 if (status)
5996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005998 if (status)
5999 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006000 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006001
6002out:
6003 return status;
6004}
6005
6006/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 * Decode CLOSE response
6008 */
Chuck Leverbf269552010-12-14 14:59:29 +00006009static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6010 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011{
Andy Adamson05d564f2008-12-23 16:06:15 -05006012 struct compound_hdr hdr;
6013 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006016 if (status)
6017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006019 if (status)
6020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006022 if (status)
6023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006025 if (status != 0)
6026 goto out;
6027 /*
6028 * Note: Server may do delete on close for this file
6029 * in which case the getattr call will fail with
6030 * an ESTALE error. Shouldn't be a problem,
6031 * though, since fattr->valid will remain unset.
6032 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006033 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006035 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006036}
6037
6038/*
6039 * Decode OPEN response
6040 */
Chuck Leverbf269552010-12-14 14:59:29 +00006041static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6042 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043{
Andy Adamson05d564f2008-12-23 16:06:15 -05006044 struct compound_hdr hdr;
6045 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006048 if (status)
6049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006051 if (status)
6052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006057 if (status)
6058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006060 if (status)
6061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006064 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006065 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006066 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006067 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006068 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006070 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071}
6072
6073/*
6074 * Decode OPEN_CONFIRM response
6075 */
Chuck Leverbf269552010-12-14 14:59:29 +00006076static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6077 struct xdr_stream *xdr,
6078 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079{
Andy Adamson05d564f2008-12-23 16:06:15 -05006080 struct compound_hdr hdr;
6081 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006084 if (status)
6085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006087 if (status)
6088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006091 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092}
6093
6094/*
6095 * Decode OPEN response
6096 */
Chuck Leverbf269552010-12-14 14:59:29 +00006097static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6098 struct xdr_stream *xdr,
6099 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100{
Andy Adamson05d564f2008-12-23 16:06:15 -05006101 struct compound_hdr hdr;
6102 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006105 if (status)
6106 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006108 if (status)
6109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006111 if (status)
6112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006114 if (status)
6115 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006116 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006118 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119}
6120
6121/*
6122 * Decode SETATTR response
6123 */
Chuck Leverbf269552010-12-14 14:59:29 +00006124static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6125 struct xdr_stream *xdr,
6126 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127{
Andy Adamson05d564f2008-12-23 16:06:15 -05006128 struct compound_hdr hdr;
6129 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006132 if (status)
6133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006135 if (status)
6136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006138 if (status)
6139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006141 if (status)
6142 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006143 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006145 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146}
6147
6148/*
6149 * Decode LOCK response
6150 */
Chuck Leverbf269552010-12-14 14:59:29 +00006151static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6152 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154 struct compound_hdr hdr;
6155 int status;
6156
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 if (status)
6159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006161 if (status)
6162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 if (status)
6165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167out:
6168 return status;
6169}
6170
6171/*
6172 * Decode LOCKT response
6173 */
Chuck Leverbf269552010-12-14 14:59:29 +00006174static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6175 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177 struct compound_hdr hdr;
6178 int status;
6179
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 if (status)
6182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006184 if (status)
6185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 if (status)
6188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190out:
6191 return status;
6192}
6193
6194/*
6195 * Decode LOCKU response
6196 */
Chuck Leverbf269552010-12-14 14:59:29 +00006197static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6198 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 struct compound_hdr hdr;
6201 int status;
6202
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 if (status)
6205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006207 if (status)
6208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 if (status)
6211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213out:
6214 return status;
6215}
6216
Chuck Leverbf269552010-12-14 14:59:29 +00006217static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6218 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006219{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006220 struct compound_hdr hdr;
6221 int status;
6222
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006224 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006226 return status;
6227}
6228
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229/*
6230 * Decode READLINK response
6231 */
Chuck Leverbf269552010-12-14 14:59:29 +00006232static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6233 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006234 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 struct compound_hdr hdr;
6237 int status;
6238
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 if (status)
6241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006242 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006243 if (status)
6244 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 if (status)
6247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006248 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249out:
6250 return status;
6251}
6252
6253/*
6254 * Decode READDIR response
6255 */
Chuck Leverbf269552010-12-14 14:59:29 +00006256static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6257 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259 struct compound_hdr hdr;
6260 int status;
6261
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 if (status)
6264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006266 if (status)
6267 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 if (status)
6270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272out:
6273 return status;
6274}
6275
6276/*
6277 * Decode Read response
6278 */
Chuck Leverbf269552010-12-14 14:59:29 +00006279static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6280 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 struct compound_hdr hdr;
6283 int status;
6284
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 if (status)
6287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006289 if (status)
6290 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 if (status)
6293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 if (!status)
6296 status = res->count;
6297out:
6298 return status;
6299}
6300
6301/*
6302 * Decode WRITE response
6303 */
Chuck Leverbf269552010-12-14 14:59:29 +00006304static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6305 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307 struct compound_hdr hdr;
6308 int status;
6309
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006320 if (status)
6321 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006322 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006323 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 if (!status)
6325 status = res->count;
6326out:
6327 return status;
6328}
6329
6330/*
6331 * Decode COMMIT response
6332 */
Chuck Leverbf269552010-12-14 14:59:29 +00006333static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6334 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336 struct compound_hdr hdr;
6337 int status;
6338
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 if (status)
6341 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006343 if (status)
6344 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 if (status)
6347 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006349 if (status)
6350 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006351 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006352 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353out:
6354 return status;
6355}
6356
6357/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006358 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 */
Chuck Leverbf269552010-12-14 14:59:29 +00006360static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006361 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 struct compound_hdr hdr;
6364 int status;
6365
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006369 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 return status;
6374}
6375
6376/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006377 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 */
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006380 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 struct compound_hdr hdr;
6383 int status;
6384
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006388 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 return status;
6393}
6394
6395/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006396 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397 */
Chuck Leverbf269552010-12-14 14:59:29 +00006398static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006399 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401 struct compound_hdr hdr;
6402 int status;
6403
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006407 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 return status;
6412}
6413
6414/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006415 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 */
Chuck Leverbf269552010-12-14 14:59:29 +00006417static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6418 struct xdr_stream *xdr,
6419 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 struct compound_hdr hdr;
6422 int status;
6423
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006425 if (status)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006428 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_putfh(xdr);
6431 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434out:
6435 return status;
6436}
6437
6438/*
6439 * Decode RENEW response
6440 */
Chuck Leverbf269552010-12-14 14:59:29 +00006441static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6442 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 struct compound_hdr hdr;
6445 int status;
6446
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 return status;
6451}
6452
6453/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006454 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 */
Chuck Leverbf269552010-12-14 14:59:29 +00006456static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6457 struct xdr_stream *xdr,
6458 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 struct compound_hdr hdr;
6461 int status;
6462
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 return status;
6467}
6468
6469/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006470 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 */
Chuck Leverbf269552010-12-14 14:59:29 +00006472static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6473 struct xdr_stream *xdr,
6474 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 struct compound_hdr hdr;
6477 int status;
6478
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006481 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 return status;
6487}
6488
6489/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006490 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 */
Chuck Leverbf269552010-12-14 14:59:29 +00006492static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6493 struct xdr_stream *xdr,
6494 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496 struct compound_hdr hdr;
6497 int status;
6498
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006503 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006506 if (status != 0)
6507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006509 if (status != 0)
6510 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006511 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006512out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 return status;
6514}
6515
Trond Myklebust683b57b2006-06-09 09:34:22 -04006516/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006517 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006518 */
Chuck Leverbf269552010-12-14 14:59:29 +00006519static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6520 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006521 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006522{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006523 struct compound_hdr hdr;
6524 int status;
6525
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006527 if (status)
6528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006530 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_putfh(xdr);
6533 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_lookup(xdr);
6536 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006539 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6540 NULL, res->fs_locations,
6541 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006542out:
6543 return status;
6544}
6545
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006546/*
6547 * Decode SECINFO response
6548 */
6549static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6550 struct xdr_stream *xdr,
6551 struct nfs4_secinfo_res *res)
6552{
6553 struct compound_hdr hdr;
6554 int status;
6555
6556 status = decode_compound_hdr(xdr, &hdr);
6557 if (status)
6558 goto out;
6559 status = decode_sequence(xdr, &res->seq_res, rqstp);
6560 if (status)
6561 goto out;
6562 status = decode_putfh(xdr);
6563 if (status)
6564 goto out;
6565 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006566out:
6567 return status;
6568}
6569
Benny Halevy99fe60d2009-04-01 09:22:29 -04006570#if defined(CONFIG_NFS_V4_1)
6571/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006572 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006573 */
Chuck Leverbf269552010-12-14 14:59:29 +00006574static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6575 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006576 void *res)
6577{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006578 struct compound_hdr hdr;
6579 int status;
6580
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006582 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006584 return status;
6585}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006586
6587/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006588 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006589 */
Chuck Leverbf269552010-12-14 14:59:29 +00006590static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6591 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006592 struct nfs41_create_session_res *res)
6593{
Andy Adamsonfc931582009-04-01 09:22:31 -04006594 struct compound_hdr hdr;
6595 int status;
6596
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006598 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006600 return status;
6601}
6602
6603/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006604 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006605 */
Chuck Leverbf269552010-12-14 14:59:29 +00006606static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6607 struct xdr_stream *xdr,
6608 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006609{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006610 struct compound_hdr hdr;
6611 int status;
6612
Chuck Leverbf269552010-12-14 14:59:29 +00006613 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006614 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006616 return status;
6617}
6618
6619/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006620 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006621 */
Chuck Leverbf269552010-12-14 14:59:29 +00006622static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6623 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006624 struct nfs4_sequence_res *res)
6625{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006626 struct compound_hdr hdr;
6627 int status;
6628
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006630 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006632 return status;
6633}
6634
6635/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006636 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006637 */
Chuck Leverbf269552010-12-14 14:59:29 +00006638static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6639 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006640 struct nfs4_get_lease_time_res *res)
6641{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006642 struct compound_hdr hdr;
6643 int status;
6644
Chuck Leverbf269552010-12-14 14:59:29 +00006645 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006646 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006648 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006650 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006652 return status;
6653}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006654
6655/*
6656 * Decode RECLAIM_COMPLETE response
6657 */
Chuck Leverbf269552010-12-14 14:59:29 +00006658static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6659 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006660 struct nfs41_reclaim_complete_res *res)
6661{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006662 struct compound_hdr hdr;
6663 int status;
6664
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006666 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006670 return status;
6671}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006672
6673/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006674 * Decode GETDEVICELIST response
6675 */
6676static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6677 struct xdr_stream *xdr,
6678 struct nfs4_getdevicelist_res *res)
6679{
6680 struct compound_hdr hdr;
6681 int status;
6682
6683 dprintk("encoding getdevicelist!\n");
6684
6685 status = decode_compound_hdr(xdr, &hdr);
6686 if (status != 0)
6687 goto out;
6688 status = decode_sequence(xdr, &res->seq_res, rqstp);
6689 if (status != 0)
6690 goto out;
6691 status = decode_putfh(xdr);
6692 if (status != 0)
6693 goto out;
6694 status = decode_getdevicelist(xdr, res->devlist);
6695out:
6696 return status;
6697}
6698
6699/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006700 * Decode GETDEVINFO response
6701 */
Chuck Leverbf269552010-12-14 14:59:29 +00006702static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6703 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006704 struct nfs4_getdeviceinfo_res *res)
6705{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006706 struct compound_hdr hdr;
6707 int status;
6708
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006710 if (status != 0)
6711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006713 if (status != 0)
6714 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006716out:
6717 return status;
6718}
6719
6720/*
6721 * Decode LAYOUTGET response
6722 */
Chuck Leverbf269552010-12-14 14:59:29 +00006723static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6724 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006725 struct nfs4_layoutget_res *res)
6726{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006727 struct compound_hdr hdr;
6728 int status;
6729
Chuck Leverbf269552010-12-14 14:59:29 +00006730 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006731 if (status)
6732 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006733 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006734 if (status)
6735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006736 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006737 if (status)
6738 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006740out:
6741 return status;
6742}
Andy Adamson863a3c62011-03-23 13:27:54 +00006743
6744/*
Benny Halevycbe82602011-05-22 19:52:37 +03006745 * Decode LAYOUTRETURN response
6746 */
6747static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6748 struct xdr_stream *xdr,
6749 struct nfs4_layoutreturn_res *res)
6750{
6751 struct compound_hdr hdr;
6752 int status;
6753
6754 status = decode_compound_hdr(xdr, &hdr);
6755 if (status)
6756 goto out;
6757 status = decode_sequence(xdr, &res->seq_res, rqstp);
6758 if (status)
6759 goto out;
6760 status = decode_putfh(xdr);
6761 if (status)
6762 goto out;
6763 status = decode_layoutreturn(xdr, res);
6764out:
6765 return status;
6766}
6767
6768/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006769 * Decode LAYOUTCOMMIT response
6770 */
6771static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6772 struct xdr_stream *xdr,
6773 struct nfs4_layoutcommit_res *res)
6774{
6775 struct compound_hdr hdr;
6776 int status;
6777
6778 status = decode_compound_hdr(xdr, &hdr);
6779 if (status)
6780 goto out;
6781 status = decode_sequence(xdr, &res->seq_res, rqstp);
6782 if (status)
6783 goto out;
6784 status = decode_putfh(xdr);
6785 if (status)
6786 goto out;
6787 status = decode_layoutcommit(xdr, rqstp, res);
6788 if (status)
6789 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006790 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006791out:
6792 return status;
6793}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006794
6795/*
6796 * Decode SECINFO_NO_NAME response
6797 */
6798static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6799 struct xdr_stream *xdr,
6800 struct nfs4_secinfo_res *res)
6801{
6802 struct compound_hdr hdr;
6803 int status;
6804
6805 status = decode_compound_hdr(xdr, &hdr);
6806 if (status)
6807 goto out;
6808 status = decode_sequence(xdr, &res->seq_res, rqstp);
6809 if (status)
6810 goto out;
6811 status = decode_putrootfh(xdr);
6812 if (status)
6813 goto out;
6814 status = decode_secinfo(xdr, res);
6815out:
6816 return status;
6817}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006818
6819/*
6820 * Decode TEST_STATEID response
6821 */
6822static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6823 struct xdr_stream *xdr,
6824 struct nfs41_test_stateid_res *res)
6825{
6826 struct compound_hdr hdr;
6827 int status;
6828
6829 status = decode_compound_hdr(xdr, &hdr);
6830 if (status)
6831 goto out;
6832 status = decode_sequence(xdr, &res->seq_res, rqstp);
6833 if (status)
6834 goto out;
6835 status = decode_test_stateid(xdr, res);
6836out:
6837 return status;
6838}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006839
6840/*
6841 * Decode FREE_STATEID response
6842 */
6843static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6844 struct xdr_stream *xdr,
6845 struct nfs41_free_stateid_res *res)
6846{
6847 struct compound_hdr hdr;
6848 int status;
6849
6850 status = decode_compound_hdr(xdr, &hdr);
6851 if (status)
6852 goto out;
6853 status = decode_sequence(xdr, &res->seq_res, rqstp);
6854 if (status)
6855 goto out;
6856 status = decode_free_stateid(xdr, res);
6857out:
6858 return status;
6859}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006860#endif /* CONFIG_NFS_V4_1 */
6861
Chuck Lever573c4e12010-12-14 14:58:11 +00006862/**
6863 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6864 * the local page cache.
6865 * @xdr: XDR stream where entry resides
6866 * @entry: buffer to fill in with entry data
6867 * @plus: boolean indicating whether this should be a readdirplus entry
6868 *
6869 * Returns zero if successful, otherwise a negative errno value is
6870 * returned.
6871 *
6872 * This function is not invoked during READDIR reply decoding, but
6873 * rather whenever an application invokes the getdents(2) system call
6874 * on a directory already in our cache.
6875 */
6876int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6877 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006878{
Fred Isamandae100c2011-07-30 20:52:37 -04006879 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006881 __be32 *p = xdr_inline_decode(xdr, 4);
6882 if (unlikely(!p))
6883 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006884 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006885 p = xdr_inline_decode(xdr, 4);
6886 if (unlikely(!p))
6887 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006888 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006889 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006891 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 }
6893
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006894 p = xdr_inline_decode(xdr, 12);
6895 if (unlikely(!p))
6896 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 entry->prev_cookie = entry->cookie;
6898 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006899 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006900
Trond Myklebust9af8c222010-10-24 11:52:55 -04006901 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006902 if (unlikely(!p))
6903 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006905
6906 /*
6907 * In case the server doesn't return an inode number,
6908 * we fake one here. (We don't use inode number 0,
6909 * since glibc seems to choke on it...)
6910 */
6911 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006912 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913
Trond Myklebust9af8c222010-10-24 11:52:55 -04006914 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006915 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006916
6917 if (decode_attr_length(xdr, &len, &p) < 0)
6918 goto out_overflow;
6919
Chuck Lever573c4e12010-12-14 14:58:11 +00006920 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006921 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006922 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006923 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6924 entry->ino = entry->fattr->mounted_on_fileid;
6925 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006926 entry->ino = entry->fattr->fileid;
6927
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006928 entry->d_type = DT_UNKNOWN;
6929 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6930 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6931
Chuck Lever573c4e12010-12-14 14:58:11 +00006932 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006933
6934out_overflow:
6935 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006936 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937}
6938
6939/*
6940 * We need to translate between nfs status return values and
6941 * the local errno values which may not be the same.
6942 */
6943static struct {
6944 int stat;
6945 int errno;
6946} nfs_errtbl[] = {
6947 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006948 { NFS4ERR_PERM, -EPERM },
6949 { NFS4ERR_NOENT, -ENOENT },
6950 { NFS4ERR_IO, -errno_NFSERR_IO},
6951 { NFS4ERR_NXIO, -ENXIO },
6952 { NFS4ERR_ACCESS, -EACCES },
6953 { NFS4ERR_EXIST, -EEXIST },
6954 { NFS4ERR_XDEV, -EXDEV },
6955 { NFS4ERR_NOTDIR, -ENOTDIR },
6956 { NFS4ERR_ISDIR, -EISDIR },
6957 { NFS4ERR_INVAL, -EINVAL },
6958 { NFS4ERR_FBIG, -EFBIG },
6959 { NFS4ERR_NOSPC, -ENOSPC },
6960 { NFS4ERR_ROFS, -EROFS },
6961 { NFS4ERR_MLINK, -EMLINK },
6962 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6963 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6964 { NFS4ERR_DQUOT, -EDQUOT },
6965 { NFS4ERR_STALE, -ESTALE },
6966 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006967 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6968 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6969 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006970 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006971 { NFS4ERR_BADTYPE, -EBADTYPE },
6972 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006973 { NFS4ERR_SYMLINK, -ELOOP },
6974 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6975 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006976 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006977};
6978
6979/*
6980 * Convert an NFS error code to a local one.
6981 * This one is used jointly by NFSv2 and NFSv3.
6982 */
6983static int
David Howells0a8ea432006-08-22 20:06:08 -04006984nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006985{
6986 int i;
6987 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6988 if (nfs_errtbl[i].stat == stat)
6989 return nfs_errtbl[i].errno;
6990 }
6991 if (stat <= 10000 || stat > 10100) {
6992 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006993 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006994 }
6995 /* If we cannot translate the error, the recovery routines should
6996 * handle it.
6997 * Note: remaining NFSv4 error codes have values > 10000, so should
6998 * not conflict with native Linux error codes.
6999 */
Benny Halevy856dff32008-03-31 17:39:06 +03007000 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007001}
7002
Linus Torvalds1da177e2005-04-16 15:20:36 -07007003#define PROC(proc, argtype, restype) \
7004[NFSPROC4_CLNT_##proc] = { \
7005 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007006 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007007 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007008 .p_arglen = NFS4_##argtype##_sz, \
7009 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007010 .p_statidx = NFSPROC4_CLNT_##proc, \
7011 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007012}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013
7014struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007015 PROC(READ, enc_read, dec_read),
7016 PROC(WRITE, enc_write, dec_write),
7017 PROC(COMMIT, enc_commit, dec_commit),
7018 PROC(OPEN, enc_open, dec_open),
7019 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7020 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7021 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7022 PROC(CLOSE, enc_close, dec_close),
7023 PROC(SETATTR, enc_setattr, dec_setattr),
7024 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7025 PROC(RENEW, enc_renew, dec_renew),
7026 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7027 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7028 PROC(LOCK, enc_lock, dec_lock),
7029 PROC(LOCKT, enc_lockt, dec_lockt),
7030 PROC(LOCKU, enc_locku, dec_locku),
7031 PROC(ACCESS, enc_access, dec_access),
7032 PROC(GETATTR, enc_getattr, dec_getattr),
7033 PROC(LOOKUP, enc_lookup, dec_lookup),
7034 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7035 PROC(REMOVE, enc_remove, dec_remove),
7036 PROC(RENAME, enc_rename, dec_rename),
7037 PROC(LINK, enc_link, dec_link),
7038 PROC(SYMLINK, enc_symlink, dec_symlink),
7039 PROC(CREATE, enc_create, dec_create),
7040 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7041 PROC(STATFS, enc_statfs, dec_statfs),
7042 PROC(READLINK, enc_readlink, dec_readlink),
7043 PROC(READDIR, enc_readdir, dec_readdir),
7044 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7045 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7046 PROC(GETACL, enc_getacl, dec_getacl),
7047 PROC(SETACL, enc_setacl, dec_setacl),
7048 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7049 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007050 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007051#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007052 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7053 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7054 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7055 PROC(SEQUENCE, enc_sequence, dec_sequence),
7056 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7057 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7058 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7059 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007060 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007061 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007062 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007063 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007064 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007065 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007066#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007067};
7068
Trond Myklebusta613fa12012-01-20 13:53:56 -05007069const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007070 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007071 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007072 .procs = nfs4_procedures
7073};
7074
7075/*
7076 * Local variables:
7077 * c-basic-offset: 8
7078 * End:
7079 */