blob: d6e8306d02a76fba85c2a07782d10d357f8855df [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
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400904static void encode_compound_hdr(struct xdr_stream *xdr,
905 struct rpc_rqst *req,
906 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Al Viro8687b632006-10-19 23:28:48 -0700908 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400909 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400910
911 /* initialize running count of expected bytes in reply.
912 * NOTE: the replied tag SHOULD be the same is the one sent,
913 * but this is not required as a MUST for the server to do so. */
914 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500917 encode_string(xdr, hdr->taglen, hdr->tag);
918 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500920 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300921 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500922}
923
924static void encode_nops(struct compound_hdr *hdr)
925{
Andy Adamsonfc931582009-04-01 09:22:31 -0400926 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500927 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928}
929
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500930static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
931{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500932 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500933}
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
936{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500937 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
939
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500940static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
942 char owner_name[IDMAP_NAMESZ];
943 char owner_group[IDMAP_NAMESZ];
944 int owner_namelen = 0;
945 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700946 __be32 *p;
947 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 int len;
949 uint32_t bmval0 = 0;
950 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /*
953 * We reserve enough space to write the entire attribute buffer at once.
954 * In the worst-case, this would be
955 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
956 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000957 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 */
959 len = 16;
960
961 /* Sigh */
962 if (iap->ia_valid & ATTR_SIZE)
963 len += 8;
964 if (iap->ia_valid & ATTR_MODE)
965 len += 4;
966 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800967 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400969 dprintk("nfs: couldn't resolve uid %d to string\n",
970 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 /* XXX */
972 strcpy(owner_name, "nobody");
973 owner_namelen = sizeof("nobody") - 1;
974 /* goto out; */
975 }
976 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
977 }
978 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800979 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400981 dprintk("nfs: couldn't resolve gid %d to string\n",
982 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 strcpy(owner_group, "nobody");
984 owner_grouplen = sizeof("nobody") - 1;
985 /* goto out; */
986 }
987 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
988 }
989 if (iap->ia_valid & ATTR_ATIME_SET)
990 len += 16;
991 else if (iap->ia_valid & ATTR_ATIME)
992 len += 4;
993 if (iap->ia_valid & ATTR_MTIME_SET)
994 len += 16;
995 else if (iap->ia_valid & ATTR_MTIME)
996 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300997 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 /*
1000 * We write the bitmap length now, but leave the bitmap and the attribute
1001 * buffer length to be backfilled at the end of this routine.
1002 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001003 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 q = p;
1005 p += 3;
1006
1007 if (iap->ia_valid & ATTR_SIZE) {
1008 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001009 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
1011 if (iap->ia_valid & ATTR_MODE) {
1012 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001013 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015 if (iap->ia_valid & ATTR_UID) {
1016 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001017 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019 if (iap->ia_valid & ATTR_GID) {
1020 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001021 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 if (iap->ia_valid & ATTR_ATIME_SET) {
1024 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1026 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001027 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1028 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 else if (iap->ia_valid & ATTR_ATIME) {
1031 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001032 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 if (iap->ia_valid & ATTR_MTIME_SET) {
1035 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001036 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1037 *p++ = cpu_to_be32(0);
1038 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1039 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
1041 else if (iap->ia_valid & ATTR_MTIME) {
1042 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001043 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 /*
1047 * Now we backfill the bitmap and the attribute buffer length.
1048 */
1049 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001050 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 len, ((char *)p - (char *)q) + 4);
1052 BUG();
1053 }
1054 len = (char *)p - (char *)q - 12;
1055 *q++ = htonl(bmval0);
1056 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001057 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001062static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Benny Halevy13c65ce2009-08-14 17:19:25 +03001066 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001068 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001073static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Al Viro8687b632006-10-19 23:28:48 -07001075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001077 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(OP_CLOSE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001079 *p = cpu_to_be32(arg->seqid->sequence->counter);
1080 encode_nfs4_stateid(xdr, arg->stateid);
Andy Adamsond0179312008-12-23 16:06:17 -05001081 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001082 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Al Viro8687b632006-10-19 23:28:48 -07001087 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001088
Benny Halevy13c65ce2009-08-14 17:19:25 +03001089 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001090 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001091 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001092 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001093 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001094 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Al Viro8687b632006-10-19 23:28:48 -07001099 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001100
Benny Halevy13c65ce2009-08-14 17:19:25 +03001101 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001102 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001103 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 switch (create->ftype) {
1106 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001107 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001108 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001109 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 break;
1111
1112 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001113 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001114 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001115 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
1117
1118 default:
1119 break;
1120 }
1121
Benny Halevy811652b2009-08-14 17:19:34 +03001122 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001123 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001124 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001126 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001129static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Andy Adamson05d564f2008-12-23 16:06:15 -05001131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Benny Halevy13c65ce2009-08-14 17:19:25 +03001133 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001134 *p++ = cpu_to_be32(OP_GETATTR);
1135 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001136 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001137 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001138 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static 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 -07001142{
Andy Adamson05d564f2008-12-23 16:06:15 -05001143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Benny Halevy13c65ce2009-08-14 17:19:25 +03001145 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001146 *p++ = cpu_to_be32(OP_GETATTR);
1147 *p++ = cpu_to_be32(2);
1148 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001149 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001150 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001151 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Fred Isamandae100c2011-07-30 20:52:37 -04001154static void
1155encode_getattr_three(struct xdr_stream *xdr,
1156 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1157 struct compound_hdr *hdr)
1158{
1159 __be32 *p;
1160
1161 p = reserve_space(xdr, 4);
1162 *p = cpu_to_be32(OP_GETATTR);
1163 if (bm2) {
1164 p = reserve_space(xdr, 16);
1165 *p++ = cpu_to_be32(3);
1166 *p++ = cpu_to_be32(bm0);
1167 *p++ = cpu_to_be32(bm1);
1168 *p = cpu_to_be32(bm2);
1169 } else if (bm1) {
1170 p = reserve_space(xdr, 12);
1171 *p++ = cpu_to_be32(2);
1172 *p++ = cpu_to_be32(bm0);
1173 *p = cpu_to_be32(bm1);
1174 } else {
1175 p = reserve_space(xdr, 8);
1176 *p++ = cpu_to_be32(1);
1177 *p = cpu_to_be32(bm0);
1178 }
1179 hdr->nops++;
1180 hdr->replen += decode_getattr_maxsz;
1181}
1182
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001183static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1186 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Fred Isamandae100c2011-07-30 20:52:37 -04001191 encode_getattr_three(xdr,
1192 bitmask[0] & nfs4_fsinfo_bitmap[0],
1193 bitmask[1] & nfs4_fsinfo_bitmap[1],
1194 bitmask[2] & nfs4_fsinfo_bitmap[2],
1195 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001198static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001199{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001200 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1201 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001202}
1203
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001204static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
Al Viro8687b632006-10-19 23:28:48 -07001206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Benny Halevy13c65ce2009-08-14 17:19:25 +03001208 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001209 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001210 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001211 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001214static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
Al Viro8687b632006-10-19 23:28:48 -07001216 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001218 p = reserve_space(xdr, 4);
1219 *p = cpu_to_be32(OP_LINK);
1220 encode_string(xdr, name->len, name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001221 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001222 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001225static inline int nfs4_lock_type(struct file_lock *fl, int block)
1226{
1227 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1228 return block ? NFS4_READW_LT : NFS4_READ_LT;
1229 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1230}
1231
1232static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1233{
1234 if (fl->fl_end == OFFSET_MAX)
1235 return ~(uint64_t)0;
1236 return fl->fl_end - fl->fl_start + 1;
1237}
1238
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001239static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1240{
1241 __be32 *p;
1242
Trond Myklebustd035c362010-12-21 10:45:27 -05001243 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001245 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001246 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001247 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001248 xdr_encode_hyper(p, lowner->id);
1249}
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251/*
1252 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1253 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1254 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001255static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Al Viro8687b632006-10-19 23:28:48 -07001257 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Benny Halevy13c65ce2009-08-14 17:19:25 +03001259 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001260 *p++ = cpu_to_be32(OP_LOCK);
1261 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1262 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001263 p = xdr_encode_hyper(p, args->fl->fl_start);
1264 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001266 if (args->new_lock_owner){
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001267 p = reserve_space(xdr, 4);
1268 *p = cpu_to_be32(args->open_seqid->sequence->counter);
1269 encode_nfs4_stateid(xdr, args->open_stateid);
1270 p = reserve_space(xdr, 4);
1271 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001272 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
1274 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001275 encode_nfs4_stateid(xdr, args->lock_stateid);
1276 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001277 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 }
Andy Adamsond0179312008-12-23 16:06:17 -05001279 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001280 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Al Viro8687b632006-10-19 23:28:48 -07001285 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001287 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001288 *p++ = cpu_to_be32(OP_LOCKT);
1289 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001290 p = xdr_encode_hyper(p, args->fl->fl_start);
1291 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001292 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001293 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001294 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295}
1296
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001297static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Al Viro8687b632006-10-19 23:28:48 -07001299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001301 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001302 *p++ = cpu_to_be32(OP_LOCKU);
1303 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001304 *p = cpu_to_be32(args->seqid->sequence->counter);
1305 encode_nfs4_stateid(xdr, args->stateid);
1306 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001307 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001308 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001309 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001310 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001313static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1314{
1315 __be32 *p;
1316
1317 p = reserve_space(xdr, 4);
1318 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1319 encode_lockowner(xdr, lowner);
1320 hdr->nops++;
1321 hdr->replen += decode_release_lockowner_maxsz;
1322}
1323
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001328 p = reserve_space(xdr, 4);
1329 *p = cpu_to_be32(OP_LOOKUP);
1330 encode_string(xdr, name->len, name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001331 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001332 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333}
1334
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001335static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
Al Viro8687b632006-10-19 23:28:48 -07001337 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Benny Halevy13c65ce2009-08-14 17:19:25 +03001339 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001340 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001341 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001342 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001343 break;
1344 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001345 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001346 break;
1347 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001348 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001349 break;
1350 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001351 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 }
Benny Halevy34558512009-08-14 17:19:30 +03001353 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354}
1355
1356static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1357{
Al Viro8687b632006-10-19 23:28:48 -07001358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 /*
1360 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1361 * owner 4 = 32
1362 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001363 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001364 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001365 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001366 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001367 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001368 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001369 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001370 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001371 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001372 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
1375static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1376{
Al Viro8687b632006-10-19 23:28:48 -07001377 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001378 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Benny Halevy13c65ce2009-08-14 17:19:25 +03001380 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001382 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001383 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 encode_attrs(xdr, arg->u.attrs, arg->server);
1385 break;
1386 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001387 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001388 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001389 if (nfs4_has_persistent_session(clp)) {
1390 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1391 encode_attrs(xdr, arg->u.attrs, arg->server);
1392 } else {
1393 struct iattr dummy;
1394
1395 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1396 encode_nfs4_verifier(xdr, &arg->u.verifier);
1397 dummy.ia_valid = 0;
1398 encode_attrs(xdr, &dummy, arg->server);
1399 }
1400 } else {
1401 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1402 encode_nfs4_verifier(xdr, &arg->u.verifier);
1403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405}
1406
1407static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001413 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001414 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001415 break;
1416 default:
1417 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421}
1422
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001423static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Al Viro8687b632006-10-19 23:28:48 -07001425 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Benny Halevy13c65ce2009-08-14 17:19:25 +03001427 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001430 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001431 break;
1432 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 break;
1435 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001437 break;
1438 default:
1439 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441}
1442
1443static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 encode_string(xdr, name->len, name->name);
1450}
1451
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001452static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_delegation_type(xdr, type);
1459}
1460
1461static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001465 p = reserve_space(xdr, 4);
1466 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1467 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 encode_string(xdr, name->len, name->name);
1469}
1470
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001471static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
1473 encode_openhdr(xdr, arg);
1474 encode_opentype(xdr, arg);
1475 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001476 case NFS4_OPEN_CLAIM_NULL:
1477 encode_claim_null(xdr, arg->name);
1478 break;
1479 case NFS4_OPEN_CLAIM_PREVIOUS:
1480 encode_claim_previous(xdr, arg->u.delegation_type);
1481 break;
1482 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1483 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1484 break;
1485 default:
1486 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 }
Andy Adamsond0179312008-12-23 16:06:17 -05001488 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001489 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static 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 -07001493{
Al Viro8687b632006-10-19 23:28:48 -07001494 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001496 p = reserve_space(xdr, 4);
1497 *p = cpu_to_be32(OP_OPEN_CONFIRM);
1498 encode_nfs4_stateid(xdr, arg->stateid);
1499 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001500 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001501 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001502 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506{
Al Viro8687b632006-10-19 23:28:48 -07001507 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001509 p = reserve_space(xdr, 4);
1510 *p = cpu_to_be32(OP_OPEN_DOWNGRADE);
1511 encode_nfs4_stateid(xdr, arg->stateid);
1512 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001513 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001514 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001515 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001516 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001519static void
Andy Adamsond0179312008-12-23 16:06:17 -05001520encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Al Viro8687b632006-10-19 23:28:48 -07001522 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001524 p = reserve_space(xdr, 4);
1525 *p = cpu_to_be32(OP_PUTFH);
1526 encode_string(xdr, fh->size, fh->data);
Andy Adamsond0179312008-12-23 16:06:17 -05001527 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001528 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529}
1530
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001531static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Andy Adamson05d564f2008-12-23 16:06:15 -05001533 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001534
Benny Halevy13c65ce2009-08-14 17:19:25 +03001535 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001536 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001537 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001538 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539}
1540
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001541static 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 -07001542{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 if (ctx->state != NULL) {
Trond Myklebust1e3987c2012-03-04 18:13:56 -05001546 nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001547 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001548 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001549 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001551 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Al Viro8687b632006-10-19 23:28:48 -07001556 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Benny Halevy13c65ce2009-08-14 17:19:25 +03001558 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001561 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001562 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Benny Halevy13c65ce2009-08-14 17:19:25 +03001564 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001565 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001566 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001567 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001568 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569}
1570
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001571static 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 -07001572{
Trond Myklebust28331a42011-04-27 13:47:52 -04001573 uint32_t attrs[2] = {
1574 FATTR4_WORD0_RDATTR_ERROR,
1575 FATTR4_WORD1_MOUNTED_ON_FILEID,
1576 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001577 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001578 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001580 if (readdir->plus) {
1581 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001582 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1584 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1585 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1586 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001587 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001588 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001589 /* Use mounted_on_fileid only if the server supports it */
1590 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1591 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592
Benny Halevy13c65ce2009-08-14 17:19:25 +03001593 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001595 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001596 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001597 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001598 *p++ = cpu_to_be32(readdir->count);
1599 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001600
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001602 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001603 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001604 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001605 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1606 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001607 (unsigned long long)readdir->cookie,
1608 ((u32 *)readdir->verifier.data)[0],
1609 ((u32 *)readdir->verifier.data)[1],
1610 attrs[0] & readdir->bitmask[0],
1611 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static 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 -07001615{
Al Viro8687b632006-10-19 23:28:48 -07001616 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Benny Halevy13c65ce2009-08-14 17:19:25 +03001618 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001619 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001620 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001621 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625{
Al Viro8687b632006-10-19 23:28:48 -07001626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001628 p = reserve_space(xdr, 4);
1629 *p = cpu_to_be32(OP_REMOVE);
1630 encode_string(xdr, name->len, name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001631 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001632 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635static 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 -07001636{
Al Viro8687b632006-10-19 23:28:48 -07001637 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Benny Halevy811652b2009-08-14 17:19:34 +03001639 p = reserve_space(xdr, 4);
1640 *p = cpu_to_be32(OP_RENAME);
1641 encode_string(xdr, oldname->len, oldname->name);
1642 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001643 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001644 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Chuck Leverbb4dae52012-03-01 17:01:48 -05001647static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1648 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649{
Al Viro8687b632006-10-19 23:28:48 -07001650 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001653 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001654 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001655 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001656 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001659static void
Andy Adamsond0179312008-12-23 16:06:17 -05001660encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001661{
Al Viro8687b632006-10-19 23:28:48 -07001662 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001663
Benny Halevy13c65ce2009-08-14 17:19:25 +03001664 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001665 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001666 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001667 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001668}
1669
Chuck Lever9f06c712010-12-14 14:59:18 +00001670static void
Andy Adamsond0179312008-12-23 16:06:17 -05001671encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001672{
Al Viro8687b632006-10-19 23:28:48 -07001673 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001674
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001675 p = reserve_space(xdr, 4);
1676 *p = cpu_to_be32(OP_SETATTR);
1677 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001678 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001679 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001680 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001681 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001684 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001685 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001686 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001687}
1688
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001689static void
Andy Adamsond0179312008-12-23 16:06:17 -05001690encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Al Viro8687b632006-10-19 23:28:48 -07001692 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Benny Halevy13c65ce2009-08-14 17:19:25 +03001694 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001695 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001696 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001697 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698}
1699
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001700static 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 -07001701{
Al Viro8687b632006-10-19 23:28:48 -07001702 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001703
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001704 p = reserve_space(xdr, 4);
1705 *p = cpu_to_be32(OP_SETATTR);
1706 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsond0179312008-12-23 16:06:17 -05001707 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001708 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001709 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001712static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
Al Viro8687b632006-10-19 23:28:48 -07001714 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Benny Halevy13c65ce2009-08-14 17:19:25 +03001716 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001717 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001718 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
1720 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001721 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001722 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1724 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001725 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001726 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001727 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001728 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729}
1730
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001731static 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 -07001732{
Andy Adamson05d564f2008-12-23 16:06:15 -05001733 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Benny Halevy13c65ce2009-08-14 17:19:25 +03001735 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001737 p = xdr_encode_hyper(p, arg->clientid);
1738 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001739 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001740 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001743static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
Al Viro8687b632006-10-19 23:28:48 -07001745 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
Benny Halevy13c65ce2009-08-14 17:19:25 +03001747 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001748 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001750 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001751 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
Benny Halevy13c65ce2009-08-14 17:19:25 +03001753 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001754 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001755 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001756 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
1758 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001759 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001760 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001763static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
Al Viro8687b632006-10-19 23:28:48 -07001765 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001767 p = reserve_space(xdr, 4);
1768 *p = cpu_to_be32(OP_DELEGRETURN);
1769 encode_nfs4_stateid(xdr, stateid);
Andy Adamsond0179312008-12-23 16:06:17 -05001770 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001771 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001773
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001774static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1775{
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001776 __be32 *p;
1777
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001778 p = reserve_space(xdr, 4);
1779 *p = cpu_to_be32(OP_SECINFO);
1780 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001781 hdr->nops++;
1782 hdr->replen += decode_secinfo_maxsz;
1783}
1784
Benny Halevy99fe60d2009-04-01 09:22:29 -04001785#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001786/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001787static void encode_exchange_id(struct xdr_stream *xdr,
1788 struct nfs41_exchange_id_args *args,
1789 struct compound_hdr *hdr)
1790{
1791 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001792 char impl_name[NFS4_OPAQUE_LIMIT];
1793 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001794
Benny Halevy13c65ce2009-08-14 17:19:25 +03001795 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001796 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001797 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001798
1799 encode_string(xdr, args->id_len, args->id);
1800
Benny Halevy13c65ce2009-08-14 17:19:25 +03001801 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001802 *p++ = cpu_to_be32(args->flags);
1803 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001804
1805 if (send_implementation_id &&
1806 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1807 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1808 <= NFS4_OPAQUE_LIMIT + 1)
1809 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1810 utsname()->sysname, utsname()->release,
1811 utsname()->version, utsname()->machine);
1812
1813 if (len > 0) {
1814 *p = cpu_to_be32(1); /* implementation id array length=1 */
1815
1816 encode_string(xdr,
1817 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1818 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1819 encode_string(xdr, len, impl_name);
1820 /* just send zeros for nii_date - the date is in nii_name */
1821 p = reserve_space(xdr, 12);
1822 p = xdr_encode_hyper(p, 0);
1823 *p = cpu_to_be32(0);
1824 } else
1825 *p = cpu_to_be32(0); /* implementation id array length=0 */
1826
Benny Halevy99fe60d2009-04-01 09:22:29 -04001827 hdr->nops++;
1828 hdr->replen += decode_exchange_id_maxsz;
1829}
Andy Adamsonfc931582009-04-01 09:22:31 -04001830
1831static void encode_create_session(struct xdr_stream *xdr,
1832 struct nfs41_create_session_args *args,
1833 struct compound_hdr *hdr)
1834{
1835 __be32 *p;
1836 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1837 uint32_t len;
1838 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001839 u32 max_resp_sz_cached;
1840
1841 /*
1842 * Assumes OPEN is the biggest non-idempotent compound.
1843 * 2 is the verifier.
1844 */
1845 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1846 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001847
Andy Adamsonfc931582009-04-01 09:22:31 -04001848 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1849 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001850
Benny Halevy13c65ce2009-08-14 17:19:25 +03001851 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001853 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1855 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001856
Andy Adamsonfc931582009-04-01 09:22:31 -04001857 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001858 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1860 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001861 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001862 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1863 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1864 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001865
1866 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001867 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001868 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1869 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1870 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1871 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1872 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1873 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001874
Benny Halevye75bc1c2009-08-14 17:18:54 +03001875 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001876 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001877 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001878
1879 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001880 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001881 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001882 *p++ = cpu_to_be32(0); /* UID */
1883 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001884 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001885 hdr->nops++;
1886 hdr->replen += decode_create_session_maxsz;
1887}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001888
1889static void encode_destroy_session(struct xdr_stream *xdr,
1890 struct nfs4_session *session,
1891 struct compound_hdr *hdr)
1892{
1893 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001894 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001895 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001896 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001897 hdr->nops++;
1898 hdr->replen += decode_destroy_session_maxsz;
1899}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001900
1901static void encode_reclaim_complete(struct xdr_stream *xdr,
1902 struct nfs41_reclaim_complete_args *args,
1903 struct compound_hdr *hdr)
1904{
1905 __be32 *p;
1906
1907 p = reserve_space(xdr, 8);
1908 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1909 *p++ = cpu_to_be32(args->one_fs);
1910 hdr->nops++;
1911 hdr->replen += decode_reclaim_complete_maxsz;
1912}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001913#endif /* CONFIG_NFS_V4_1 */
1914
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001915static void encode_sequence(struct xdr_stream *xdr,
1916 const struct nfs4_sequence_args *args,
1917 struct compound_hdr *hdr)
1918{
1919#if defined(CONFIG_NFS_V4_1)
1920 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001921 struct nfs4_slot_table *tp;
1922 struct nfs4_slot *slot;
1923 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001924
1925 if (!session)
1926 return;
1927
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001928 tp = &session->fc_slot_table;
1929
1930 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1931 slot = tp->slots + args->sa_slotid;
1932
Benny Halevy13c65ce2009-08-14 17:19:25 +03001933 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001934 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001935
1936 /*
1937 * Sessionid + seqid + slotid + max slotid + cache_this
1938 */
1939 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1940 "max_slotid=%d cache_this=%d\n",
1941 __func__,
1942 ((u32 *)session->sess_id.data)[0],
1943 ((u32 *)session->sess_id.data)[1],
1944 ((u32 *)session->sess_id.data)[2],
1945 ((u32 *)session->sess_id.data)[3],
1946 slot->seq_nr, args->sa_slotid,
1947 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001948 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001949 *p++ = cpu_to_be32(slot->seq_nr);
1950 *p++ = cpu_to_be32(args->sa_slotid);
1951 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001952 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001953 hdr->nops++;
1954 hdr->replen += decode_sequence_maxsz;
1955#endif /* CONFIG_NFS_V4_1 */
1956}
1957
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001958#ifdef CONFIG_NFS_V4_1
1959static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001960encode_getdevicelist(struct xdr_stream *xdr,
1961 const struct nfs4_getdevicelist_args *args,
1962 struct compound_hdr *hdr)
1963{
1964 __be32 *p;
1965 nfs4_verifier dummy = {
1966 .data = "dummmmmy",
1967 };
1968
1969 p = reserve_space(xdr, 20);
1970 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1971 *p++ = cpu_to_be32(args->layoutclass);
1972 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1973 xdr_encode_hyper(p, 0ULL); /* cookie */
1974 encode_nfs4_verifier(xdr, &dummy);
1975 hdr->nops++;
1976 hdr->replen += decode_getdevicelist_maxsz;
1977}
1978
1979static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001980encode_getdeviceinfo(struct xdr_stream *xdr,
1981 const struct nfs4_getdeviceinfo_args *args,
1982 struct compound_hdr *hdr)
1983{
1984 __be32 *p;
1985
1986 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1987 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1988 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1989 NFS4_DEVICEID4_SIZE);
1990 *p++ = cpu_to_be32(args->pdev->layout_type);
1991 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1992 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1993 hdr->nops++;
1994 hdr->replen += decode_getdeviceinfo_maxsz;
1995}
1996
1997static void
1998encode_layoutget(struct xdr_stream *xdr,
1999 const struct nfs4_layoutget_args *args,
2000 struct compound_hdr *hdr)
2001{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002002 __be32 *p;
2003
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002004 p = reserve_space(xdr, 40);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002005 *p++ = cpu_to_be32(OP_LAYOUTGET);
2006 *p++ = cpu_to_be32(0); /* Signal layout available */
2007 *p++ = cpu_to_be32(args->type);
2008 *p++ = cpu_to_be32(args->range.iomode);
2009 p = xdr_encode_hyper(p, args->range.offset);
2010 p = xdr_encode_hyper(p, args->range.length);
2011 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002012 encode_nfs4_stateid(xdr, &args->stateid);
2013 p = reserve_space(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002014 *p = cpu_to_be32(args->maxcount);
2015
2016 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2017 __func__,
2018 args->type,
2019 args->range.iomode,
2020 (unsigned long)args->range.offset,
2021 (unsigned long)args->range.length,
2022 args->maxcount);
2023 hdr->nops++;
2024 hdr->replen += decode_layoutget_maxsz;
2025}
Andy Adamson863a3c62011-03-23 13:27:54 +00002026
2027static int
2028encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002029 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002030 const struct nfs4_layoutcommit_args *args,
2031 struct compound_hdr *hdr)
2032{
2033 __be32 *p;
2034
2035 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2036 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2037
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002038 p = reserve_space(xdr, 24);
Andy Adamson863a3c62011-03-23 13:27:54 +00002039 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2040 /* Only whole file layouts */
2041 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002042 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002043 *p = cpu_to_be32(0); /* reclaim */
2044 encode_nfs4_stateid(xdr, &args->stateid);
2045 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002046 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2047 p = xdr_encode_hyper(p, args->lastbytewritten);
2048 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2049 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002050
2051 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2052 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2053 NFS_I(inode)->layout, xdr, args);
2054 else {
2055 p = reserve_space(xdr, 4);
2056 *p = cpu_to_be32(0); /* no layout-type payload */
2057 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002058
2059 hdr->nops++;
2060 hdr->replen += decode_layoutcommit_maxsz;
2061 return 0;
2062}
Benny Halevycbe82602011-05-22 19:52:37 +03002063
2064static void
2065encode_layoutreturn(struct xdr_stream *xdr,
2066 const struct nfs4_layoutreturn_args *args,
2067 struct compound_hdr *hdr)
2068{
2069 __be32 *p;
2070
2071 p = reserve_space(xdr, 20);
2072 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2073 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2074 *p++ = cpu_to_be32(args->layout_type);
2075 *p++ = cpu_to_be32(IOMODE_ANY);
2076 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002077 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002078 p = xdr_encode_hyper(p, 0);
2079 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2080 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002081 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002082 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002083 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2084 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2085 NFS_I(args->inode)->layout, xdr, args);
2086 } else {
2087 p = reserve_space(xdr, 4);
2088 *p = cpu_to_be32(0);
2089 }
Benny Halevycbe82602011-05-22 19:52:37 +03002090 hdr->nops++;
2091 hdr->replen += decode_layoutreturn_maxsz;
2092}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002093
2094static int
2095encode_secinfo_no_name(struct xdr_stream *xdr,
2096 const struct nfs41_secinfo_no_name_args *args,
2097 struct compound_hdr *hdr)
2098{
2099 __be32 *p;
2100 p = reserve_space(xdr, 8);
2101 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2102 *p++ = cpu_to_be32(args->style);
2103 hdr->nops++;
2104 hdr->replen += decode_secinfo_no_name_maxsz;
2105 return 0;
2106}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002107
2108static void encode_test_stateid(struct xdr_stream *xdr,
2109 struct nfs41_test_stateid_args *args,
2110 struct compound_hdr *hdr)
2111{
2112 __be32 *p;
2113
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002114 p = reserve_space(xdr, 8);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002115 *p++ = cpu_to_be32(OP_TEST_STATEID);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002116 *p = cpu_to_be32(1);
2117 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002118 hdr->nops++;
2119 hdr->replen += decode_test_stateid_maxsz;
2120}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002121
2122static void encode_free_stateid(struct xdr_stream *xdr,
2123 struct nfs41_free_stateid_args *args,
2124 struct compound_hdr *hdr)
2125{
2126 __be32 *p;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002127 p = reserve_space(xdr, 4);
2128 *p = cpu_to_be32(OP_FREE_STATEID);
2129 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002130 hdr->nops++;
2131 hdr->replen += decode_free_stateid_maxsz;
2132}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002133#endif /* CONFIG_NFS_V4_1 */
2134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135/*
2136 * END OF "GENERIC" ENCODE ROUTINES.
2137 */
2138
Benny Halevy66cc0422009-04-01 09:22:10 -04002139static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2140{
2141#if defined(CONFIG_NFS_V4_1)
2142 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002143 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002144#endif /* CONFIG_NFS_V4_1 */
2145 return 0;
2146}
2147
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148/*
2149 * Encode an ACCESS request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->fh, &hdr);
2161 encode_access(xdr, args->access, &hdr);
2162 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002163 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
2166/*
2167 * Encode LOOKUP request
2168 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002169static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2170 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002173 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Chuck Lever9f06c712010-12-14 14:59:18 +00002176 encode_compound_hdr(xdr, req, &hdr);
2177 encode_sequence(xdr, &args->seq_args, &hdr);
2178 encode_putfh(xdr, args->dir_fh, &hdr);
2179 encode_lookup(xdr, args->name, &hdr);
2180 encode_getfh(xdr, &hdr);
2181 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode LOOKUP_ROOT request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2189 struct xdr_stream *xdr,
2190 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002193 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_compound_hdr(xdr, req, &hdr);
2197 encode_sequence(xdr, &args->seq_args, &hdr);
2198 encode_putrootfh(xdr, &hdr);
2199 encode_getfh(xdr, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode REMOVE request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->fh, &hdr);
2217 encode_remove(xdr, &args->name, &hdr);
2218 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002219 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220}
2221
2222/*
2223 * Encode RENAME request
2224 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002225static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2226 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002229 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Chuck Lever9f06c712010-12-14 14:59:18 +00002232 encode_compound_hdr(xdr, req, &hdr);
2233 encode_sequence(xdr, &args->seq_args, &hdr);
2234 encode_putfh(xdr, args->old_dir, &hdr);
2235 encode_savefh(xdr, &hdr);
2236 encode_putfh(xdr, args->new_dir, &hdr);
2237 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2238 encode_getfattr(xdr, args->bitmask, &hdr);
2239 encode_restorefh(xdr, &hdr);
2240 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002241 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242}
2243
2244/*
2245 * Encode LINK request
2246 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002247static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2248 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002251 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253
Chuck Lever9f06c712010-12-14 14:59:18 +00002254 encode_compound_hdr(xdr, req, &hdr);
2255 encode_sequence(xdr, &args->seq_args, &hdr);
2256 encode_putfh(xdr, args->fh, &hdr);
2257 encode_savefh(xdr, &hdr);
2258 encode_putfh(xdr, args->dir_fh, &hdr);
2259 encode_link(xdr, args->name, &hdr);
2260 encode_getfattr(xdr, args->bitmask, &hdr);
2261 encode_restorefh(xdr, &hdr);
2262 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
2266/*
2267 * Encode CREATE request
2268 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002269static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2270 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002273 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 encode_compound_hdr(xdr, req, &hdr);
2277 encode_sequence(xdr, &args->seq_args, &hdr);
2278 encode_putfh(xdr, args->dir_fh, &hdr);
2279 encode_savefh(xdr, &hdr);
2280 encode_create(xdr, args, &hdr);
2281 encode_getfh(xdr, &hdr);
2282 encode_getfattr(xdr, args->bitmask, &hdr);
2283 encode_restorefh(xdr, &hdr);
2284 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002285 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286}
2287
2288/*
2289 * Encode SYMLINK request
2290 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002291static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2292 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293{
Chuck Lever9f06c712010-12-14 14:59:18 +00002294 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
2297/*
2298 * Encode GETATTR request
2299 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002300static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2301 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002304 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Chuck Lever9f06c712010-12-14 14:59:18 +00002307 encode_compound_hdr(xdr, req, &hdr);
2308 encode_sequence(xdr, &args->seq_args, &hdr);
2309 encode_putfh(xdr, args->fh, &hdr);
2310 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002311 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
2314/*
2315 * Encode a CLOSE request
2316 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002317static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2318 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319{
Andy Adamson05d564f2008-12-23 16:06:15 -05002320 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002321 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002322 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
Chuck Lever9f06c712010-12-14 14:59:18 +00002324 encode_compound_hdr(xdr, req, &hdr);
2325 encode_sequence(xdr, &args->seq_args, &hdr);
2326 encode_putfh(xdr, args->fh, &hdr);
2327 encode_close(xdr, args, &hdr);
2328 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002329 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
2332/*
2333 * Encode an OPEN request
2334 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002335static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2336 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002339 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Chuck Lever9f06c712010-12-14 14:59:18 +00002342 encode_compound_hdr(xdr, req, &hdr);
2343 encode_sequence(xdr, &args->seq_args, &hdr);
2344 encode_putfh(xdr, args->fh, &hdr);
2345 encode_savefh(xdr, &hdr);
2346 encode_open(xdr, args, &hdr);
2347 encode_getfh(xdr, &hdr);
2348 encode_getfattr(xdr, args->bitmask, &hdr);
2349 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002350 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002351 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352}
2353
2354/*
2355 * Encode an OPEN_CONFIRM request
2356 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002357static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2358 struct xdr_stream *xdr,
2359 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002362 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Chuck Lever9f06c712010-12-14 14:59:18 +00002365 encode_compound_hdr(xdr, req, &hdr);
2366 encode_putfh(xdr, args->fh, &hdr);
2367 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002368 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
2371/*
2372 * Encode an OPEN request with no attributes.
2373 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002374static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2375 struct xdr_stream *xdr,
2376 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Chuck Lever9f06c712010-12-14 14:59:18 +00002382 encode_compound_hdr(xdr, req, &hdr);
2383 encode_sequence(xdr, &args->seq_args, &hdr);
2384 encode_putfh(xdr, args->fh, &hdr);
2385 encode_open(xdr, args, &hdr);
2386 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002387 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}
2389
2390/*
2391 * Encode an OPEN_DOWNGRADE request
2392 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002393static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2394 struct xdr_stream *xdr,
2395 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002398 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
Chuck Lever9f06c712010-12-14 14:59:18 +00002401 encode_compound_hdr(xdr, req, &hdr);
2402 encode_sequence(xdr, &args->seq_args, &hdr);
2403 encode_putfh(xdr, args->fh, &hdr);
2404 encode_open_downgrade(xdr, args, &hdr);
2405 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002406 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407}
2408
2409/*
2410 * Encode a LOCK request
2411 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002412static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2413 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002416 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Chuck Lever9f06c712010-12-14 14:59:18 +00002419 encode_compound_hdr(xdr, req, &hdr);
2420 encode_sequence(xdr, &args->seq_args, &hdr);
2421 encode_putfh(xdr, args->fh, &hdr);
2422 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002423 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424}
2425
2426/*
2427 * Encode a LOCKT request
2428 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002429static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2430 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Chuck Lever9f06c712010-12-14 14:59:18 +00002436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fh, &hdr);
2439 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002440 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441}
2442
2443/*
2444 * Encode a LOCKU request
2445 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002446static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2447 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002450 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453 encode_compound_hdr(xdr, req, &hdr);
2454 encode_sequence(xdr, &args->seq_args, &hdr);
2455 encode_putfh(xdr, args->fh, &hdr);
2456 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002457 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458}
2459
Chuck Lever9f06c712010-12-14 14:59:18 +00002460static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2461 struct xdr_stream *xdr,
2462 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002464 struct compound_hdr hdr = {
2465 .minorversion = 0,
2466 };
2467
Chuck Lever9f06c712010-12-14 14:59:18 +00002468 encode_compound_hdr(xdr, req, &hdr);
2469 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002470 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002471}
2472
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473/*
2474 * Encode a READLINK request
2475 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002476static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2477 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002480 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
Chuck Lever9f06c712010-12-14 14:59:18 +00002483 encode_compound_hdr(xdr, req, &hdr);
2484 encode_sequence(xdr, &args->seq_args, &hdr);
2485 encode_putfh(xdr, args->fh, &hdr);
2486 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002487
Benny Halevy28f56692009-04-01 09:22:09 -04002488 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002489 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002490 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491}
2492
2493/*
2494 * Encode a READDIR request
2495 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002496static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2497 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002500 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Chuck Lever9f06c712010-12-14 14:59:18 +00002503 encode_compound_hdr(xdr, req, &hdr);
2504 encode_sequence(xdr, &args->seq_args, &hdr);
2505 encode_putfh(xdr, args->fh, &hdr);
2506 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002507
Benny Halevy28f56692009-04-01 09:22:09 -04002508 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002509 args->pgbase, args->count);
2510 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002511 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002512 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002513 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514}
2515
2516/*
2517 * Encode a READ request
2518 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002519static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2520 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002523 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
Chuck Lever9f06c712010-12-14 14:59:18 +00002526 encode_compound_hdr(xdr, req, &hdr);
2527 encode_sequence(xdr, &args->seq_args, &hdr);
2528 encode_putfh(xdr, args->fh, &hdr);
2529 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
Benny Halevy28f56692009-04-01 09:22:09 -04002531 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002533 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002534 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/*
2538 * Encode an SETATTR request
2539 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002540static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2541 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542{
Andy Adamson05d564f2008-12-23 16:06:15 -05002543 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002544 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002545 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Chuck Lever9f06c712010-12-14 14:59:18 +00002547 encode_compound_hdr(xdr, req, &hdr);
2548 encode_sequence(xdr, &args->seq_args, &hdr);
2549 encode_putfh(xdr, args->fh, &hdr);
2550 encode_setattr(xdr, args, args->server, &hdr);
2551 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002552 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553}
2554
2555/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002556 * Encode a GETACL request
2557 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002558static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2559 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002560{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002561 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002562 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002563 };
Benny Halevy28f56692009-04-01 09:22:09 -04002564 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002565
Chuck Lever9f06c712010-12-14 14:59:18 +00002566 encode_compound_hdr(xdr, req, &hdr);
2567 encode_sequence(xdr, &args->seq_args, &hdr);
2568 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002569 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002570 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002571
Benny Halevy28f56692009-04-01 09:22:09 -04002572 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002573 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002574
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002576}
2577
2578/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 * Encode a WRITE request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2582 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002585 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Chuck Lever9f06c712010-12-14 14:59:18 +00002588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_sequence(xdr, &args->seq_args, &hdr);
2590 encode_putfh(xdr, args->fh, &hdr);
2591 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002592 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002593 if (args->bitmask)
2594 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002595 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
2598/*
2599 * a COMMIT request
2600 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002601static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2602 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fh, &hdr);
2611 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002612 if (args->bitmask)
2613 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002614 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615}
2616
2617/*
2618 * FSINFO request
2619 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002620static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2621 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Chuck Lever9f06c712010-12-14 14:59:18 +00002627 encode_compound_hdr(xdr, req, &hdr);
2628 encode_sequence(xdr, &args->seq_args, &hdr);
2629 encode_putfh(xdr, args->fh, &hdr);
2630 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002631 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632}
2633
2634/*
2635 * a PATHCONF request
2636 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002637static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2638 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002641 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
Chuck Lever9f06c712010-12-14 14:59:18 +00002644 encode_compound_hdr(xdr, req, &hdr);
2645 encode_sequence(xdr, &args->seq_args, &hdr);
2646 encode_putfh(xdr, args->fh, &hdr);
2647 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002648 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002649 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650}
2651
2652/*
2653 * a STATFS request
2654 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002655static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2656 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002659 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
Chuck Lever9f06c712010-12-14 14:59:18 +00002662 encode_compound_hdr(xdr, req, &hdr);
2663 encode_sequence(xdr, &args->seq_args, &hdr);
2664 encode_putfh(xdr, args->fh, &hdr);
2665 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002666 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002667 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668}
2669
2670/*
2671 * GETATTR_BITMAP request
2672 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002673static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2674 struct xdr_stream *xdr,
2675 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002678 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Chuck Lever9f06c712010-12-14 14:59:18 +00002681 encode_compound_hdr(xdr, req, &hdr);
2682 encode_sequence(xdr, &args->seq_args, &hdr);
2683 encode_putfh(xdr, args->fhandle, &hdr);
2684 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002685 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002686 FATTR4_WORD0_LINK_SUPPORT|
2687 FATTR4_WORD0_SYMLINK_SUPPORT|
2688 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002689 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690}
2691
2692/*
2693 * a RENEW request
2694 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002695static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2696 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002699 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 };
2701
Chuck Lever9f06c712010-12-14 14:59:18 +00002702 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002703 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002704 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705}
2706
2707/*
2708 * a SETCLIENTID request
2709 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002710static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2711 struct xdr_stream *xdr,
2712 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002715 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 };
2717
Chuck Lever9f06c712010-12-14 14:59:18 +00002718 encode_compound_hdr(xdr, req, &hdr);
2719 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002720 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721}
2722
2723/*
2724 * a SETCLIENTID_CONFIRM request
2725 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002726static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2727 struct xdr_stream *xdr,
2728 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002731 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 };
Fred Isamandae100c2011-07-30 20:52:37 -04002733 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
Chuck Lever9f06c712010-12-14 14:59:18 +00002735 encode_compound_hdr(xdr, req, &hdr);
2736 encode_setclientid_confirm(xdr, arg, &hdr);
2737 encode_putrootfh(xdr, &hdr);
2738 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002739 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740}
2741
2742/*
2743 * DELEGRETURN request
2744 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002745static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
2747 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
Chuck Lever9f06c712010-12-14 14:59:18 +00002753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->seq_args, &hdr);
2755 encode_putfh(xdr, args->fhandle, &hdr);
2756 encode_delegreturn(xdr, args->stateid, &hdr);
2757 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002758 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759}
2760
2761/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002762 * Encode FS_LOCATIONS request
2763 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002764static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002767{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002768 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002769 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002770 };
Benny Halevy28f56692009-04-01 09:22:09 -04002771 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002772
Chuck Lever9f06c712010-12-14 14:59:18 +00002773 encode_compound_hdr(xdr, req, &hdr);
2774 encode_sequence(xdr, &args->seq_args, &hdr);
2775 encode_putfh(xdr, args->dir_fh, &hdr);
2776 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002777 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002778 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002779
Benny Halevy28f56692009-04-01 09:22:09 -04002780 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002781 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002782 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002783}
2784
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002785/*
2786 * Encode SECINFO request
2787 */
2788static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2789 struct xdr_stream *xdr,
2790 struct nfs4_secinfo_arg *args)
2791{
2792 struct compound_hdr hdr = {
2793 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2794 };
2795
2796 encode_compound_hdr(xdr, req, &hdr);
2797 encode_sequence(xdr, &args->seq_args, &hdr);
2798 encode_putfh(xdr, args->dir_fh, &hdr);
2799 encode_secinfo(xdr, args->name, &hdr);
2800 encode_nops(&hdr);
2801}
2802
Benny Halevy99fe60d2009-04-01 09:22:29 -04002803#if defined(CONFIG_NFS_V4_1)
2804/*
2805 * EXCHANGE_ID request
2806 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002807static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2808 struct xdr_stream *xdr,
2809 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002810{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002811 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002812 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002813 };
2814
Chuck Lever9f06c712010-12-14 14:59:18 +00002815 encode_compound_hdr(xdr, req, &hdr);
2816 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002817 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002818}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002819
2820/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002821 * a CREATE_SESSION request
2822 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002823static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2824 struct xdr_stream *xdr,
2825 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002826{
Andy Adamsonfc931582009-04-01 09:22:31 -04002827 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002828 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002829 };
2830
Chuck Lever9f06c712010-12-14 14:59:18 +00002831 encode_compound_hdr(xdr, req, &hdr);
2832 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002833 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002834}
2835
2836/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002837 * a DESTROY_SESSION request
2838 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002839static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2840 struct xdr_stream *xdr,
2841 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002842{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002843 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002844 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002845 };
2846
Chuck Lever9f06c712010-12-14 14:59:18 +00002847 encode_compound_hdr(xdr, req, &hdr);
2848 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002849 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002850}
2851
2852/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002853 * a SEQUENCE request
2854 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002855static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2856 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002857{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002858 struct compound_hdr hdr = {
2859 .minorversion = nfs4_xdr_minorversion(args),
2860 };
2861
Chuck Lever9f06c712010-12-14 14:59:18 +00002862 encode_compound_hdr(xdr, req, &hdr);
2863 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002864 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002865}
2866
2867/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002868 * a GET_LEASE_TIME request
2869 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002870static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2871 struct xdr_stream *xdr,
2872 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002873{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002874 struct compound_hdr hdr = {
2875 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2876 };
Fred Isamandae100c2011-07-30 20:52:37 -04002877 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002878
Chuck Lever9f06c712010-12-14 14:59:18 +00002879 encode_compound_hdr(xdr, req, &hdr);
2880 encode_sequence(xdr, &args->la_seq_args, &hdr);
2881 encode_putrootfh(xdr, &hdr);
2882 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002883 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002884}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002885
2886/*
2887 * a RECLAIM_COMPLETE request
2888 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002889static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2890 struct xdr_stream *xdr,
2891 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002892{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002893 struct compound_hdr hdr = {
2894 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2895 };
2896
Chuck Lever9f06c712010-12-14 14:59:18 +00002897 encode_compound_hdr(xdr, req, &hdr);
2898 encode_sequence(xdr, &args->seq_args, &hdr);
2899 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002900 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002901}
2902
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002903/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002904 * Encode GETDEVICELIST request
2905 */
2906static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2907 struct xdr_stream *xdr,
2908 struct nfs4_getdevicelist_args *args)
2909{
2910 struct compound_hdr hdr = {
2911 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2912 };
2913
2914 encode_compound_hdr(xdr, req, &hdr);
2915 encode_sequence(xdr, &args->seq_args, &hdr);
2916 encode_putfh(xdr, args->fh, &hdr);
2917 encode_getdevicelist(xdr, args, &hdr);
2918 encode_nops(&hdr);
2919}
2920
2921/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002922 * Encode GETDEVICEINFO request
2923 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002924static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2925 struct xdr_stream *xdr,
2926 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002927{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002928 struct compound_hdr hdr = {
2929 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2930 };
2931
Chuck Lever9f06c712010-12-14 14:59:18 +00002932 encode_compound_hdr(xdr, req, &hdr);
2933 encode_sequence(xdr, &args->seq_args, &hdr);
2934 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002935
2936 /* set up reply kvec. Subtract notification bitmap max size (2)
2937 * so that notification bitmap is put in xdr_buf tail */
2938 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2939 args->pdev->pages, args->pdev->pgbase,
2940 args->pdev->pglen);
2941
2942 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002943}
2944
2945/*
2946 * Encode LAYOUTGET request
2947 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002948static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2949 struct xdr_stream *xdr,
2950 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002951{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002952 struct compound_hdr hdr = {
2953 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2954 };
2955
Chuck Lever9f06c712010-12-14 14:59:18 +00002956 encode_compound_hdr(xdr, req, &hdr);
2957 encode_sequence(xdr, &args->seq_args, &hdr);
2958 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2959 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002960
2961 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2962 args->layout.pages, 0, args->layout.pglen);
2963
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002964 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002965}
Andy Adamson863a3c62011-03-23 13:27:54 +00002966
2967/*
2968 * Encode LAYOUTCOMMIT request
2969 */
Benny Halevycbe82602011-05-22 19:52:37 +03002970static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2971 struct xdr_stream *xdr,
2972 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002973{
Benny Halevyac7db722011-05-22 19:53:48 +03002974 struct nfs4_layoutcommit_data *data =
2975 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002976 struct compound_hdr hdr = {
2977 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2978 };
2979
2980 encode_compound_hdr(xdr, req, &hdr);
2981 encode_sequence(xdr, &args->seq_args, &hdr);
2982 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002983 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002984 encode_getfattr(xdr, args->bitmask, &hdr);
2985 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002986}
2987
2988/*
2989 * Encode LAYOUTRETURN request
2990 */
2991static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2992 struct xdr_stream *xdr,
2993 struct nfs4_layoutreturn_args *args)
2994{
2995 struct compound_hdr hdr = {
2996 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2997 };
2998
2999 encode_compound_hdr(xdr, req, &hdr);
3000 encode_sequence(xdr, &args->seq_args, &hdr);
3001 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3002 encode_layoutreturn(xdr, args, &hdr);
3003 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003004}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003005
3006/*
3007 * Encode SECINFO_NO_NAME request
3008 */
3009static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3010 struct xdr_stream *xdr,
3011 struct nfs41_secinfo_no_name_args *args)
3012{
3013 struct compound_hdr hdr = {
3014 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3015 };
3016
3017 encode_compound_hdr(xdr, req, &hdr);
3018 encode_sequence(xdr, &args->seq_args, &hdr);
3019 encode_putrootfh(xdr, &hdr);
3020 encode_secinfo_no_name(xdr, args, &hdr);
3021 encode_nops(&hdr);
3022 return 0;
3023}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003024
3025/*
3026 * Encode TEST_STATEID request
3027 */
3028static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3029 struct xdr_stream *xdr,
3030 struct nfs41_test_stateid_args *args)
3031{
3032 struct compound_hdr hdr = {
3033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3034 };
3035
3036 encode_compound_hdr(xdr, req, &hdr);
3037 encode_sequence(xdr, &args->seq_args, &hdr);
3038 encode_test_stateid(xdr, args, &hdr);
3039 encode_nops(&hdr);
3040}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003041
3042/*
3043 * Encode FREE_STATEID request
3044 */
3045static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3046 struct xdr_stream *xdr,
3047 struct nfs41_free_stateid_args *args)
3048{
3049 struct compound_hdr hdr = {
3050 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3051 };
3052
3053 encode_compound_hdr(xdr, req, &hdr);
3054 encode_sequence(xdr, &args->seq_args, &hdr);
3055 encode_free_stateid(xdr, args, &hdr);
3056 encode_nops(&hdr);
3057}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003058#endif /* CONFIG_NFS_V4_1 */
3059
Benny Halevy686841b2009-08-14 17:19:48 +03003060static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3061{
3062 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3063 "Remaining buffer length is %tu words.\n",
3064 func, xdr->end - xdr->p);
3065}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
Trond Myklebust683b57b2006-06-09 09:34:22 -04003067static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068{
Al Viro8687b632006-10-19 23:28:48 -07003069 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
Benny Halevyc0eae662009-08-14 17:20:14 +03003071 p = xdr_inline_decode(xdr, 4);
3072 if (unlikely(!p))
3073 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003074 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003075 p = xdr_inline_decode(xdr, *len);
3076 if (unlikely(!p))
3077 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 *string = (char *)p;
3079 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003080out_overflow:
3081 print_overflow_msg(__func__, xdr);
3082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083}
3084
3085static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3086{
Al Viro8687b632006-10-19 23:28:48 -07003087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
Benny Halevyc0eae662009-08-14 17:20:14 +03003089 p = xdr_inline_decode(xdr, 8);
3090 if (unlikely(!p))
3091 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003092 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003093 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003094
Benny Halevyc0eae662009-08-14 17:20:14 +03003095 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3096 if (unlikely(!p))
3097 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 hdr->tag = (char *)p;
3099 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003100 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003101 if (unlikely(hdr->nops < 1))
3102 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003104out_overflow:
3105 print_overflow_msg(__func__, xdr);
3106 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107}
3108
3109static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3110{
Al Viro8687b632006-10-19 23:28:48 -07003111 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 uint32_t opnum;
3113 int32_t nfserr;
3114
Benny Halevyc0eae662009-08-14 17:20:14 +03003115 p = xdr_inline_decode(xdr, 8);
3116 if (unlikely(!p))
3117 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003118 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003120 dprintk("nfs: Server returned operation"
3121 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 opnum, expected);
3123 return -EIO;
3124 }
Benny Halevycccddf42009-08-14 17:20:19 +03003125 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003127 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003129out_overflow:
3130 print_overflow_msg(__func__, xdr);
3131 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132}
3133
3134/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003135static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136{
Al Viro8687b632006-10-19 23:28:48 -07003137 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003138 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 char *str;
3140
Benny Halevyc0eae662009-08-14 17:20:14 +03003141 p = xdr_inline_decode(xdr, 12);
3142 if (likely(p))
3143 return decode_opaque_inline(xdr, &strlen, &str);
3144 print_overflow_msg(__func__, xdr);
3145 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146}
3147
3148static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3149{
Al Viro8687b632006-10-19 23:28:48 -07003150 uint32_t bmlen;
3151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
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 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
Fred Isamandae100c2011-07-30 20:52:37 -04003158 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003159 p = xdr_inline_decode(xdr, (bmlen << 2));
3160 if (unlikely(!p))
3161 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003163 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003164 if (bmlen > 1) {
3165 bitmap[1] = be32_to_cpup(p++);
3166 if (bmlen > 2)
3167 bitmap[2] = be32_to_cpup(p);
3168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
3170 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003171out_overflow:
3172 print_overflow_msg(__func__, xdr);
3173 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174}
3175
Al Viro8687b632006-10-19 23:28:48 -07003176static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
Al Viro8687b632006-10-19 23:28:48 -07003178 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
Benny Halevyc0eae662009-08-14 17:20:14 +03003180 p = xdr_inline_decode(xdr, 4);
3181 if (unlikely(!p))
3182 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003183 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 *savep = xdr->p;
3185 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003186out_overflow:
3187 print_overflow_msg(__func__, xdr);
3188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189}
3190
3191static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3192{
3193 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003194 int ret;
3195 ret = decode_attr_bitmap(xdr, bitmask);
3196 if (unlikely(ret < 0))
3197 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3199 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003200 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3201 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3202 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 return 0;
3204}
3205
3206static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3207{
Al Viro8687b632006-10-19 23:28:48 -07003208 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003209 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
3211 *type = 0;
3212 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3213 return -EIO;
3214 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003215 p = xdr_inline_decode(xdr, 4);
3216 if (unlikely(!p))
3217 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003218 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003220 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 return -EIO;
3222 }
3223 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003224 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003226 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003228out_overflow:
3229 print_overflow_msg(__func__, xdr);
3230 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231}
3232
Chuck Lever264e6352012-03-01 17:02:05 -05003233static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3234 uint32_t *bitmap, uint32_t *type)
3235{
3236 __be32 *p;
3237
3238 *type = 0;
3239 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3240 return -EIO;
3241 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3242 p = xdr_inline_decode(xdr, 4);
3243 if (unlikely(!p))
3244 goto out_overflow;
3245 *type = be32_to_cpup(p);
3246 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3247 }
3248 dprintk("%s: expire type=0x%x\n", __func__, *type);
3249 return 0;
3250out_overflow:
3251 print_overflow_msg(__func__, xdr);
3252 return -EIO;
3253}
3254
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3256{
Al Viro8687b632006-10-19 23:28:48 -07003257 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003258 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
3260 *change = 0;
3261 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3262 return -EIO;
3263 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003264 p = xdr_inline_decode(xdr, 8);
3265 if (unlikely(!p))
3266 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003267 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003269 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003271 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003273 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003274out_overflow:
3275 print_overflow_msg(__func__, xdr);
3276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277}
3278
3279static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3280{
Al Viro8687b632006-10-19 23:28:48 -07003281 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003282 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
3284 *size = 0;
3285 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3286 return -EIO;
3287 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003288 p = xdr_inline_decode(xdr, 8);
3289 if (unlikely(!p))
3290 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003291 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003293 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
3302static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3303{
Al Viro8687b632006-10-19 23:28:48 -07003304 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
3306 *res = 0;
3307 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3308 return -EIO;
3309 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003310 p = xdr_inline_decode(xdr, 4);
3311 if (unlikely(!p))
3312 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003313 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3315 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003316 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003318out_overflow:
3319 print_overflow_msg(__func__, xdr);
3320 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321}
3322
3323static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3324{
Al Viro8687b632006-10-19 23:28:48 -07003325 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
3327 *res = 0;
3328 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3329 return -EIO;
3330 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003331 p = xdr_inline_decode(xdr, 4);
3332 if (unlikely(!p))
3333 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003334 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3336 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003337 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003339out_overflow:
3340 print_overflow_msg(__func__, xdr);
3341 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342}
3343
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003344static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345{
Al Viro8687b632006-10-19 23:28:48 -07003346 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003347 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
3349 fsid->major = 0;
3350 fsid->minor = 0;
3351 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3352 return -EIO;
3353 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003354 p = xdr_inline_decode(xdr, 16);
3355 if (unlikely(!p))
3356 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003357 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003358 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003360 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003362 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 (unsigned long long)fsid->major,
3364 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003365 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003366out_overflow:
3367 print_overflow_msg(__func__, xdr);
3368 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369}
3370
3371static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3372{
Al Viro8687b632006-10-19 23:28:48 -07003373 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374
3375 *res = 60;
3376 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3377 return -EIO;
3378 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003379 p = xdr_inline_decode(xdr, 4);
3380 if (unlikely(!p))
3381 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003382 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3384 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003385 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003387out_overflow:
3388 print_overflow_msg(__func__, xdr);
3389 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390}
3391
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003392static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003393{
3394 __be32 *p;
3395
3396 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3397 return -EIO;
3398 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3399 p = xdr_inline_decode(xdr, 4);
3400 if (unlikely(!p))
3401 goto out_overflow;
3402 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003403 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003404 }
3405 return 0;
3406out_overflow:
3407 print_overflow_msg(__func__, xdr);
3408 return -EIO;
3409}
3410
3411static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3412{
3413 __be32 *p;
3414 int len;
3415
Trond Myklebust7ad07352010-10-23 15:34:20 -04003416 if (fh != NULL)
3417 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003418
3419 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3420 return -EIO;
3421 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3422 p = xdr_inline_decode(xdr, 4);
3423 if (unlikely(!p))
3424 goto out_overflow;
3425 len = be32_to_cpup(p);
3426 if (len > NFS4_FHSIZE)
3427 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003428 p = xdr_inline_decode(xdr, len);
3429 if (unlikely(!p))
3430 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003431 if (fh != NULL) {
3432 memcpy(fh->data, p, len);
3433 fh->size = len;
3434 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003435 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3436 }
3437 return 0;
3438out_overflow:
3439 print_overflow_msg(__func__, xdr);
3440 return -EIO;
3441}
3442
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3444{
Al Viro8687b632006-10-19 23:28:48 -07003445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3448 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3449 return -EIO;
3450 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003451 p = xdr_inline_decode(xdr, 4);
3452 if (unlikely(!p))
3453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003454 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3456 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003457 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459out_overflow:
3460 print_overflow_msg(__func__, xdr);
3461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462}
3463
3464static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3465{
Al Viro8687b632006-10-19 23:28:48 -07003466 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003467 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
3469 *fileid = 0;
3470 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3471 return -EIO;
3472 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003473 p = xdr_inline_decode(xdr, 8);
3474 if (unlikely(!p))
3475 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003476 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003478 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003480 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003481 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003482out_overflow:
3483 print_overflow_msg(__func__, xdr);
3484 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485}
3486
Manoj Naik99baf622006-06-09 09:34:24 -04003487static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3488{
Al Viro8687b632006-10-19 23:28:48 -07003489 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003490 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003491
3492 *fileid = 0;
3493 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3494 return -EIO;
3495 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003496 p = xdr_inline_decode(xdr, 8);
3497 if (unlikely(!p))
3498 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003499 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003500 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003501 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003502 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003503 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003504 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003505out_overflow:
3506 print_overflow_msg(__func__, xdr);
3507 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003508}
3509
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3511{
Al Viro8687b632006-10-19 23:28:48 -07003512 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 int status = 0;
3514
3515 *res = 0;
3516 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3517 return -EIO;
3518 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003519 p = xdr_inline_decode(xdr, 8);
3520 if (unlikely(!p))
3521 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003522 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3524 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003525 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003527out_overflow:
3528 print_overflow_msg(__func__, xdr);
3529 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530}
3531
3532static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3533{
Al Viro8687b632006-10-19 23:28:48 -07003534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 int status = 0;
3536
3537 *res = 0;
3538 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3539 return -EIO;
3540 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003541 p = xdr_inline_decode(xdr, 8);
3542 if (unlikely(!p))
3543 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003544 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3546 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003547 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003549out_overflow:
3550 print_overflow_msg(__func__, xdr);
3551 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552}
3553
3554static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3555{
Al Viro8687b632006-10-19 23:28:48 -07003556 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 int status = 0;
3558
3559 *res = 0;
3560 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3561 return -EIO;
3562 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003563 p = xdr_inline_decode(xdr, 8);
3564 if (unlikely(!p))
3565 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003566 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3568 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003569 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003571out_overflow:
3572 print_overflow_msg(__func__, xdr);
3573 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574}
3575
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003576static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3577{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003578 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003579 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003580 int status = 0;
3581
Benny Halevyc0eae662009-08-14 17:20:14 +03003582 p = xdr_inline_decode(xdr, 4);
3583 if (unlikely(!p))
3584 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003585 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003586 if (n == 0)
3587 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003588 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003589 path->ncomponents = 0;
3590 while (path->ncomponents < n) {
3591 struct nfs4_string *component = &path->components[path->ncomponents];
3592 status = decode_opaque_inline(xdr, &component->len, &component->data);
3593 if (unlikely(status != 0))
3594 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003595 if (unlikely(nfs_debug & NFSDBG_XDR))
3596 pr_cont("%s%.*s ",
3597 (path->ncomponents != n ? "/ " : ""),
3598 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003599 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3600 path->ncomponents++;
3601 else {
3602 dprintk("cannot parse %d components in path\n", n);
3603 goto out_eio;
3604 }
3605 }
3606out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003607 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003608root_path:
3609/* a root pathname is sent as a zero component4 */
3610 path->ncomponents = 1;
3611 path->components[0].len=0;
3612 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003613 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003614 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003615out_eio:
3616 dprintk(" status %d", status);
3617 status = -EIO;
3618 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003619out_overflow:
3620 print_overflow_msg(__func__, xdr);
3621 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003622}
3623
3624static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003625{
3626 int n;
Al Viro8687b632006-10-19 23:28:48 -07003627 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003628 int status = -EIO;
3629
3630 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3631 goto out;
3632 status = 0;
3633 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3634 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003635 status = -EIO;
3636 /* Ignore borken servers that return unrequested attrs */
3637 if (unlikely(res == NULL))
3638 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003639 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003640 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003641 if (unlikely(status != 0))
3642 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 4);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003647 if (n <= 0)
3648 goto out_eio;
3649 res->nlocations = 0;
3650 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003651 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003652 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003653
Benny Halevyc0eae662009-08-14 17:20:14 +03003654 p = xdr_inline_decode(xdr, 4);
3655 if (unlikely(!p))
3656 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003657 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003658
3659 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003660 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003661 while (loc->nservers < m) {
3662 struct nfs4_string *server = &loc->servers[loc->nservers];
3663 status = decode_opaque_inline(xdr, &server->len, &server->data);
3664 if (unlikely(status != 0))
3665 goto out_eio;
3666 dprintk("%s ", server->data);
3667 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3668 loc->nservers++;
3669 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003670 unsigned int i;
3671 dprintk("%s: using first %u of %u servers "
3672 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003673 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003674 NFS4_FS_LOCATION_MAXSERVERS,
3675 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003676 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003677 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003678 char *data;
3679 status = decode_opaque_inline(xdr, &len, &data);
3680 if (unlikely(status != 0))
3681 goto out_eio;
3682 }
3683 }
3684 }
3685 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003686 if (unlikely(status != 0))
3687 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003688 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003689 res->nlocations++;
3690 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003692 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003693out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003694 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003695 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003696out_overflow:
3697 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003698out_eio:
3699 status = -EIO;
3700 goto out;
3701}
3702
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3704{
Al Viro8687b632006-10-19 23:28:48 -07003705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 int status = 0;
3707
3708 *res = 0;
3709 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3710 return -EIO;
3711 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003712 p = xdr_inline_decode(xdr, 8);
3713 if (unlikely(!p))
3714 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003715 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3717 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003718 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003720out_overflow:
3721 print_overflow_msg(__func__, xdr);
3722 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723}
3724
3725static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3726{
Al Viro8687b632006-10-19 23:28:48 -07003727 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 int status = 0;
3729
3730 *maxlink = 1;
3731 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3732 return -EIO;
3733 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003734 p = xdr_inline_decode(xdr, 4);
3735 if (unlikely(!p))
3736 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003737 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3739 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003740 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003742out_overflow:
3743 print_overflow_msg(__func__, xdr);
3744 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745}
3746
3747static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3748{
Al Viro8687b632006-10-19 23:28:48 -07003749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 int status = 0;
3751
3752 *maxname = 1024;
3753 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3754 return -EIO;
3755 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003756 p = xdr_inline_decode(xdr, 4);
3757 if (unlikely(!p))
3758 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003759 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3761 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003762 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003764out_overflow:
3765 print_overflow_msg(__func__, xdr);
3766 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767}
3768
3769static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3770{
Al Viro8687b632006-10-19 23:28:48 -07003771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 int status = 0;
3773
3774 *res = 1024;
3775 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3776 return -EIO;
3777 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3778 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003779 p = xdr_inline_decode(xdr, 8);
3780 if (unlikely(!p))
3781 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003782 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 if (maxread > 0x7FFFFFFF)
3784 maxread = 0x7FFFFFFF;
3785 *res = (uint32_t)maxread;
3786 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3787 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003788 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003790out_overflow:
3791 print_overflow_msg(__func__, xdr);
3792 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793}
3794
3795static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3796{
Al Viro8687b632006-10-19 23:28:48 -07003797 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 int status = 0;
3799
3800 *res = 1024;
3801 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3802 return -EIO;
3803 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3804 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003805 p = xdr_inline_decode(xdr, 8);
3806 if (unlikely(!p))
3807 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003808 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 if (maxwrite > 0x7FFFFFFF)
3810 maxwrite = 0x7FFFFFFF;
3811 *res = (uint32_t)maxwrite;
3812 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3813 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003814 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003816out_overflow:
3817 print_overflow_msg(__func__, xdr);
3818 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819}
3820
Trond Myklebustbca79472009-03-11 14:10:26 -04003821static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822{
Trond Myklebustbca79472009-03-11 14:10:26 -04003823 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003824 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003825 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826
3827 *mode = 0;
3828 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3829 return -EIO;
3830 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003831 p = xdr_inline_decode(xdr, 4);
3832 if (unlikely(!p))
3833 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003834 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003835 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003839 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003841out_overflow:
3842 print_overflow_msg(__func__, xdr);
3843 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844}
3845
3846static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3847{
Al Viro8687b632006-10-19 23:28:48 -07003848 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850
3851 *nlink = 1;
3852 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3853 return -EIO;
3854 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003855 p = xdr_inline_decode(xdr, 4);
3856 if (unlikely(!p))
3857 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003858 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003862 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003863 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003864out_overflow:
3865 print_overflow_msg(__func__, xdr);
3866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867}
3868
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003869static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003870 const struct nfs_server *server, uint32_t *uid,
3871 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872{
Al Viro8687b632006-10-19 23:28:48 -07003873 uint32_t len;
3874 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876
3877 *uid = -2;
3878 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3879 return -EIO;
3880 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003881 p = xdr_inline_decode(xdr, 4);
3882 if (unlikely(!p))
3883 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003884 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003885 p = xdr_inline_decode(xdr, len);
3886 if (unlikely(!p))
3887 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003888 if (owner_name != NULL) {
3889 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3890 if (owner_name->data != NULL) {
3891 owner_name->len = len;
3892 ret = NFS_ATTR_FATTR_OWNER_NAME;
3893 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003894 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003895 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003896 ret = NFS_ATTR_FATTR_OWNER;
3897 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003899 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003901 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003902 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3904 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003905 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003906 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003907out_overflow:
3908 print_overflow_msg(__func__, xdr);
3909 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910}
3911
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003912static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003913 const struct nfs_server *server, uint32_t *gid,
3914 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915{
Al Viro8687b632006-10-19 23:28:48 -07003916 uint32_t len;
3917 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003918 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919
3920 *gid = -2;
3921 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3922 return -EIO;
3923 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003924 p = xdr_inline_decode(xdr, 4);
3925 if (unlikely(!p))
3926 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003927 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003928 p = xdr_inline_decode(xdr, len);
3929 if (unlikely(!p))
3930 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003931 if (group_name != NULL) {
3932 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3933 if (group_name->data != NULL) {
3934 group_name->len = len;
3935 ret = NFS_ATTR_FATTR_GROUP_NAME;
3936 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003937 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003938 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003939 ret = NFS_ATTR_FATTR_GROUP;
3940 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003942 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003944 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003945 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3947 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003948 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003949 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003950out_overflow:
3951 print_overflow_msg(__func__, xdr);
3952 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953}
3954
3955static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3956{
Al Viro8687b632006-10-19 23:28:48 -07003957 uint32_t major = 0, minor = 0;
3958 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003959 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
3961 *rdev = MKDEV(0,0);
3962 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3963 return -EIO;
3964 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3965 dev_t tmp;
3966
Benny Halevyc0eae662009-08-14 17:20:14 +03003967 p = xdr_inline_decode(xdr, 8);
3968 if (unlikely(!p))
3969 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003970 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003971 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 tmp = MKDEV(major, minor);
3973 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3974 *rdev = tmp;
3975 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003976 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003978 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003979 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003980out_overflow:
3981 print_overflow_msg(__func__, xdr);
3982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983}
3984
3985static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3986{
Al Viro8687b632006-10-19 23:28:48 -07003987 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 int status = 0;
3989
3990 *res = 0;
3991 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3992 return -EIO;
3993 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003994 p = xdr_inline_decode(xdr, 8);
3995 if (unlikely(!p))
3996 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003997 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3999 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004000 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004002out_overflow:
4003 print_overflow_msg(__func__, xdr);
4004 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005}
4006
4007static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4008{
Al Viro8687b632006-10-19 23:28:48 -07004009 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 int status = 0;
4011
4012 *res = 0;
4013 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4014 return -EIO;
4015 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004016 p = xdr_inline_decode(xdr, 8);
4017 if (unlikely(!p))
4018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004019 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4021 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004022 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004024out_overflow:
4025 print_overflow_msg(__func__, xdr);
4026 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027}
4028
4029static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4030{
Al Viro8687b632006-10-19 23:28:48 -07004031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 int status = 0;
4033
4034 *res = 0;
4035 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4036 return -EIO;
4037 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004038 p = xdr_inline_decode(xdr, 8);
4039 if (unlikely(!p))
4040 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004041 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4043 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004044 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004046out_overflow:
4047 print_overflow_msg(__func__, xdr);
4048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049}
4050
4051static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4052{
Al Viro8687b632006-10-19 23:28:48 -07004053 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004054 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
4056 *used = 0;
4057 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4058 return -EIO;
4059 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004060 p = xdr_inline_decode(xdr, 8);
4061 if (unlikely(!p))
4062 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004063 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004065 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004067 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004069 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004070out_overflow:
4071 print_overflow_msg(__func__, xdr);
4072 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073}
4074
4075static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4076{
Al Viro8687b632006-10-19 23:28:48 -07004077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 uint64_t sec;
4079 uint32_t nsec;
4080
Benny Halevyc0eae662009-08-14 17:20:14 +03004081 p = xdr_inline_decode(xdr, 12);
4082 if (unlikely(!p))
4083 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004084 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004085 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 time->tv_sec = (time_t)sec;
4087 time->tv_nsec = (long)nsec;
4088 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004089out_overflow:
4090 print_overflow_msg(__func__, xdr);
4091 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092}
4093
4094static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4095{
4096 int status = 0;
4097
4098 time->tv_sec = 0;
4099 time->tv_nsec = 0;
4100 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4101 return -EIO;
4102 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4103 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004104 if (status == 0)
4105 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4107 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004108 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 return status;
4110}
4111
4112static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4113{
4114 int status = 0;
4115
4116 time->tv_sec = 0;
4117 time->tv_nsec = 0;
4118 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4119 return -EIO;
4120 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4121 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004122 if (status == 0)
4123 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4125 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004126 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 return status;
4128}
4129
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004130static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4131 struct timespec *time)
4132{
4133 int status = 0;
4134
4135 time->tv_sec = 0;
4136 time->tv_nsec = 0;
4137 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4138 return -EIO;
4139 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4140 status = decode_attr_time(xdr, time);
4141 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4142 }
4143 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4144 (long)time->tv_nsec);
4145 return status;
4146}
4147
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4149{
4150 int status = 0;
4151
4152 time->tv_sec = 0;
4153 time->tv_nsec = 0;
4154 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4155 return -EIO;
4156 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4157 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004158 if (status == 0)
4159 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4161 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004162 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 return status;
4164}
4165
Al Viro8687b632006-10-19 23:28:48 -07004166static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167{
4168 unsigned int attrwords = XDR_QUADLEN(attrlen);
4169 unsigned int nwords = xdr->p - savep;
4170
4171 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004172 dprintk("%s: server returned incorrect attribute length: "
4173 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004174 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 attrwords << 2,
4176 (attrwords < nwords) ? '<' : '>',
4177 nwords << 2);
4178 return -EIO;
4179 }
4180 return 0;
4181}
4182
4183static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4184{
Al Viro8687b632006-10-19 23:28:48 -07004185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
Benny Halevyc0eae662009-08-14 17:20:14 +03004187 p = xdr_inline_decode(xdr, 20);
4188 if (unlikely(!p))
4189 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004190 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004191 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004192 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004194out_overflow:
4195 print_overflow_msg(__func__, xdr);
4196 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197}
4198
4199static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4200{
Al Viro8687b632006-10-19 23:28:48 -07004201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 uint32_t supp, acc;
4203 int status;
4204
4205 status = decode_op_hdr(xdr, OP_ACCESS);
4206 if (status)
4207 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004208 p = xdr_inline_decode(xdr, 8);
4209 if (unlikely(!p))
4210 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004211 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004212 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 access->supported = supp;
4214 access->access = acc;
4215 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004216out_overflow:
4217 print_overflow_msg(__func__, xdr);
4218 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219}
4220
Benny Halevy07d30432009-08-14 17:19:52 +03004221static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222{
Al Viro8687b632006-10-19 23:28:48 -07004223 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004224
4225 p = xdr_inline_decode(xdr, len);
4226 if (likely(p)) {
4227 memcpy(buf, p, len);
4228 return 0;
4229 }
4230 print_overflow_msg(__func__, xdr);
4231 return -EIO;
4232}
4233
4234static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4235{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004236 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237}
4238
4239static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4240{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 int status;
4242
4243 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004244 if (status != -EIO)
4245 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004246 if (!status)
4247 status = decode_stateid(xdr, &res->stateid);
4248 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249}
4250
Benny Halevydb942bb2009-08-14 17:19:56 +03004251static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4252{
4253 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
4256static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 int status;
4259
4260 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004261 if (!status)
4262 status = decode_verifier(xdr, res->verf->verifier);
4263 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264}
4265
4266static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4267{
Al Viro8687b632006-10-19 23:28:48 -07004268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 uint32_t bmlen;
4270 int status;
4271
4272 status = decode_op_hdr(xdr, OP_CREATE);
4273 if (status)
4274 return status;
4275 if ((status = decode_change_info(xdr, cinfo)))
4276 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004277 p = xdr_inline_decode(xdr, 4);
4278 if (unlikely(!p))
4279 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004280 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004281 p = xdr_inline_decode(xdr, bmlen << 2);
4282 if (likely(p))
4283 return 0;
4284out_overflow:
4285 print_overflow_msg(__func__, xdr);
4286 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287}
4288
4289static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4290{
Al Viro8687b632006-10-19 23:28:48 -07004291 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004292 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 int status;
4294
4295 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4296 goto xdr_error;
4297 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4298 goto xdr_error;
4299 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4300 goto xdr_error;
4301 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4302 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004303 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4304 &res->fh_expire_type)) != 0)
4305 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4307 goto xdr_error;
4308 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4309 goto xdr_error;
4310 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4311 goto xdr_error;
4312 status = verify_attr_len(xdr, savep, attrlen);
4313xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004314 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 return status;
4316}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004317
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4319{
Al Viro8687b632006-10-19 23:28:48 -07004320 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004321 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004323
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4325 goto xdr_error;
4326 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4327 goto xdr_error;
4328 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4329 goto xdr_error;
4330
4331 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4334 goto xdr_error;
4335 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4338 goto xdr_error;
4339 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4340 goto xdr_error;
4341 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4342 goto xdr_error;
4343
4344 status = verify_attr_len(xdr, savep, attrlen);
4345xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004346 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 return status;
4348}
4349
4350static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4351{
Al Viro8687b632006-10-19 23:28:48 -07004352 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004353 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004355
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4359 goto xdr_error;
4360 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4361 goto xdr_error;
4362
4363 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4364 goto xdr_error;
4365 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4366 goto xdr_error;
4367
4368 status = verify_attr_len(xdr, savep, attrlen);
4369xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004370 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 return status;
4372}
4373
Bryan Schumakerae42c702010-10-21 16:33:17 -04004374static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4375 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004376 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004377 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378{
Trond Myklebustbca79472009-03-11 14:10:26 -04004379 int status;
4380 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004381 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004382 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004384 status = decode_attr_type(xdr, bitmap, &type);
4385 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004387 fattr->mode = 0;
4388 if (status != 0) {
4389 fattr->mode |= nfs_type2fmt[type];
4390 fattr->valid |= status;
4391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004393 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4394 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004396 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004397
4398 status = decode_attr_size(xdr, bitmap, &fattr->size);
4399 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004401 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004402
4403 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4404 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004406 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004407
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004408 err = 0;
4409 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004410 if (status < 0)
4411 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004412 if (err == -NFS4ERR_WRONGSEC)
4413 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004414
4415 status = decode_attr_filehandle(xdr, bitmap, fh);
4416 if (status < 0)
4417 goto xdr_error;
4418
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004419 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4420 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004422 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004423
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004424 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004425 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004426 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004427 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004428
4429 status = decode_attr_mode(xdr, bitmap, &fmode);
4430 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004432 if (status != 0) {
4433 fattr->mode |= fmode;
4434 fattr->valid |= status;
4435 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004436
4437 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4438 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004440 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004441
Trond Myklebust6926afd2012-01-07 13:22:46 -05004442 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004443 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004445 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004446
Trond Myklebust6926afd2012-01-07 13:22:46 -05004447 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004448 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004450 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004451
4452 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4453 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004455 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004456
4457 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4458 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004460 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004461
4462 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4463 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004465 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004466
4467 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4468 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004470 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004471
4472 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4473 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004475 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004476
Trond Myklebust28331a42011-04-27 13:47:52 -04004477 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004478 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004479 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004480 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004481
Bryan Schumakerae42c702010-10-21 16:33:17 -04004482xdr_error:
4483 dprintk("%s: xdr returned %d\n", __func__, -status);
4484 return status;
4485}
4486
4487static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004488 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4489 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004490{
4491 __be32 *savep;
4492 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004493 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004494 int status;
4495
4496 status = decode_op_hdr(xdr, OP_GETATTR);
4497 if (status < 0)
4498 goto xdr_error;
4499
4500 status = decode_attr_bitmap(xdr, bitmap);
4501 if (status < 0)
4502 goto xdr_error;
4503
4504 status = decode_attr_length(xdr, &attrlen, &savep);
4505 if (status < 0)
4506 goto xdr_error;
4507
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004508 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004509 if (status < 0)
4510 goto xdr_error;
4511
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004512 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004514 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 return status;
4516}
4517
Bryan Schumakerae42c702010-10-21 16:33:17 -04004518static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004519 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004520{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004521 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004522}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523
Andy Adamson504913f2010-10-20 00:17:57 -04004524/*
4525 * Decode potentially multiple layout types. Currently we only support
4526 * one layout driver per file system.
4527 */
4528static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4529 uint32_t *layouttype)
4530{
4531 uint32_t *p;
4532 int num;
4533
4534 p = xdr_inline_decode(xdr, 4);
4535 if (unlikely(!p))
4536 goto out_overflow;
4537 num = be32_to_cpup(p);
4538
4539 /* pNFS is not supported by the underlying file system */
4540 if (num == 0) {
4541 *layouttype = 0;
4542 return 0;
4543 }
4544 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004545 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4546 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004547
4548 /* Decode and set first layout type, move xdr->p past unused types */
4549 p = xdr_inline_decode(xdr, num * 4);
4550 if (unlikely(!p))
4551 goto out_overflow;
4552 *layouttype = be32_to_cpup(p);
4553 return 0;
4554out_overflow:
4555 print_overflow_msg(__func__, xdr);
4556 return -EIO;
4557}
4558
4559/*
4560 * The type of file system exported.
4561 * Note we must ensure that layouttype is set in any non-error case.
4562 */
4563static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4564 uint32_t *layouttype)
4565{
4566 int status = 0;
4567
4568 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4569 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4570 return -EIO;
4571 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4572 status = decode_first_pnfs_layout_type(xdr, layouttype);
4573 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4574 } else
4575 *layouttype = 0;
4576 return status;
4577}
4578
Fred Isamandae100c2011-07-30 20:52:37 -04004579/*
4580 * The prefered block size for layout directed io
4581 */
4582static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4583 uint32_t *res)
4584{
4585 __be32 *p;
4586
4587 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4588 *res = 0;
4589 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4590 p = xdr_inline_decode(xdr, 4);
4591 if (unlikely(!p)) {
4592 print_overflow_msg(__func__, xdr);
4593 return -EIO;
4594 }
4595 *res = be32_to_cpup(p);
4596 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4597 }
4598 return 0;
4599}
4600
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4602{
Al Viro8687b632006-10-19 23:28:48 -07004603 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004604 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 int status;
4606
4607 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4608 goto xdr_error;
4609 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4610 goto xdr_error;
4611 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4612 goto xdr_error;
4613
4614 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4615
4616 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4617 goto xdr_error;
4618 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4619 goto xdr_error;
4620 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4621 goto xdr_error;
4622 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4623 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4624 goto xdr_error;
4625 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004626 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4627 if (status != 0)
4628 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004629 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4630 if (status != 0)
4631 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004632 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4633 if (status)
4634 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635
4636 status = verify_attr_len(xdr, savep, attrlen);
4637xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004638 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 return status;
4640}
4641
4642static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4643{
Al Viro8687b632006-10-19 23:28:48 -07004644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 uint32_t len;
4646 int status;
4647
Trond Myklebust99367812007-07-17 21:52:41 -04004648 /* Zero handle first to allow comparisons */
4649 memset(fh, 0, sizeof(*fh));
4650
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 status = decode_op_hdr(xdr, OP_GETFH);
4652 if (status)
4653 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654
Benny Halevyc0eae662009-08-14 17:20:14 +03004655 p = xdr_inline_decode(xdr, 4);
4656 if (unlikely(!p))
4657 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004658 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 if (len > NFS4_FHSIZE)
4660 return -EIO;
4661 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004662 p = xdr_inline_decode(xdr, len);
4663 if (unlikely(!p))
4664 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004665 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004667out_overflow:
4668 print_overflow_msg(__func__, xdr);
4669 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670}
4671
4672static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4673{
4674 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004675
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676 status = decode_op_hdr(xdr, OP_LINK);
4677 if (status)
4678 return status;
4679 return decode_change_info(xdr, cinfo);
4680}
4681
4682/*
4683 * We create the owner, so we know a proper owner.id length is 4.
4684 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004685static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004687 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004688 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004689 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004691 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004692 if (unlikely(!p))
4693 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004694 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004695 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004696 type = be32_to_cpup(p++); /* 4 byte read */
4697 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004698 fl->fl_start = (loff_t)offset;
4699 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4700 if (length == ~(uint64_t)0)
4701 fl->fl_end = OFFSET_MAX;
4702 fl->fl_type = F_WRLCK;
4703 if (type & 1)
4704 fl->fl_type = F_RDLCK;
4705 fl->fl_pid = 0;
4706 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004707 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4708 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4709 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004710 if (likely(p))
4711 return -NFS4ERR_DENIED;
4712out_overflow:
4713 print_overflow_msg(__func__, xdr);
4714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715}
4716
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004717static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 int status;
4720
4721 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004722 if (status == -EIO)
4723 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004725 status = decode_stateid(xdr, &res->stateid);
4726 if (unlikely(status))
4727 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004729 status = decode_lock_denied(xdr, NULL);
4730 if (res->open_seqid != NULL)
4731 nfs_increment_open_seqid(status, res->open_seqid);
4732 nfs_increment_lock_seqid(status, res->lock_seqid);
4733out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 return status;
4735}
4736
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004737static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738{
4739 int status;
4740 status = decode_op_hdr(xdr, OP_LOCKT);
4741 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004742 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743 return status;
4744}
4745
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004746static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 int status;
4749
4750 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004751 if (status != -EIO)
4752 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004753 if (status == 0)
4754 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 return status;
4756}
4757
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004758static int decode_release_lockowner(struct xdr_stream *xdr)
4759{
4760 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4761}
4762
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763static int decode_lookup(struct xdr_stream *xdr)
4764{
4765 return decode_op_hdr(xdr, OP_LOOKUP);
4766}
4767
4768/* This is too sick! */
4769static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4770{
Andy Adamson05d564f2008-12-23 16:06:15 -05004771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 uint32_t limit_type, nblocks, blocksize;
4773
Benny Halevyc0eae662009-08-14 17:20:14 +03004774 p = xdr_inline_decode(xdr, 12);
4775 if (unlikely(!p))
4776 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004777 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004779 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004780 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004781 break;
4782 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004783 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004784 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004785 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 }
4787 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004788out_overflow:
4789 print_overflow_msg(__func__, xdr);
4790 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791}
4792
4793static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4794{
Andy Adamson05d564f2008-12-23 16:06:15 -05004795 __be32 *p;
4796 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004797 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798
Benny Halevyc0eae662009-08-14 17:20:14 +03004799 p = xdr_inline_decode(xdr, 4);
4800 if (unlikely(!p))
4801 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004802 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4804 res->delegation_type = 0;
4805 return 0;
4806 }
Benny Halevy07d30432009-08-14 17:19:52 +03004807 status = decode_stateid(xdr, &res->delegation);
4808 if (unlikely(status))
4809 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004810 p = xdr_inline_decode(xdr, 4);
4811 if (unlikely(!p))
4812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004813 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004814
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004816 case NFS4_OPEN_DELEGATE_READ:
4817 res->delegation_type = FMODE_READ;
4818 break;
4819 case NFS4_OPEN_DELEGATE_WRITE:
4820 res->delegation_type = FMODE_WRITE|FMODE_READ;
4821 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 return -EIO;
4823 }
David Howells7539bba2006-08-22 20:06:09 -04004824 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004825out_overflow:
4826 print_overflow_msg(__func__, xdr);
4827 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828}
4829
4830static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4831{
Andy Adamson05d564f2008-12-23 16:06:15 -05004832 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004833 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004834 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835
Andy Adamson05d564f2008-12-23 16:06:15 -05004836 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004837 if (status != -EIO)
4838 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004839 if (!status)
4840 status = decode_stateid(xdr, &res->stateid);
4841 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004842 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843
Andy Adamson05d564f2008-12-23 16:06:15 -05004844 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Benny Halevyc0eae662009-08-14 17:20:14 +03004846 p = xdr_inline_decode(xdr, 8);
4847 if (unlikely(!p))
4848 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004849 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004850 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004851 if (bmlen > 10)
4852 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
Benny Halevyc0eae662009-08-14 17:20:14 +03004854 p = xdr_inline_decode(xdr, bmlen << 2);
4855 if (unlikely(!p))
4856 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004857 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4858 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004859 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004860 for (; i < NFS4_BITMAP_SIZE; i++)
4861 res->attrset[i] = 0;
4862
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 return decode_delegation(xdr, res);
4864xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004865 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004867out_overflow:
4868 print_overflow_msg(__func__, xdr);
4869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870}
4871
4872static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4873{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 int status;
4875
Andy Adamson05d564f2008-12-23 16:06:15 -05004876 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004877 if (status != -EIO)
4878 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004879 if (!status)
4880 status = decode_stateid(xdr, &res->stateid);
4881 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882}
4883
4884static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 int status;
4887
4888 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004889 if (status != -EIO)
4890 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004891 if (!status)
4892 status = decode_stateid(xdr, &res->stateid);
4893 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894}
4895
4896static int decode_putfh(struct xdr_stream *xdr)
4897{
4898 return decode_op_hdr(xdr, OP_PUTFH);
4899}
4900
4901static int decode_putrootfh(struct xdr_stream *xdr)
4902{
4903 return decode_op_hdr(xdr, OP_PUTROOTFH);
4904}
4905
4906static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4907{
4908 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004909 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 uint32_t count, eof, recvd, hdrlen;
4911 int status;
4912
4913 status = decode_op_hdr(xdr, OP_READ);
4914 if (status)
4915 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004916 p = xdr_inline_decode(xdr, 8);
4917 if (unlikely(!p))
4918 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004919 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004920 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004921 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 recvd = req->rq_rcv_buf.len - hdrlen;
4923 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004924 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 "count %u > recvd %u\n", count, recvd);
4926 count = recvd;
4927 eof = 0;
4928 }
4929 xdr_read_pages(xdr, count);
4930 res->eof = eof;
4931 res->count = count;
4932 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004933out_overflow:
4934 print_overflow_msg(__func__, xdr);
4935 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936}
4937
4938static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4939{
4940 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004942 size_t hdrlen;
4943 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004944 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945
4946 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004947 if (!status)
4948 status = decode_verifier(xdr, readdir->verifier.data);
4949 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004951 dprintk("%s: verifier = %08x:%08x\n",
4952 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004953 ((u32 *)readdir->verifier.data)[0],
4954 ((u32 *)readdir->verifier.data)[1]);
4955
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956
Benny Halevydb942bb2009-08-14 17:19:56 +03004957 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 recvd = rcvbuf->len - hdrlen;
4959 if (pglen > recvd)
4960 pglen = recvd;
4961 xdr_read_pages(xdr, pglen);
4962
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004963
Trond Myklebustac396122010-11-15 20:26:22 -05004964 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965}
4966
4967static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4968{
4969 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4970 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004971 size_t hdrlen;
4972 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004973 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 int status;
4975
4976 status = decode_op_hdr(xdr, OP_READLINK);
4977 if (status)
4978 return status;
4979
4980 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004981 p = xdr_inline_decode(xdr, 4);
4982 if (unlikely(!p))
4983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004984 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004986 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 return -ENAMETOOLONG;
4988 }
4989 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4990 recvd = req->rq_rcv_buf.len - hdrlen;
4991 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004992 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 "count %u > recvd %u\n", len, recvd);
4994 return -EIO;
4995 }
4996 xdr_read_pages(xdr, len);
4997 /*
4998 * The XDR encode routine has set things up so that
4999 * the link text will be copied directly into the
5000 * buffer. We just have to do overflow-checking,
5001 * and and null-terminate the text (the VFS expects
5002 * null-termination).
5003 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005004 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005006out_overflow:
5007 print_overflow_msg(__func__, xdr);
5008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009}
5010
5011static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5012{
5013 int status;
5014
5015 status = decode_op_hdr(xdr, OP_REMOVE);
5016 if (status)
5017 goto out;
5018 status = decode_change_info(xdr, cinfo);
5019out:
5020 return status;
5021}
5022
5023static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5024 struct nfs4_change_info *new_cinfo)
5025{
5026 int status;
5027
5028 status = decode_op_hdr(xdr, OP_RENAME);
5029 if (status)
5030 goto out;
5031 if ((status = decode_change_info(xdr, old_cinfo)))
5032 goto out;
5033 status = decode_change_info(xdr, new_cinfo);
5034out:
5035 return status;
5036}
5037
5038static int decode_renew(struct xdr_stream *xdr)
5039{
5040 return decode_op_hdr(xdr, OP_RENEW);
5041}
5042
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005043static int
5044decode_restorefh(struct xdr_stream *xdr)
5045{
5046 return decode_op_hdr(xdr, OP_RESTOREFH);
5047}
5048
J. Bruce Fields029d1052005-06-22 17:16:22 +00005049static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005050 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005051{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005052 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005053 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005054 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005055 struct kvec *iov = req->rq_rcv_buf.head;
5056 int status;
5057
Andy Adamsonbf118a32011-12-07 11:55:27 -05005058 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005059 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5060 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005061 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005062 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5063 goto out;
5064 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5065 goto out;
5066
5067 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5068 return -EIO;
5069 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005070 size_t hdrlen;
5071 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005072
Andy Adamsonbf118a32011-12-07 11:55:27 -05005073 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5074 * are stored with the acl data to handle the problem of
5075 * variable length bitmaps.*/
5076 xdr->p = bm_p;
5077 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5078 res->acl_data_offset <<= 2;
5079
J. Bruce Fields029d1052005-06-22 17:16:22 +00005080 /* We ignore &savep and don't do consistency checks on
5081 * the attr length. Let userspace figure it out.... */
5082 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005083 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005084 recvd = req->rq_rcv_buf.len - hdrlen;
5085 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005086 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5087 /* getxattr interface called with a NULL buf */
5088 res->acl_len = attrlen;
5089 goto out;
5090 }
5091 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005092 attrlen, recvd);
5093 return -EINVAL;
5094 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005095 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005096 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005097 } else
5098 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005099
5100out:
5101 return status;
5102}
5103
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104static int
5105decode_savefh(struct xdr_stream *xdr)
5106{
5107 return decode_op_hdr(xdr, OP_SAVEFH);
5108}
5109
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005110static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111{
Al Viro8687b632006-10-19 23:28:48 -07005112 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 uint32_t bmlen;
5114 int status;
5115
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 status = decode_op_hdr(xdr, OP_SETATTR);
5117 if (status)
5118 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005119 p = xdr_inline_decode(xdr, 4);
5120 if (unlikely(!p))
5121 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005122 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005123 p = xdr_inline_decode(xdr, bmlen << 2);
5124 if (likely(p))
5125 return 0;
5126out_overflow:
5127 print_overflow_msg(__func__, xdr);
5128 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129}
5130
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005131static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132{
Al Viro8687b632006-10-19 23:28:48 -07005133 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 uint32_t opnum;
5135 int32_t nfserr;
5136
Benny Halevyc0eae662009-08-14 17:20:14 +03005137 p = xdr_inline_decode(xdr, 8);
5138 if (unlikely(!p))
5139 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005140 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005142 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005143 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 return -EIO;
5145 }
Benny Halevycccddf42009-08-14 17:20:19 +03005146 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005148 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5149 if (unlikely(!p))
5150 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005151 p = xdr_decode_hyper(p, &res->clientid);
5152 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 } else if (nfserr == NFSERR_CLID_INUSE) {
5154 uint32_t len;
5155
5156 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005157 p = xdr_inline_decode(xdr, 4);
5158 if (unlikely(!p))
5159 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005160 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005161 p = xdr_inline_decode(xdr, len);
5162 if (unlikely(!p))
5163 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164
5165 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005166 p = xdr_inline_decode(xdr, 4);
5167 if (unlikely(!p))
5168 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005169 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005170 p = xdr_inline_decode(xdr, len);
5171 if (unlikely(!p))
5172 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 return -NFSERR_CLID_INUSE;
5174 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005175 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176
5177 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005178out_overflow:
5179 print_overflow_msg(__func__, xdr);
5180 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181}
5182
5183static int decode_setclientid_confirm(struct xdr_stream *xdr)
5184{
5185 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5186}
5187
5188static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5189{
Al Viro8687b632006-10-19 23:28:48 -07005190 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 int status;
5192
5193 status = decode_op_hdr(xdr, OP_WRITE);
5194 if (status)
5195 return status;
5196
Benny Halevyc0eae662009-08-14 17:20:14 +03005197 p = xdr_inline_decode(xdr, 16);
5198 if (unlikely(!p))
5199 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005200 res->count = be32_to_cpup(p++);
5201 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005202 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005204out_overflow:
5205 print_overflow_msg(__func__, xdr);
5206 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207}
5208
5209static int decode_delegreturn(struct xdr_stream *xdr)
5210{
5211 return decode_op_hdr(xdr, OP_DELEGRETURN);
5212}
5213
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005214static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5215{
5216 __be32 *p;
5217
5218 p = xdr_inline_decode(xdr, 4);
5219 if (unlikely(!p))
5220 goto out_overflow;
5221 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5222 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5223 goto out_err;
5224
5225 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5226 if (unlikely(!p))
5227 goto out_overflow;
5228 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5229
5230 p = xdr_inline_decode(xdr, 8);
5231 if (unlikely(!p))
5232 goto out_overflow;
5233 flavor->gss.qop4 = be32_to_cpup(p++);
5234 flavor->gss.service = be32_to_cpup(p);
5235
5236 return 0;
5237
5238out_overflow:
5239 print_overflow_msg(__func__, xdr);
5240 return -EIO;
5241out_err:
5242 return -EINVAL;
5243}
5244
5245static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5246{
5247 struct nfs4_secinfo_flavor *sec_flavor;
5248 int status;
5249 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005250 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005251
5252 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005253 if (status)
5254 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005255 p = xdr_inline_decode(xdr, 4);
5256 if (unlikely(!p))
5257 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005258
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005259 res->flavors->num_flavors = 0;
5260 num_flavors = be32_to_cpup(p);
5261
5262 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005263 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005264 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005265 break;
5266
5267 p = xdr_inline_decode(xdr, 4);
5268 if (unlikely(!p))
5269 goto out_overflow;
5270 sec_flavor->flavor = be32_to_cpup(p);
5271
5272 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005273 status = decode_secinfo_gss(xdr, sec_flavor);
5274 if (status)
5275 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005276 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005277 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005278 }
5279
Bryan Schumaker613e9012011-04-27 15:28:44 -04005280out:
5281 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005282out_overflow:
5283 print_overflow_msg(__func__, xdr);
5284 return -EIO;
5285}
5286
Benny Halevy99fe60d2009-04-01 09:22:29 -04005287#if defined(CONFIG_NFS_V4_1)
5288static int decode_exchange_id(struct xdr_stream *xdr,
5289 struct nfs41_exchange_id_res *res)
5290{
5291 __be32 *p;
5292 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005293 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005294 int status;
5295 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005296 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005297
5298 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5299 if (status)
5300 return status;
5301
Benny Halevyc0eae662009-08-14 17:20:14 +03005302 p = xdr_inline_decode(xdr, 8);
5303 if (unlikely(!p))
5304 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005305 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005306 p = xdr_inline_decode(xdr, 12);
5307 if (unlikely(!p))
5308 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005309 clp->cl_seqid = be32_to_cpup(p++);
5310 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005311
5312 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005313 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005314 if (dummy != SP4_NONE)
5315 return -EIO;
5316
5317 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005318 p = xdr_inline_decode(xdr, 8);
5319 if (unlikely(!p))
5320 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005321
5322 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005323 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5324 if (unlikely(status))
5325 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005326
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005327 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005328 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5329 if (unlikely(status))
5330 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005331
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005332 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5333 return -EIO;
5334
5335 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5336 res->server_scope->server_scope_sz = dummy;
5337
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005338 /* Implementation Id */
5339 p = xdr_inline_decode(xdr, 4);
5340 if (unlikely(!p))
5341 goto out_overflow;
5342 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005343
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005344 if (impl_id_count) {
5345 /* nii_domain */
5346 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5347 if (unlikely(status))
5348 return status;
5349 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5350 return -EIO;
5351 memcpy(res->impl_id->domain, dummy_str, dummy);
5352
5353 /* nii_name */
5354 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5355 if (unlikely(status))
5356 return status;
5357 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5358 return -EIO;
5359 memcpy(res->impl_id->name, dummy_str, dummy);
5360
5361 /* nii_date */
5362 p = xdr_inline_decode(xdr, 12);
5363 if (unlikely(!p))
5364 goto out_overflow;
5365 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5366 res->impl_id->date.nseconds = be32_to_cpup(p);
5367
5368 /* if there's more than one entry, ignore the rest */
5369 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005370 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005371out_overflow:
5372 print_overflow_msg(__func__, xdr);
5373 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005374}
Andy Adamsonfc931582009-04-01 09:22:31 -04005375
5376static int decode_chan_attrs(struct xdr_stream *xdr,
5377 struct nfs4_channel_attrs *attrs)
5378{
5379 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005380 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005381
Benny Halevyc0eae662009-08-14 17:20:14 +03005382 p = xdr_inline_decode(xdr, 28);
5383 if (unlikely(!p))
5384 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005385 val = be32_to_cpup(p++); /* headerpadsz */
5386 if (val)
5387 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005388 attrs->max_rqst_sz = be32_to_cpup(p++);
5389 attrs->max_resp_sz = be32_to_cpup(p++);
5390 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5391 attrs->max_ops = be32_to_cpup(p++);
5392 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005393 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005394 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005395 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5396 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005397 return -EINVAL;
5398 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005399 if (nr_attrs == 1) {
5400 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5401 if (unlikely(!p))
5402 goto out_overflow;
5403 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005404 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005405out_overflow:
5406 print_overflow_msg(__func__, xdr);
5407 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005408}
5409
Benny Halevye78291e2009-08-14 17:20:00 +03005410static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5411{
5412 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005413}
5414
5415static int decode_create_session(struct xdr_stream *xdr,
5416 struct nfs41_create_session_res *res)
5417{
5418 __be32 *p;
5419 int status;
5420 struct nfs_client *clp = res->client;
5421 struct nfs4_session *session = clp->cl_session;
5422
5423 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005424 if (!status)
5425 status = decode_sessionid(xdr, &session->sess_id);
5426 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005427 return status;
5428
Andy Adamsonfc931582009-04-01 09:22:31 -04005429 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005430 p = xdr_inline_decode(xdr, 8);
5431 if (unlikely(!p))
5432 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005433 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005434 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005435
5436 /* Channel attributes */
5437 status = decode_chan_attrs(xdr, &session->fc_attrs);
5438 if (!status)
5439 status = decode_chan_attrs(xdr, &session->bc_attrs);
5440 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005441out_overflow:
5442 print_overflow_msg(__func__, xdr);
5443 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005444}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005445
5446static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5447{
5448 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5449}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005450
5451static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5452{
5453 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5454}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005455#endif /* CONFIG_NFS_V4_1 */
5456
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005457static int decode_sequence(struct xdr_stream *xdr,
5458 struct nfs4_sequence_res *res,
5459 struct rpc_rqst *rqstp)
5460{
5461#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005462 struct nfs4_sessionid id;
5463 u32 dummy;
5464 int status;
5465 __be32 *p;
5466
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005467 if (!res->sr_session)
5468 return 0;
5469
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005470 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005471 if (!status)
5472 status = decode_sessionid(xdr, &id);
5473 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005474 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005475
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005476 /*
5477 * If the server returns different values for sessionID, slotID or
5478 * sequence number, the server is looney tunes.
5479 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005480 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005481
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005482 if (memcmp(id.data, res->sr_session->sess_id.data,
5483 NFS4_MAX_SESSIONID_LEN)) {
5484 dprintk("%s Invalid session id\n", __func__);
5485 goto out_err;
5486 }
Benny Halevye78291e2009-08-14 17:20:00 +03005487
Benny Halevyc0eae662009-08-14 17:20:14 +03005488 p = xdr_inline_decode(xdr, 20);
5489 if (unlikely(!p))
5490 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005491
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005492 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005493 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005494 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005495 dprintk("%s Invalid sequence number\n", __func__);
5496 goto out_err;
5497 }
5498 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005499 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005500 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005501 dprintk("%s Invalid slot id\n", __func__);
5502 goto out_err;
5503 }
5504 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005505 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005506 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005507 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005508 /* result flags */
5509 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005510 status = 0;
5511out_err:
5512 res->sr_status = status;
5513 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005514out_overflow:
5515 print_overflow_msg(__func__, xdr);
5516 status = -EIO;
5517 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005518#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005519 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005520#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005521}
5522
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005523#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005524/*
5525 * TODO: Need to handle case when EOF != true;
5526 */
5527static int decode_getdevicelist(struct xdr_stream *xdr,
5528 struct pnfs_devicelist *res)
5529{
5530 __be32 *p;
5531 int status, i;
5532 struct nfs_writeverf verftemp;
5533
5534 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5535 if (status)
5536 return status;
5537
5538 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5539 if (unlikely(!p))
5540 goto out_overflow;
5541
5542 /* TODO: Skip cookie for now */
5543 p += 2;
5544
5545 /* Read verifier */
5546 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5547
5548 res->num_devs = be32_to_cpup(p);
5549
5550 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5551
5552 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005553 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005554 __func__, res->num_devs);
5555 return -EIO;
5556 }
5557
5558 p = xdr_inline_decode(xdr,
5559 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5560 if (unlikely(!p))
5561 goto out_overflow;
5562 for (i = 0; i < res->num_devs; i++)
5563 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5564 NFS4_DEVICEID4_SIZE);
5565 res->eof = be32_to_cpup(p);
5566 return 0;
5567out_overflow:
5568 print_overflow_msg(__func__, xdr);
5569 return -EIO;
5570}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005571
5572static int decode_getdeviceinfo(struct xdr_stream *xdr,
5573 struct pnfs_device *pdev)
5574{
5575 __be32 *p;
5576 uint32_t len, type;
5577 int status;
5578
5579 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5580 if (status) {
5581 if (status == -ETOOSMALL) {
5582 p = xdr_inline_decode(xdr, 4);
5583 if (unlikely(!p))
5584 goto out_overflow;
5585 pdev->mincount = be32_to_cpup(p);
5586 dprintk("%s: Min count too small. mincnt = %u\n",
5587 __func__, pdev->mincount);
5588 }
5589 return status;
5590 }
5591
5592 p = xdr_inline_decode(xdr, 8);
5593 if (unlikely(!p))
5594 goto out_overflow;
5595 type = be32_to_cpup(p++);
5596 if (type != pdev->layout_type) {
5597 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5598 __func__, pdev->layout_type, type);
5599 return -EINVAL;
5600 }
5601 /*
5602 * Get the length of the opaque device_addr4. xdr_read_pages places
5603 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5604 * and places the remaining xdr data in xdr_buf->tail
5605 */
5606 pdev->mincount = be32_to_cpup(p);
5607 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5608
5609 /* Parse notification bitmap, verifying that it is zero. */
5610 p = xdr_inline_decode(xdr, 4);
5611 if (unlikely(!p))
5612 goto out_overflow;
5613 len = be32_to_cpup(p);
5614 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005615 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005616
5617 p = xdr_inline_decode(xdr, 4 * len);
5618 if (unlikely(!p))
5619 goto out_overflow;
5620 for (i = 0; i < len; i++, p++) {
5621 if (be32_to_cpup(p)) {
5622 dprintk("%s: notifications not supported\n",
5623 __func__);
5624 return -EIO;
5625 }
5626 }
5627 }
5628 return 0;
5629out_overflow:
5630 print_overflow_msg(__func__, xdr);
5631 return -EIO;
5632}
5633
5634static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5635 struct nfs4_layoutget_res *res)
5636{
5637 __be32 *p;
5638 int status;
5639 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005640 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5641 struct kvec *iov = rcvbuf->head;
5642 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005643
5644 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5645 if (status)
5646 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005647 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005648 if (unlikely(!p))
5649 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005650 res->return_on_close = be32_to_cpup(p);
5651 decode_stateid(xdr, &res->stateid);
5652 p = xdr_inline_decode(xdr, 4);
5653 if (unlikely(!p))
5654 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005655 layout_count = be32_to_cpup(p);
5656 if (!layout_count) {
5657 dprintk("%s: server responded with empty layout array\n",
5658 __func__);
5659 return -EINVAL;
5660 }
5661
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005662 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005663 if (unlikely(!p))
5664 goto out_overflow;
5665 p = xdr_decode_hyper(p, &res->range.offset);
5666 p = xdr_decode_hyper(p, &res->range.length);
5667 res->range.iomode = be32_to_cpup(p++);
5668 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005669 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005670
5671 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5672 __func__,
5673 (unsigned long)res->range.offset,
5674 (unsigned long)res->range.length,
5675 res->range.iomode,
5676 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005677 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005678
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005679 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5680 recvd = req->rq_rcv_buf.len - hdrlen;
5681 if (res->layoutp->len > recvd) {
5682 dprintk("NFS: server cheating in layoutget reply: "
5683 "layout len %u > recvd %u\n",
5684 res->layoutp->len, recvd);
5685 return -EINVAL;
5686 }
5687
5688 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005689
5690 if (layout_count > 1) {
5691 /* We only handle a length one array at the moment. Any
5692 * further entries are just ignored. Note that this means
5693 * the client may see a response that is less than the
5694 * minimum it requested.
5695 */
5696 dprintk("%s: server responded with %d layouts, dropping tail\n",
5697 __func__, layout_count);
5698 }
5699
5700 return 0;
5701out_overflow:
5702 print_overflow_msg(__func__, xdr);
5703 return -EIO;
5704}
Andy Adamson863a3c62011-03-23 13:27:54 +00005705
Benny Halevycbe82602011-05-22 19:52:37 +03005706static int decode_layoutreturn(struct xdr_stream *xdr,
5707 struct nfs4_layoutreturn_res *res)
5708{
5709 __be32 *p;
5710 int status;
5711
5712 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5713 if (status)
5714 return status;
5715 p = xdr_inline_decode(xdr, 4);
5716 if (unlikely(!p))
5717 goto out_overflow;
5718 res->lrs_present = be32_to_cpup(p);
5719 if (res->lrs_present)
5720 status = decode_stateid(xdr, &res->stateid);
5721 return status;
5722out_overflow:
5723 print_overflow_msg(__func__, xdr);
5724 return -EIO;
5725}
5726
Andy Adamson863a3c62011-03-23 13:27:54 +00005727static int decode_layoutcommit(struct xdr_stream *xdr,
5728 struct rpc_rqst *req,
5729 struct nfs4_layoutcommit_res *res)
5730{
5731 __be32 *p;
5732 __u32 sizechanged;
5733 int status;
5734
5735 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005736 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005737 if (status)
5738 return status;
5739
5740 p = xdr_inline_decode(xdr, 4);
5741 if (unlikely(!p))
5742 goto out_overflow;
5743 sizechanged = be32_to_cpup(p);
5744
5745 if (sizechanged) {
5746 /* throw away new size */
5747 p = xdr_inline_decode(xdr, 8);
5748 if (unlikely(!p))
5749 goto out_overflow;
5750 }
5751 return 0;
5752out_overflow:
5753 print_overflow_msg(__func__, xdr);
5754 return -EIO;
5755}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005756
5757static int decode_test_stateid(struct xdr_stream *xdr,
5758 struct nfs41_test_stateid_res *res)
5759{
5760 __be32 *p;
5761 int status;
5762 int num_res;
5763
5764 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5765 if (status)
5766 return status;
5767
5768 p = xdr_inline_decode(xdr, 4);
5769 if (unlikely(!p))
5770 goto out_overflow;
5771 num_res = be32_to_cpup(p++);
5772 if (num_res != 1)
5773 goto out;
5774
5775 p = xdr_inline_decode(xdr, 4);
5776 if (unlikely(!p))
5777 goto out_overflow;
5778 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005779
5780 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005781out_overflow:
5782 print_overflow_msg(__func__, xdr);
5783out:
5784 return -EIO;
5785}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005786
5787static int decode_free_stateid(struct xdr_stream *xdr,
5788 struct nfs41_free_stateid_res *res)
5789{
5790 __be32 *p;
5791 int status;
5792
5793 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5794 if (status)
5795 return status;
5796
5797 p = xdr_inline_decode(xdr, 4);
5798 if (unlikely(!p))
5799 goto out_overflow;
5800 res->status = be32_to_cpup(p++);
5801 return res->status;
5802out_overflow:
5803 print_overflow_msg(__func__, xdr);
5804 return -EIO;
5805}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005806#endif /* CONFIG_NFS_V4_1 */
5807
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808/*
Benny Halevy49c25592008-12-23 16:06:16 -05005809 * END OF "GENERIC" DECODE ROUTINES.
5810 */
5811
5812/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813 * Decode OPEN_DOWNGRADE response
5814 */
Chuck Leverbf269552010-12-14 14:59:29 +00005815static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5816 struct xdr_stream *xdr,
5817 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818{
Andy Adamson05d564f2008-12-23 16:06:15 -05005819 struct compound_hdr hdr;
5820 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005823 if (status)
5824 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005825 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005826 if (status)
5827 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005828 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005829 if (status)
5830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005831 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005832 if (status != 0)
5833 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005834 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005836 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837}
5838
5839/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840 * Decode ACCESS response
5841 */
Chuck Leverbf269552010-12-14 14:59:29 +00005842static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5843 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 struct compound_hdr hdr;
5846 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005847
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005849 if (status)
5850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005852 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005855 if (status != 0)
5856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005857 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005858 if (status != 0)
5859 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005860 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861out:
5862 return status;
5863}
5864
5865/*
5866 * Decode LOOKUP response
5867 */
Chuck Leverbf269552010-12-14 14:59:29 +00005868static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5869 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871 struct compound_hdr hdr;
5872 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005873
Chuck Leverbf269552010-12-14 14:59:29 +00005874 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005875 if (status)
5876 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005877 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005878 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005880 status = decode_putfh(xdr);
5881 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005883 status = decode_lookup(xdr);
5884 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005886 status = decode_getfh(xdr, res->fh);
5887 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005889 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890out:
5891 return status;
5892}
5893
5894/*
5895 * Decode LOOKUP_ROOT response
5896 */
Chuck Leverbf269552010-12-14 14:59:29 +00005897static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5898 struct xdr_stream *xdr,
5899 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901 struct compound_hdr hdr;
5902 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005903
Chuck Leverbf269552010-12-14 14:59:29 +00005904 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005905 if (status)
5906 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005907 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005908 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005910 status = decode_putrootfh(xdr);
5911 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_getfh(xdr, res->fh);
5914 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005915 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916out:
5917 return status;
5918}
5919
5920/*
5921 * Decode REMOVE response
5922 */
Chuck Leverbf269552010-12-14 14:59:29 +00005923static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5924 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 struct compound_hdr hdr;
5927 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005928
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005930 if (status)
5931 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005933 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_putfh(xdr);
5936 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_remove(xdr, &res->cinfo);
5939 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005940 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005941 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942out:
5943 return status;
5944}
5945
5946/*
5947 * Decode RENAME response
5948 */
Chuck Leverbf269552010-12-14 14:59:29 +00005949static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5950 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952 struct compound_hdr hdr;
5953 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005954
Chuck Leverbf269552010-12-14 14:59:29 +00005955 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005956 if (status)
5957 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005959 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_putfh(xdr);
5962 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005964 status = decode_savefh(xdr);
5965 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_putfh(xdr);
5968 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005970 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5971 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005972 goto out;
5973 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005974 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005975 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005976 status = decode_restorefh(xdr);
5977 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005978 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005979 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980out:
5981 return status;
5982}
5983
5984/*
5985 * Decode LINK response
5986 */
Chuck Leverbf269552010-12-14 14:59:29 +00005987static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5988 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 struct compound_hdr hdr;
5991 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005992
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005994 if (status)
5995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005997 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_putfh(xdr);
6000 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006002 status = decode_savefh(xdr);
6003 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_putfh(xdr);
6006 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_link(xdr, &res->cinfo);
6009 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006010 goto out;
6011 /*
6012 * Note order: OP_LINK leaves the directory as the current
6013 * filehandle.
6014 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006015 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_restorefh(xdr);
6018 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006019 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006020 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021out:
6022 return status;
6023}
6024
6025/*
6026 * Decode CREATE response
6027 */
Chuck Leverbf269552010-12-14 14:59:29 +00006028static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6029 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 struct compound_hdr hdr;
6032 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006033
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006035 if (status)
6036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006038 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_putfh(xdr);
6041 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_savefh(xdr);
6044 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006045 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_create(xdr, &res->dir_cinfo);
6047 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_getfh(xdr, res->fh);
6050 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006052 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006053 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_restorefh(xdr);
6055 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006056 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006057 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058out:
6059 return status;
6060}
6061
6062/*
6063 * Decode SYMLINK response
6064 */
Chuck Leverbf269552010-12-14 14:59:29 +00006065static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6066 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067{
Chuck Leverbf269552010-12-14 14:59:29 +00006068 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069}
6070
6071/*
6072 * Decode GETATTR response
6073 */
Chuck Leverbf269552010-12-14 14:59:29 +00006074static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6075 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 struct compound_hdr hdr;
6078 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006079
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 if (status)
6082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006084 if (status)
6085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 if (status)
6088 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006089 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090out:
6091 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092}
6093
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006094/*
6095 * Encode an SETACL request
6096 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006097static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6098 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006099{
Andy Adamson05d564f2008-12-23 16:06:15 -05006100 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006101 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006102 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006103
Chuck Lever9f06c712010-12-14 14:59:18 +00006104 encode_compound_hdr(xdr, req, &hdr);
6105 encode_sequence(xdr, &args->seq_args, &hdr);
6106 encode_putfh(xdr, args->fh, &hdr);
6107 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006108 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006109}
Andy Adamson05d564f2008-12-23 16:06:15 -05006110
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006111/*
6112 * Decode SETACL response
6113 */
6114static int
Chuck Leverbf269552010-12-14 14:59:29 +00006115nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006116 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006117{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006118 struct compound_hdr hdr;
6119 int status;
6120
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006122 if (status)
6123 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006125 if (status)
6126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006128 if (status)
6129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006131out:
6132 return status;
6133}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134
6135/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006136 * Decode GETACL response
6137 */
6138static int
Chuck Leverbf269552010-12-14 14:59:29 +00006139nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006140 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006141{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006142 struct compound_hdr hdr;
6143 int status;
6144
Trond Myklebust331818f2012-02-03 18:30:53 -05006145 if (res->acl_scratch != NULL) {
6146 void *p = page_address(res->acl_scratch);
6147 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6148 }
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006150 if (status)
6151 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006152 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006153 if (status)
6154 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006156 if (status)
6157 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006158 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006159
6160out:
6161 return status;
6162}
6163
6164/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165 * Decode CLOSE response
6166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6168 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169{
Andy Adamson05d564f2008-12-23 16:06:15 -05006170 struct compound_hdr hdr;
6171 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006174 if (status)
6175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006177 if (status)
6178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006180 if (status)
6181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006183 if (status != 0)
6184 goto out;
6185 /*
6186 * Note: Server may do delete on close for this file
6187 * in which case the getattr call will fail with
6188 * an ESTALE error. Shouldn't be a problem,
6189 * though, since fattr->valid will remain unset.
6190 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006191 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006193 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194}
6195
6196/*
6197 * Decode OPEN response
6198 */
Chuck Leverbf269552010-12-14 14:59:29 +00006199static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6200 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201{
Andy Adamson05d564f2008-12-23 16:06:15 -05006202 struct compound_hdr hdr;
6203 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006206 if (status)
6207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006209 if (status)
6210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006212 if (status)
6213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006215 if (status)
6216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006218 if (status)
6219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006220 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006222 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006224 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006225 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006226 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006228 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229}
6230
6231/*
6232 * Decode OPEN_CONFIRM response
6233 */
Chuck Leverbf269552010-12-14 14:59:29 +00006234static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6235 struct xdr_stream *xdr,
6236 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237{
Andy Adamson05d564f2008-12-23 16:06:15 -05006238 struct compound_hdr hdr;
6239 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006242 if (status)
6243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006245 if (status)
6246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006249 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250}
6251
6252/*
6253 * Decode OPEN response
6254 */
Chuck Leverbf269552010-12-14 14:59:29 +00006255static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6256 struct xdr_stream *xdr,
6257 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258{
Andy Adamson05d564f2008-12-23 16:06:15 -05006259 struct compound_hdr hdr;
6260 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006263 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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006269 if (status)
6270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006272 if (status)
6273 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006274 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006276 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277}
6278
6279/*
6280 * Decode SETATTR response
6281 */
Chuck Leverbf269552010-12-14 14:59:29 +00006282static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6283 struct xdr_stream *xdr,
6284 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285{
Andy Adamson05d564f2008-12-23 16:06:15 -05006286 struct compound_hdr hdr;
6287 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006290 if (status)
6291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006293 if (status)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006296 if (status)
6297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006299 if (status)
6300 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006301 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006303 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304}
6305
6306/*
6307 * Decode LOCK response
6308 */
Chuck Leverbf269552010-12-14 14:59:29 +00006309static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6310 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 struct compound_hdr hdr;
6313 int status;
6314
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 if (status)
6317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006319 if (status)
6320 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006321 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 if (status)
6323 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325out:
6326 return status;
6327}
6328
6329/*
6330 * Decode LOCKT response
6331 */
Chuck Leverbf269552010-12-14 14:59:29 +00006332static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6333 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 struct compound_hdr hdr;
6336 int status;
6337
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 if (status)
6340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006342 if (status)
6343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 if (status)
6346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348out:
6349 return status;
6350}
6351
6352/*
6353 * Decode LOCKU response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
6360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371out:
6372 return status;
6373}
6374
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6376 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006377{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006378 struct compound_hdr hdr;
6379 int status;
6380
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006382 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006384 return status;
6385}
6386
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387/*
6388 * Decode READLINK response
6389 */
Chuck Leverbf269552010-12-14 14:59:29 +00006390static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6391 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006392 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394 struct compound_hdr hdr;
6395 int status;
6396
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 if (status)
6399 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006400 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006401 if (status)
6402 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 if (status)
6405 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407out:
6408 return status;
6409}
6410
6411/*
6412 * Decode READDIR response
6413 */
Chuck Leverbf269552010-12-14 14:59:29 +00006414static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6415 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417 struct compound_hdr hdr;
6418 int status;
6419
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006424 if (status)
6425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006426 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 if (status)
6428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430out:
6431 return status;
6432}
6433
6434/*
6435 * Decode Read response
6436 */
Chuck Leverbf269552010-12-14 14:59:29 +00006437static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6438 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 struct compound_hdr hdr;
6441 int status;
6442
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 if (status)
6445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006447 if (status)
6448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 if (status)
6451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 if (!status)
6454 status = res->count;
6455out:
6456 return status;
6457}
6458
6459/*
6460 * Decode WRITE response
6461 */
Chuck Leverbf269552010-12-14 14:59:29 +00006462static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6463 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 struct compound_hdr hdr;
6466 int status;
6467
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 if (status)
6476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006478 if (status)
6479 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006480 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006481 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 if (!status)
6483 status = res->count;
6484out:
6485 return status;
6486}
6487
6488/*
6489 * Decode COMMIT response
6490 */
Chuck Leverbf269552010-12-14 14:59:29 +00006491static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6492 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494 struct compound_hdr hdr;
6495 int status;
6496
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 if (status)
6499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006501 if (status)
6502 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504 if (status)
6505 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006507 if (status)
6508 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006509 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006510 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511out:
6512 return status;
6513}
6514
6515/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006516 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 */
Chuck Leverbf269552010-12-14 14:59:29 +00006518static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006519 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 struct compound_hdr hdr;
6522 int status;
6523
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006527 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531 return status;
6532}
6533
6534/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006535 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 */
Chuck Leverbf269552010-12-14 14:59:29 +00006537static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006538 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 struct compound_hdr hdr;
6541 int status;
6542
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006546 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 return status;
6551}
6552
6553/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006554 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 */
Chuck Leverbf269552010-12-14 14:59:29 +00006556static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006557 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 struct compound_hdr hdr;
6560 int status;
6561
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006565 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 return status;
6570}
6571
6572/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006573 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 */
Chuck Leverbf269552010-12-14 14:59:29 +00006575static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6576 struct xdr_stream *xdr,
6577 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 struct compound_hdr hdr;
6580 int status;
6581
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006583 if (status)
6584 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006586 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_putfh(xdr);
6589 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006592out:
6593 return status;
6594}
6595
6596/*
6597 * Decode RENEW response
6598 */
Chuck Leverbf269552010-12-14 14:59:29 +00006599static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6600 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 struct compound_hdr hdr;
6603 int status;
6604
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 return status;
6609}
6610
6611/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006612 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 */
Chuck Leverbf269552010-12-14 14:59:29 +00006614static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6615 struct xdr_stream *xdr,
6616 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 struct compound_hdr hdr;
6619 int status;
6620
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 return status;
6625}
6626
6627/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006628 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 */
Chuck Leverbf269552010-12-14 14:59:29 +00006630static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6631 struct xdr_stream *xdr,
6632 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 struct compound_hdr hdr;
6635 int status;
6636
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 return status;
6645}
6646
6647/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006648 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 */
Chuck Leverbf269552010-12-14 14:59:29 +00006650static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6651 struct xdr_stream *xdr,
6652 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654 struct compound_hdr hdr;
6655 int status;
6656
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006658 if (status)
6659 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006661 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006662 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006664 if (status != 0)
6665 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006667 if (status != 0)
6668 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006669 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006670out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 return status;
6672}
6673
Trond Myklebust683b57b2006-06-09 09:34:22 -04006674/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006675 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006676 */
Chuck Leverbf269552010-12-14 14:59:29 +00006677static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6678 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006679 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006680{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006681 struct compound_hdr hdr;
6682 int status;
6683
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006685 if (status)
6686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006688 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_putfh(xdr);
6691 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_lookup(xdr);
6694 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006697 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6698 NULL, res->fs_locations,
6699 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006700out:
6701 return status;
6702}
6703
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006704/*
6705 * Decode SECINFO response
6706 */
6707static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6708 struct xdr_stream *xdr,
6709 struct nfs4_secinfo_res *res)
6710{
6711 struct compound_hdr hdr;
6712 int status;
6713
6714 status = decode_compound_hdr(xdr, &hdr);
6715 if (status)
6716 goto out;
6717 status = decode_sequence(xdr, &res->seq_res, rqstp);
6718 if (status)
6719 goto out;
6720 status = decode_putfh(xdr);
6721 if (status)
6722 goto out;
6723 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006724out:
6725 return status;
6726}
6727
Benny Halevy99fe60d2009-04-01 09:22:29 -04006728#if defined(CONFIG_NFS_V4_1)
6729/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006730 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006731 */
Chuck Leverbf269552010-12-14 14:59:29 +00006732static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6733 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006734 void *res)
6735{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006736 struct compound_hdr hdr;
6737 int status;
6738
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006740 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006742 return status;
6743}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006744
6745/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006746 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006747 */
Chuck Leverbf269552010-12-14 14:59:29 +00006748static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6749 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006750 struct nfs41_create_session_res *res)
6751{
Andy Adamsonfc931582009-04-01 09:22:31 -04006752 struct compound_hdr hdr;
6753 int status;
6754
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006756 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006758 return status;
6759}
6760
6761/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006762 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006763 */
Chuck Leverbf269552010-12-14 14:59:29 +00006764static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6765 struct xdr_stream *xdr,
6766 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006767{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006768 struct compound_hdr hdr;
6769 int status;
6770
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006772 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006774 return status;
6775}
6776
6777/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006778 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006779 */
Chuck Leverbf269552010-12-14 14:59:29 +00006780static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6781 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006782 struct nfs4_sequence_res *res)
6783{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006784 struct compound_hdr hdr;
6785 int status;
6786
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006788 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006789 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006790 return status;
6791}
6792
6793/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006794 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006795 */
Chuck Leverbf269552010-12-14 14:59:29 +00006796static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6797 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006798 struct nfs4_get_lease_time_res *res)
6799{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006800 struct compound_hdr hdr;
6801 int status;
6802
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006804 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006806 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006808 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006809 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006810 return status;
6811}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006812
6813/*
6814 * Decode RECLAIM_COMPLETE response
6815 */
Chuck Leverbf269552010-12-14 14:59:29 +00006816static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6817 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006818 struct nfs41_reclaim_complete_res *res)
6819{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006820 struct compound_hdr hdr;
6821 int status;
6822
Chuck Leverbf269552010-12-14 14:59:29 +00006823 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006824 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006825 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006826 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006828 return status;
6829}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006830
6831/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006832 * Decode GETDEVICELIST response
6833 */
6834static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6835 struct xdr_stream *xdr,
6836 struct nfs4_getdevicelist_res *res)
6837{
6838 struct compound_hdr hdr;
6839 int status;
6840
6841 dprintk("encoding getdevicelist!\n");
6842
6843 status = decode_compound_hdr(xdr, &hdr);
6844 if (status != 0)
6845 goto out;
6846 status = decode_sequence(xdr, &res->seq_res, rqstp);
6847 if (status != 0)
6848 goto out;
6849 status = decode_putfh(xdr);
6850 if (status != 0)
6851 goto out;
6852 status = decode_getdevicelist(xdr, res->devlist);
6853out:
6854 return status;
6855}
6856
6857/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006858 * Decode GETDEVINFO response
6859 */
Chuck Leverbf269552010-12-14 14:59:29 +00006860static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6861 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006862 struct nfs4_getdeviceinfo_res *res)
6863{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006864 struct compound_hdr hdr;
6865 int status;
6866
Chuck Leverbf269552010-12-14 14:59:29 +00006867 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006868 if (status != 0)
6869 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006870 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006871 if (status != 0)
6872 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006873 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006874out:
6875 return status;
6876}
6877
6878/*
6879 * Decode LAYOUTGET response
6880 */
Chuck Leverbf269552010-12-14 14:59:29 +00006881static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6882 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006883 struct nfs4_layoutget_res *res)
6884{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006885 struct compound_hdr hdr;
6886 int status;
6887
Chuck Leverbf269552010-12-14 14:59:29 +00006888 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006889 if (status)
6890 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006891 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006892 if (status)
6893 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006894 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006895 if (status)
6896 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006897 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006898out:
6899 return status;
6900}
Andy Adamson863a3c62011-03-23 13:27:54 +00006901
6902/*
Benny Halevycbe82602011-05-22 19:52:37 +03006903 * Decode LAYOUTRETURN response
6904 */
6905static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6906 struct xdr_stream *xdr,
6907 struct nfs4_layoutreturn_res *res)
6908{
6909 struct compound_hdr hdr;
6910 int status;
6911
6912 status = decode_compound_hdr(xdr, &hdr);
6913 if (status)
6914 goto out;
6915 status = decode_sequence(xdr, &res->seq_res, rqstp);
6916 if (status)
6917 goto out;
6918 status = decode_putfh(xdr);
6919 if (status)
6920 goto out;
6921 status = decode_layoutreturn(xdr, res);
6922out:
6923 return status;
6924}
6925
6926/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006927 * Decode LAYOUTCOMMIT response
6928 */
6929static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6930 struct xdr_stream *xdr,
6931 struct nfs4_layoutcommit_res *res)
6932{
6933 struct compound_hdr hdr;
6934 int status;
6935
6936 status = decode_compound_hdr(xdr, &hdr);
6937 if (status)
6938 goto out;
6939 status = decode_sequence(xdr, &res->seq_res, rqstp);
6940 if (status)
6941 goto out;
6942 status = decode_putfh(xdr);
6943 if (status)
6944 goto out;
6945 status = decode_layoutcommit(xdr, rqstp, res);
6946 if (status)
6947 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006948 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006949out:
6950 return status;
6951}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006952
6953/*
6954 * Decode SECINFO_NO_NAME response
6955 */
6956static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6957 struct xdr_stream *xdr,
6958 struct nfs4_secinfo_res *res)
6959{
6960 struct compound_hdr hdr;
6961 int status;
6962
6963 status = decode_compound_hdr(xdr, &hdr);
6964 if (status)
6965 goto out;
6966 status = decode_sequence(xdr, &res->seq_res, rqstp);
6967 if (status)
6968 goto out;
6969 status = decode_putrootfh(xdr);
6970 if (status)
6971 goto out;
6972 status = decode_secinfo(xdr, res);
6973out:
6974 return status;
6975}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006976
6977/*
6978 * Decode TEST_STATEID response
6979 */
6980static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6981 struct xdr_stream *xdr,
6982 struct nfs41_test_stateid_res *res)
6983{
6984 struct compound_hdr hdr;
6985 int status;
6986
6987 status = decode_compound_hdr(xdr, &hdr);
6988 if (status)
6989 goto out;
6990 status = decode_sequence(xdr, &res->seq_res, rqstp);
6991 if (status)
6992 goto out;
6993 status = decode_test_stateid(xdr, res);
6994out:
6995 return status;
6996}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006997
6998/*
6999 * Decode FREE_STATEID response
7000 */
7001static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7002 struct xdr_stream *xdr,
7003 struct nfs41_free_stateid_res *res)
7004{
7005 struct compound_hdr hdr;
7006 int status;
7007
7008 status = decode_compound_hdr(xdr, &hdr);
7009 if (status)
7010 goto out;
7011 status = decode_sequence(xdr, &res->seq_res, rqstp);
7012 if (status)
7013 goto out;
7014 status = decode_free_stateid(xdr, res);
7015out:
7016 return status;
7017}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007018#endif /* CONFIG_NFS_V4_1 */
7019
Chuck Lever573c4e12010-12-14 14:58:11 +00007020/**
7021 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7022 * the local page cache.
7023 * @xdr: XDR stream where entry resides
7024 * @entry: buffer to fill in with entry data
7025 * @plus: boolean indicating whether this should be a readdirplus entry
7026 *
7027 * Returns zero if successful, otherwise a negative errno value is
7028 * returned.
7029 *
7030 * This function is not invoked during READDIR reply decoding, but
7031 * rather whenever an application invokes the getdents(2) system call
7032 * on a directory already in our cache.
7033 */
7034int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7035 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036{
Fred Isamandae100c2011-07-30 20:52:37 -04007037 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007039 __be32 *p = xdr_inline_decode(xdr, 4);
7040 if (unlikely(!p))
7041 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007042 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007043 p = xdr_inline_decode(xdr, 4);
7044 if (unlikely(!p))
7045 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007046 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007047 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007049 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007050 }
7051
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007052 p = xdr_inline_decode(xdr, 12);
7053 if (unlikely(!p))
7054 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007055 entry->prev_cookie = entry->cookie;
7056 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007057 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007058
Trond Myklebust9af8c222010-10-24 11:52:55 -04007059 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007060 if (unlikely(!p))
7061 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007062 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007063
7064 /*
7065 * In case the server doesn't return an inode number,
7066 * we fake one here. (We don't use inode number 0,
7067 * since glibc seems to choke on it...)
7068 */
7069 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007070 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071
Trond Myklebust9af8c222010-10-24 11:52:55 -04007072 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007073 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007074
7075 if (decode_attr_length(xdr, &len, &p) < 0)
7076 goto out_overflow;
7077
Chuck Lever573c4e12010-12-14 14:58:11 +00007078 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007079 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007080 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007081 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7082 entry->ino = entry->fattr->mounted_on_fileid;
7083 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007084 entry->ino = entry->fattr->fileid;
7085
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007086 entry->d_type = DT_UNKNOWN;
7087 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7088 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7089
Chuck Lever573c4e12010-12-14 14:58:11 +00007090 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007091
7092out_overflow:
7093 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007094 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095}
7096
7097/*
7098 * We need to translate between nfs status return values and
7099 * the local errno values which may not be the same.
7100 */
7101static struct {
7102 int stat;
7103 int errno;
7104} nfs_errtbl[] = {
7105 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007106 { NFS4ERR_PERM, -EPERM },
7107 { NFS4ERR_NOENT, -ENOENT },
7108 { NFS4ERR_IO, -errno_NFSERR_IO},
7109 { NFS4ERR_NXIO, -ENXIO },
7110 { NFS4ERR_ACCESS, -EACCES },
7111 { NFS4ERR_EXIST, -EEXIST },
7112 { NFS4ERR_XDEV, -EXDEV },
7113 { NFS4ERR_NOTDIR, -ENOTDIR },
7114 { NFS4ERR_ISDIR, -EISDIR },
7115 { NFS4ERR_INVAL, -EINVAL },
7116 { NFS4ERR_FBIG, -EFBIG },
7117 { NFS4ERR_NOSPC, -ENOSPC },
7118 { NFS4ERR_ROFS, -EROFS },
7119 { NFS4ERR_MLINK, -EMLINK },
7120 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7121 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7122 { NFS4ERR_DQUOT, -EDQUOT },
7123 { NFS4ERR_STALE, -ESTALE },
7124 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007125 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7126 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7127 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007128 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007129 { NFS4ERR_BADTYPE, -EBADTYPE },
7130 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007131 { NFS4ERR_SYMLINK, -ELOOP },
7132 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7133 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007134 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007135};
7136
7137/*
7138 * Convert an NFS error code to a local one.
7139 * This one is used jointly by NFSv2 and NFSv3.
7140 */
7141static int
David Howells0a8ea432006-08-22 20:06:08 -04007142nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007143{
7144 int i;
7145 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7146 if (nfs_errtbl[i].stat == stat)
7147 return nfs_errtbl[i].errno;
7148 }
7149 if (stat <= 10000 || stat > 10100) {
7150 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007151 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007152 }
7153 /* If we cannot translate the error, the recovery routines should
7154 * handle it.
7155 * Note: remaining NFSv4 error codes have values > 10000, so should
7156 * not conflict with native Linux error codes.
7157 */
Benny Halevy856dff32008-03-31 17:39:06 +03007158 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007159}
7160
Linus Torvalds1da177e2005-04-16 15:20:36 -07007161#define PROC(proc, argtype, restype) \
7162[NFSPROC4_CLNT_##proc] = { \
7163 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007164 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007165 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007166 .p_arglen = NFS4_##argtype##_sz, \
7167 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007168 .p_statidx = NFSPROC4_CLNT_##proc, \
7169 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007171
7172struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007173 PROC(READ, enc_read, dec_read),
7174 PROC(WRITE, enc_write, dec_write),
7175 PROC(COMMIT, enc_commit, dec_commit),
7176 PROC(OPEN, enc_open, dec_open),
7177 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7178 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7179 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7180 PROC(CLOSE, enc_close, dec_close),
7181 PROC(SETATTR, enc_setattr, dec_setattr),
7182 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7183 PROC(RENEW, enc_renew, dec_renew),
7184 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7185 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7186 PROC(LOCK, enc_lock, dec_lock),
7187 PROC(LOCKT, enc_lockt, dec_lockt),
7188 PROC(LOCKU, enc_locku, dec_locku),
7189 PROC(ACCESS, enc_access, dec_access),
7190 PROC(GETATTR, enc_getattr, dec_getattr),
7191 PROC(LOOKUP, enc_lookup, dec_lookup),
7192 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7193 PROC(REMOVE, enc_remove, dec_remove),
7194 PROC(RENAME, enc_rename, dec_rename),
7195 PROC(LINK, enc_link, dec_link),
7196 PROC(SYMLINK, enc_symlink, dec_symlink),
7197 PROC(CREATE, enc_create, dec_create),
7198 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7199 PROC(STATFS, enc_statfs, dec_statfs),
7200 PROC(READLINK, enc_readlink, dec_readlink),
7201 PROC(READDIR, enc_readdir, dec_readdir),
7202 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7203 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7204 PROC(GETACL, enc_getacl, dec_getacl),
7205 PROC(SETACL, enc_setacl, dec_setacl),
7206 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7207 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007208 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007209#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007210 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7211 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7212 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7213 PROC(SEQUENCE, enc_sequence, dec_sequence),
7214 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7215 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7216 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7217 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007218 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007219 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007220 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007221 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007222 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007223 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007224#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007225};
7226
Trond Myklebusta613fa12012-01-20 13:53:56 -05007227const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007228 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007229 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007230 .procs = nfs4_procedures
7231};
7232
7233/*
7234 * Local variables:
7235 * c-basic-offset: 8
7236 * End:
7237 */