blob: 4ea9f50a32f2063ec3ea63a3530be648596dd528 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Trond Myklebustcb17e552012-03-04 18:13:56 -0500888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500900 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 xdr_encode_opaque(p, str, len);
902}
903
Trond Myklebust4ade9822012-03-04 18:13:57 -0500904static void encode_uint32(struct xdr_stream *xdr, u32 n)
905{
906 __be32 *p;
907
908 p = reserve_space(xdr, 4);
909 *p = cpu_to_be32(n);
910}
911
912static void encode_nfs4_seqid(struct xdr_stream *xdr,
913 const struct nfs_seqid *seqid)
914{
915 encode_uint32(xdr, seqid->sequence->counter);
916}
917
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400918static void encode_compound_hdr(struct xdr_stream *xdr,
919 struct rpc_rqst *req,
920 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400923 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400924
925 /* initialize running count of expected bytes in reply.
926 * NOTE: the replied tag SHOULD be the same is the one sent,
927 * but this is not required as a MUST for the server to do so. */
928 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500931 encode_string(xdr, hdr->taglen, hdr->tag);
932 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300933 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500934 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300935 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500936}
937
Trond Myklebustab19b482012-03-04 18:13:57 -0500938static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
939 uint32_t replen,
940 struct compound_hdr *hdr)
941{
942 encode_uint32(xdr, op);
943 hdr->nops++;
944 hdr->replen += replen;
945}
946
Andy Adamsond0179312008-12-23 16:06:17 -0500947static void encode_nops(struct compound_hdr *hdr)
948{
Andy Adamsonfc931582009-04-01 09:22:31 -0400949 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500950 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500953static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
954{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500955 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500956}
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
959{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500960 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500963static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
965 char owner_name[IDMAP_NAMESZ];
966 char owner_group[IDMAP_NAMESZ];
967 int owner_namelen = 0;
968 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700969 __be32 *p;
970 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 int len;
972 uint32_t bmval0 = 0;
973 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /*
976 * We reserve enough space to write the entire attribute buffer at once.
977 * In the worst-case, this would be
978 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
979 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000980 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 */
982 len = 16;
983
984 /* Sigh */
985 if (iap->ia_valid & ATTR_SIZE)
986 len += 8;
987 if (iap->ia_valid & ATTR_MODE)
988 len += 4;
989 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800990 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400992 dprintk("nfs: couldn't resolve uid %d to string\n",
993 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 /* XXX */
995 strcpy(owner_name, "nobody");
996 owner_namelen = sizeof("nobody") - 1;
997 /* goto out; */
998 }
999 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1000 }
1001 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001002 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001004 dprintk("nfs: couldn't resolve gid %d to string\n",
1005 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 strcpy(owner_group, "nobody");
1007 owner_grouplen = sizeof("nobody") - 1;
1008 /* goto out; */
1009 }
1010 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1011 }
1012 if (iap->ia_valid & ATTR_ATIME_SET)
1013 len += 16;
1014 else if (iap->ia_valid & ATTR_ATIME)
1015 len += 4;
1016 if (iap->ia_valid & ATTR_MTIME_SET)
1017 len += 16;
1018 else if (iap->ia_valid & ATTR_MTIME)
1019 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001020 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 /*
1023 * We write the bitmap length now, but leave the bitmap and the attribute
1024 * buffer length to be backfilled at the end of this routine.
1025 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001026 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 q = p;
1028 p += 3;
1029
1030 if (iap->ia_valid & ATTR_SIZE) {
1031 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001032 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 if (iap->ia_valid & ATTR_MODE) {
1035 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001036 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038 if (iap->ia_valid & ATTR_UID) {
1039 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001040 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 if (iap->ia_valid & ATTR_GID) {
1043 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001044 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_ATIME_SET) {
1047 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1049 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001050 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1051 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
1053 else if (iap->ia_valid & ATTR_ATIME) {
1054 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
1057 if (iap->ia_valid & ATTR_MTIME_SET) {
1058 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001059 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1060 *p++ = cpu_to_be32(0);
1061 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1062 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064 else if (iap->ia_valid & ATTR_MTIME) {
1065 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001066 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 /*
1070 * Now we backfill the bitmap and the attribute buffer length.
1071 */
1072 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001073 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 len, ((char *)p - (char *)q) + 4);
1075 BUG();
1076 }
1077 len = (char *)p - (char *)q - 12;
1078 *q++ = htonl(bmval0);
1079 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001080 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001087 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1088 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089}
1090
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001091static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
Trond Myklebustab19b482012-03-04 18:13:57 -05001093 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001094 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001095 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001098static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Al Viro8687b632006-10-19 23:28:48 -07001100 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001101
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001102 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1103 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001104 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001105 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001108static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Al Viro8687b632006-10-19 23:28:48 -07001110 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001111
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001112 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1113 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 switch (create->ftype) {
1116 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001117 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001118 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001119 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 break;
1121
1122 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001123 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001124 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001125 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 break;
1127
1128 default:
1129 break;
1130 }
1131
Benny Halevy811652b2009-08-14 17:19:34 +03001132 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001133 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001136static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
Andy Adamson05d564f2008-12-23 16:06:15 -05001138 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001140 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1141 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001142 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001143 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001146static 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 -07001147{
Andy Adamson05d564f2008-12-23 16:06:15 -05001148 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001150 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1151 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001152 *p++ = cpu_to_be32(2);
1153 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001154 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155}
1156
Fred Isamandae100c2011-07-30 20:52:37 -04001157static void
1158encode_getattr_three(struct xdr_stream *xdr,
1159 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1160 struct compound_hdr *hdr)
1161{
1162 __be32 *p;
1163
Trond Myklebustab19b482012-03-04 18:13:57 -05001164 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001165 if (bm2) {
1166 p = reserve_space(xdr, 16);
1167 *p++ = cpu_to_be32(3);
1168 *p++ = cpu_to_be32(bm0);
1169 *p++ = cpu_to_be32(bm1);
1170 *p = cpu_to_be32(bm2);
1171 } else if (bm1) {
1172 p = reserve_space(xdr, 12);
1173 *p++ = cpu_to_be32(2);
1174 *p++ = cpu_to_be32(bm0);
1175 *p = cpu_to_be32(bm1);
1176 } else {
1177 p = reserve_space(xdr, 8);
1178 *p++ = cpu_to_be32(1);
1179 *p = cpu_to_be32(bm0);
1180 }
Fred Isamandae100c2011-07-30 20:52:37 -04001181}
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{
Trond Myklebustab19b482012-03-04 18:13:57 -05001206 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001209static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210{
Trond Myklebustab19b482012-03-04 18:13:57 -05001211 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001212 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001215static inline int nfs4_lock_type(struct file_lock *fl, int block)
1216{
1217 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1218 return block ? NFS4_READW_LT : NFS4_READ_LT;
1219 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1220}
1221
1222static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1223{
1224 if (fl->fl_end == OFFSET_MAX)
1225 return ~(uint64_t)0;
1226 return fl->fl_end - fl->fl_start + 1;
1227}
1228
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001229static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1230{
1231 __be32 *p;
1232
Trond Myklebustd035c362010-12-21 10:45:27 -05001233 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001234 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001235 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001236 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001237 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001238 xdr_encode_hyper(p, lowner->id);
1239}
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241/*
1242 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1243 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1244 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001245static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Al Viro8687b632006-10-19 23:28:48 -07001247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001249 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1250 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001251 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1252 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001253 p = xdr_encode_hyper(p, args->fl->fl_start);
1254 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001255 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001256 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001257 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001258 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001259 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001260 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
1262 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001263 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001264 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001272 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1273 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001274 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001275 p = xdr_encode_hyper(p, args->fl->fl_start);
1276 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001277 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001280static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
Al Viro8687b632006-10-19 23:28:48 -07001282 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001284 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1285 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001286 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001287 encode_nfs4_stateid(xdr, args->stateid);
1288 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001289 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001290 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291}
1292
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001293static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1294{
Trond Myklebustab19b482012-03-04 18:13:57 -05001295 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001296 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001297}
1298
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001299static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Trond Myklebustab19b482012-03-04 18:13:57 -05001301 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001302 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303}
1304
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001305static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
Al Viro8687b632006-10-19 23:28:48 -07001307 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Benny Halevy13c65ce2009-08-14 17:19:25 +03001309 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001310 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001311 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001312 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001313 break;
1314 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001315 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001316 break;
1317 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001318 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001319 break;
1320 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001321 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
Benny Halevy34558512009-08-14 17:19:30 +03001323 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
1326static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 /*
1330 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1331 * owner 4 = 32
1332 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001333 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001334 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001335 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001336 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001337 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001338 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001339 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001340 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
1343static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1344{
Al Viro8687b632006-10-19 23:28:48 -07001345 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001346 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Benny Halevy13c65ce2009-08-14 17:19:25 +03001348 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001350 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001351 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001352 encode_attrs(xdr, arg->u.attrs, arg->server);
1353 break;
1354 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001355 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001356 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001357 if (nfs4_has_persistent_session(clp)) {
1358 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1359 encode_attrs(xdr, arg->u.attrs, arg->server);
1360 } else {
1361 struct iattr dummy;
1362
1363 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1364 encode_nfs4_verifier(xdr, &arg->u.verifier);
1365 dummy.ia_valid = 0;
1366 encode_attrs(xdr, &dummy, arg->server);
1367 }
1368 } else {
1369 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1370 encode_nfs4_verifier(xdr, &arg->u.verifier);
1371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
1373}
1374
1375static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1376{
Al Viro8687b632006-10-19 23:28:48 -07001377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Benny Halevy13c65ce2009-08-14 17:19:25 +03001379 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001381 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001382 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001383 break;
1384 default:
1385 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001386 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001387 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389}
1390
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001391static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001397 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001399 break;
1400 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001402 break;
1403 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 break;
1406 default:
1407 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
1409}
1410
1411static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1412{
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001416 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 encode_string(xdr, name->len, name->name);
1418}
1419
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001420static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
Al Viro8687b632006-10-19 23:28:48 -07001422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Benny Halevy13c65ce2009-08-14 17:19:25 +03001424 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 encode_delegation_type(xdr, type);
1427}
1428
1429static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1430{
Al Viro8687b632006-10-19 23:28:48 -07001431 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001433 p = reserve_space(xdr, 4);
1434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1435 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 encode_string(xdr, name->len, name->name);
1437}
1438
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001439static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
Trond Myklebustab19b482012-03-04 18:13:57 -05001441 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 encode_openhdr(xdr, arg);
1443 encode_opentype(xdr, arg);
1444 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001445 case NFS4_OPEN_CLAIM_NULL:
1446 encode_claim_null(xdr, arg->name);
1447 break;
1448 case NFS4_OPEN_CLAIM_PREVIOUS:
1449 encode_claim_previous(xdr, arg->u.delegation_type);
1450 break;
1451 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1452 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1453 break;
1454 default:
1455 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001459static 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 -07001460{
Trond Myklebustab19b482012-03-04 18:13:57 -05001461 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001462 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001463 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001466static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Trond Myklebustab19b482012-03-04 18:13:57 -05001468 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001469 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001470 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001471 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static void
Andy Adamsond0179312008-12-23 16:06:17 -05001475encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Trond Myklebustab19b482012-03-04 18:13:57 -05001477 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001478 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001481static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Trond Myklebustab19b482012-03-04 18:13:57 -05001483 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001486static 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 -07001487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 if (ctx->state != NULL) {
Trond Myklebust1e3987c2012-03-04 18:13:56 -05001491 nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001492 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001493 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001494 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001496 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001499static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Al Viro8687b632006-10-19 23:28:48 -07001501 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Trond Myklebustab19b482012-03-04 18:13:57 -05001503 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001504 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001505 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Benny Halevy13c65ce2009-08-14 17:19:25 +03001507 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001508 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001509 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static 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 -07001513{
Trond Myklebust28331a42011-04-27 13:47:52 -04001514 uint32_t attrs[2] = {
1515 FATTR4_WORD0_RDATTR_ERROR,
1516 FATTR4_WORD1_MOUNTED_ON_FILEID,
1517 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001518 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001519 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001521 if (readdir->plus) {
1522 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001523 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001524 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1525 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1526 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1527 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001528 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001529 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001530 /* Use mounted_on_fileid only if the server supports it */
1531 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1532 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001533
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001534 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1535 p = reserve_space(xdr, 8);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001536 p = xdr_encode_hyper(p, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001537 encode_nfs4_verifier(xdr, &readdir->verifier);
1538 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001539 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001540 *p++ = cpu_to_be32(readdir->count);
1541 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001542
Benny Halevye75bc1c2009-08-14 17:18:54 +03001543 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001544 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001545 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001546 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1547 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001548 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001549 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001550 attrs[0] & readdir->bitmask[0],
1551 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static 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 -07001555{
Trond Myklebustab19b482012-03-04 18:13:57 -05001556 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001559static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
Trond Myklebustab19b482012-03-04 18:13:57 -05001561 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001562 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001565static 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 -07001566{
Trond Myklebustab19b482012-03-04 18:13:57 -05001567 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001568 encode_string(xdr, oldname->len, oldname->name);
1569 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Chuck Leverbb4dae52012-03-01 17:01:48 -05001572static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1573 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Al Viro8687b632006-10-19 23:28:48 -07001575 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001577 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1578 p = reserve_space(xdr, 8);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001579 xdr_encode_hyper(p, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001582static void
Andy Adamsond0179312008-12-23 16:06:17 -05001583encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001584{
Trond Myklebustab19b482012-03-04 18:13:57 -05001585 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001586}
1587
Chuck Lever9f06c712010-12-14 14:59:18 +00001588static void
Andy Adamsond0179312008-12-23 16:06:17 -05001589encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001590{
Al Viro8687b632006-10-19 23:28:48 -07001591 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001592
Trond Myklebustab19b482012-03-04 18:13:57 -05001593 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001594 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001595 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001596 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001597 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001598 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001599 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001600 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001601 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001602}
1603
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001604static void
Andy Adamsond0179312008-12-23 16:06:17 -05001605encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Trond Myklebustab19b482012-03-04 18:13:57 -05001607 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608}
1609
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001610static 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 -07001611{
Trond Myklebustab19b482012-03-04 18:13:57 -05001612 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001613 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Al Viro8687b632006-10-19 23:28:48 -07001619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Trond Myklebust70019512012-03-04 20:49:32 -05001621 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001622 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
1624 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001625 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001626 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1628 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001629 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001630 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001633static 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 -07001634{
Andy Adamson05d564f2008-12-23 16:06:15 -05001635 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001637 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1638 decode_setclientid_confirm_maxsz, hdr);
1639 p = reserve_space(xdr, 8);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001640 p = xdr_encode_hyper(p, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001641 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001644static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Al Viro8687b632006-10-19 23:28:48 -07001646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Trond Myklebustab19b482012-03-04 18:13:57 -05001648 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001649 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001650 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001653 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001654 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001655 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001660static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001663 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001665
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001666static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1667{
Trond Myklebustab19b482012-03-04 18:13:57 -05001668 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001669 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001670}
1671
Benny Halevy99fe60d2009-04-01 09:22:29 -04001672#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001673/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001674static void encode_exchange_id(struct xdr_stream *xdr,
1675 struct nfs41_exchange_id_args *args,
1676 struct compound_hdr *hdr)
1677{
1678 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001679 char impl_name[NFS4_OPAQUE_LIMIT];
1680 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001681
Trond Myklebust70019512012-03-04 20:49:32 -05001682 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001683 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001684
1685 encode_string(xdr, args->id_len, args->id);
1686
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001688 *p++ = cpu_to_be32(args->flags);
1689 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001690
1691 if (send_implementation_id &&
1692 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1693 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1694 <= NFS4_OPAQUE_LIMIT + 1)
1695 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1696 utsname()->sysname, utsname()->release,
1697 utsname()->version, utsname()->machine);
1698
1699 if (len > 0) {
1700 *p = cpu_to_be32(1); /* implementation id array length=1 */
1701
1702 encode_string(xdr,
1703 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1704 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1705 encode_string(xdr, len, impl_name);
1706 /* just send zeros for nii_date - the date is in nii_name */
1707 p = reserve_space(xdr, 12);
1708 p = xdr_encode_hyper(p, 0);
1709 *p = cpu_to_be32(0);
1710 } else
1711 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001712}
Andy Adamsonfc931582009-04-01 09:22:31 -04001713
1714static void encode_create_session(struct xdr_stream *xdr,
1715 struct nfs41_create_session_args *args,
1716 struct compound_hdr *hdr)
1717{
1718 __be32 *p;
1719 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1720 uint32_t len;
1721 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001722 u32 max_resp_sz_cached;
1723
1724 /*
1725 * Assumes OPEN is the biggest non-idempotent compound.
1726 * 2 is the verifier.
1727 */
1728 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1729 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001730
Andy Adamsonfc931582009-04-01 09:22:31 -04001731 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1732 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001733
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001734 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1735 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001736 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1738 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001739
Andy Adamsonfc931582009-04-01 09:22:31 -04001740 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001741 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001742 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1743 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001744 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001745 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1746 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1747 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001748
1749 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001750 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001751 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1752 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1753 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1754 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1755 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1756 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001757
Benny Halevye75bc1c2009-08-14 17:18:54 +03001758 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001759 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001761
1762 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001763 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001764 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001765 *p++ = cpu_to_be32(0); /* UID */
1766 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001767 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001768}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001769
1770static void encode_destroy_session(struct xdr_stream *xdr,
1771 struct nfs4_session *session,
1772 struct compound_hdr *hdr)
1773{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001774 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1775 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001776}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001777
1778static void encode_reclaim_complete(struct xdr_stream *xdr,
1779 struct nfs41_reclaim_complete_args *args,
1780 struct compound_hdr *hdr)
1781{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001782 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1783 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001784}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001785#endif /* CONFIG_NFS_V4_1 */
1786
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001787static void encode_sequence(struct xdr_stream *xdr,
1788 const struct nfs4_sequence_args *args,
1789 struct compound_hdr *hdr)
1790{
1791#if defined(CONFIG_NFS_V4_1)
1792 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001793 struct nfs4_slot_table *tp;
1794 struct nfs4_slot *slot;
1795 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001796
1797 if (!session)
1798 return;
1799
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001800 tp = &session->fc_slot_table;
1801
1802 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1803 slot = tp->slots + args->sa_slotid;
1804
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001805 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001806
1807 /*
1808 * Sessionid + seqid + slotid + max slotid + cache_this
1809 */
1810 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1811 "max_slotid=%d cache_this=%d\n",
1812 __func__,
1813 ((u32 *)session->sess_id.data)[0],
1814 ((u32 *)session->sess_id.data)[1],
1815 ((u32 *)session->sess_id.data)[2],
1816 ((u32 *)session->sess_id.data)[3],
1817 slot->seq_nr, args->sa_slotid,
1818 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001819 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001820 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(slot->seq_nr);
1822 *p++ = cpu_to_be32(args->sa_slotid);
1823 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001824 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001825#endif /* CONFIG_NFS_V4_1 */
1826}
1827
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001828#ifdef CONFIG_NFS_V4_1
1829static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001830encode_getdevicelist(struct xdr_stream *xdr,
1831 const struct nfs4_getdevicelist_args *args,
1832 struct compound_hdr *hdr)
1833{
1834 __be32 *p;
1835 nfs4_verifier dummy = {
1836 .data = "dummmmmy",
1837 };
1838
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001839 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1840 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001841 *p++ = cpu_to_be32(args->layoutclass);
1842 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1843 xdr_encode_hyper(p, 0ULL); /* cookie */
1844 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001845}
1846
1847static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001848encode_getdeviceinfo(struct xdr_stream *xdr,
1849 const struct nfs4_getdeviceinfo_args *args,
1850 struct compound_hdr *hdr)
1851{
1852 __be32 *p;
1853
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001854 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1855 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001856 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1857 NFS4_DEVICEID4_SIZE);
1858 *p++ = cpu_to_be32(args->pdev->layout_type);
1859 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1860 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001861}
1862
1863static void
1864encode_layoutget(struct xdr_stream *xdr,
1865 const struct nfs4_layoutget_args *args,
1866 struct compound_hdr *hdr)
1867{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001868 __be32 *p;
1869
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001870 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1871 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001872 *p++ = cpu_to_be32(0); /* Signal layout available */
1873 *p++ = cpu_to_be32(args->type);
1874 *p++ = cpu_to_be32(args->range.iomode);
1875 p = xdr_encode_hyper(p, args->range.offset);
1876 p = xdr_encode_hyper(p, args->range.length);
1877 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001878 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001879 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001880
1881 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1882 __func__,
1883 args->type,
1884 args->range.iomode,
1885 (unsigned long)args->range.offset,
1886 (unsigned long)args->range.length,
1887 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001888}
Andy Adamson863a3c62011-03-23 13:27:54 +00001889
1890static int
1891encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001892 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001893 const struct nfs4_layoutcommit_args *args,
1894 struct compound_hdr *hdr)
1895{
1896 __be32 *p;
1897
1898 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1899 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1900
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001901 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1902 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001903 /* Only whole file layouts */
1904 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001905 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001906 *p = cpu_to_be32(0); /* reclaim */
1907 encode_nfs4_stateid(xdr, &args->stateid);
1908 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001909 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1910 p = xdr_encode_hyper(p, args->lastbytewritten);
1911 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1912 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001913
1914 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1915 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1916 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001917 else
1918 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001919
Andy Adamson863a3c62011-03-23 13:27:54 +00001920 return 0;
1921}
Benny Halevycbe82602011-05-22 19:52:37 +03001922
1923static void
1924encode_layoutreturn(struct xdr_stream *xdr,
1925 const struct nfs4_layoutreturn_args *args,
1926 struct compound_hdr *hdr)
1927{
1928 __be32 *p;
1929
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001930 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1931 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001932 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1933 *p++ = cpu_to_be32(args->layout_type);
1934 *p++ = cpu_to_be32(IOMODE_ANY);
1935 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001936 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001937 p = xdr_encode_hyper(p, 0);
1938 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1939 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001940 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001941 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001942 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1943 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1944 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001945 } else
1946 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001947}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001948
1949static int
1950encode_secinfo_no_name(struct xdr_stream *xdr,
1951 const struct nfs41_secinfo_no_name_args *args,
1952 struct compound_hdr *hdr)
1953{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001954 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1955 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001956 return 0;
1957}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001958
1959static void encode_test_stateid(struct xdr_stream *xdr,
1960 struct nfs41_test_stateid_args *args,
1961 struct compound_hdr *hdr)
1962{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001963 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1964 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001965 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001966}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001967
1968static void encode_free_stateid(struct xdr_stream *xdr,
1969 struct nfs41_free_stateid_args *args,
1970 struct compound_hdr *hdr)
1971{
Trond Myklebustab19b482012-03-04 18:13:57 -05001972 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001973 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001974}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975#endif /* CONFIG_NFS_V4_1 */
1976
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977/*
1978 * END OF "GENERIC" ENCODE ROUTINES.
1979 */
1980
Benny Halevy66cc0422009-04-01 09:22:10 -04001981static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1982{
1983#if defined(CONFIG_NFS_V4_1)
1984 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001985 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001986#endif /* CONFIG_NFS_V4_1 */
1987 return 0;
1988}
1989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990/*
1991 * Encode an ACCESS request
1992 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001993static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1994 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001997 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Chuck Lever9f06c712010-12-14 14:59:18 +00002000 encode_compound_hdr(xdr, req, &hdr);
2001 encode_sequence(xdr, &args->seq_args, &hdr);
2002 encode_putfh(xdr, args->fh, &hdr);
2003 encode_access(xdr, args->access, &hdr);
2004 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002005 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006}
2007
2008/*
2009 * Encode LOOKUP request
2010 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002011static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2012 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002015 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Chuck Lever9f06c712010-12-14 14:59:18 +00002018 encode_compound_hdr(xdr, req, &hdr);
2019 encode_sequence(xdr, &args->seq_args, &hdr);
2020 encode_putfh(xdr, args->dir_fh, &hdr);
2021 encode_lookup(xdr, args->name, &hdr);
2022 encode_getfh(xdr, &hdr);
2023 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002024 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025}
2026
2027/*
2028 * Encode LOOKUP_ROOT request
2029 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002030static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2031 struct xdr_stream *xdr,
2032 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002035 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
Chuck Lever9f06c712010-12-14 14:59:18 +00002038 encode_compound_hdr(xdr, req, &hdr);
2039 encode_sequence(xdr, &args->seq_args, &hdr);
2040 encode_putrootfh(xdr, &hdr);
2041 encode_getfh(xdr, &hdr);
2042 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002043 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
2046/*
2047 * Encode REMOVE request
2048 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002049static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2050 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002053 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Chuck Lever9f06c712010-12-14 14:59:18 +00002056 encode_compound_hdr(xdr, req, &hdr);
2057 encode_sequence(xdr, &args->seq_args, &hdr);
2058 encode_putfh(xdr, args->fh, &hdr);
2059 encode_remove(xdr, &args->name, &hdr);
2060 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002061 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062}
2063
2064/*
2065 * Encode RENAME request
2066 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002067static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2068 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002071 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
Chuck Lever9f06c712010-12-14 14:59:18 +00002074 encode_compound_hdr(xdr, req, &hdr);
2075 encode_sequence(xdr, &args->seq_args, &hdr);
2076 encode_putfh(xdr, args->old_dir, &hdr);
2077 encode_savefh(xdr, &hdr);
2078 encode_putfh(xdr, args->new_dir, &hdr);
2079 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2080 encode_getfattr(xdr, args->bitmask, &hdr);
2081 encode_restorefh(xdr, &hdr);
2082 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002083 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
2086/*
2087 * Encode LINK request
2088 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002089static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2090 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002093 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Chuck Lever9f06c712010-12-14 14:59:18 +00002096 encode_compound_hdr(xdr, req, &hdr);
2097 encode_sequence(xdr, &args->seq_args, &hdr);
2098 encode_putfh(xdr, args->fh, &hdr);
2099 encode_savefh(xdr, &hdr);
2100 encode_putfh(xdr, args->dir_fh, &hdr);
2101 encode_link(xdr, args->name, &hdr);
2102 encode_getfattr(xdr, args->bitmask, &hdr);
2103 encode_restorefh(xdr, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode CREATE request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->dir_fh, &hdr);
2121 encode_savefh(xdr, &hdr);
2122 encode_create(xdr, args, &hdr);
2123 encode_getfh(xdr, &hdr);
2124 encode_getfattr(xdr, args->bitmask, &hdr);
2125 encode_restorefh(xdr, &hdr);
2126 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002127 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128}
2129
2130/*
2131 * Encode SYMLINK request
2132 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002133static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2134 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135{
Chuck Lever9f06c712010-12-14 14:59:18 +00002136 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137}
2138
2139/*
2140 * Encode GETATTR request
2141 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002142static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2143 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002146 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
Chuck Lever9f06c712010-12-14 14:59:18 +00002149 encode_compound_hdr(xdr, req, &hdr);
2150 encode_sequence(xdr, &args->seq_args, &hdr);
2151 encode_putfh(xdr, args->fh, &hdr);
2152 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002153 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154}
2155
2156/*
2157 * Encode a CLOSE request
2158 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002159static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2160 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
Andy Adamson05d564f2008-12-23 16:06:15 -05002162 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002163 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002164 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Chuck Lever9f06c712010-12-14 14:59:18 +00002166 encode_compound_hdr(xdr, req, &hdr);
2167 encode_sequence(xdr, &args->seq_args, &hdr);
2168 encode_putfh(xdr, args->fh, &hdr);
2169 encode_close(xdr, args, &hdr);
2170 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002171 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172}
2173
2174/*
2175 * Encode an OPEN request
2176 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002177static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2178 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002181 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Chuck Lever9f06c712010-12-14 14:59:18 +00002184 encode_compound_hdr(xdr, req, &hdr);
2185 encode_sequence(xdr, &args->seq_args, &hdr);
2186 encode_putfh(xdr, args->fh, &hdr);
2187 encode_savefh(xdr, &hdr);
2188 encode_open(xdr, args, &hdr);
2189 encode_getfh(xdr, &hdr);
2190 encode_getfattr(xdr, args->bitmask, &hdr);
2191 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002192 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002193 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196/*
2197 * Encode an OPEN_CONFIRM request
2198 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002199static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2200 struct xdr_stream *xdr,
2201 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002204 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
Chuck Lever9f06c712010-12-14 14:59:18 +00002207 encode_compound_hdr(xdr, req, &hdr);
2208 encode_putfh(xdr, args->fh, &hdr);
2209 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002210 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211}
2212
2213/*
2214 * Encode an OPEN request with no attributes.
2215 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002216static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2217 struct xdr_stream *xdr,
2218 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002221 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Chuck Lever9f06c712010-12-14 14:59:18 +00002224 encode_compound_hdr(xdr, req, &hdr);
2225 encode_sequence(xdr, &args->seq_args, &hdr);
2226 encode_putfh(xdr, args->fh, &hdr);
2227 encode_open(xdr, args, &hdr);
2228 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002229 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * Encode an OPEN_DOWNGRADE request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2236 struct xdr_stream *xdr,
2237 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002240 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_sequence(xdr, &args->seq_args, &hdr);
2245 encode_putfh(xdr, args->fh, &hdr);
2246 encode_open_downgrade(xdr, args, &hdr);
2247 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode a LOCK request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2255 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
2264 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002265 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266}
2267
2268/*
2269 * Encode a LOCKT request
2270 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002271static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2272 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002275 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
Chuck Lever9f06c712010-12-14 14:59:18 +00002278 encode_compound_hdr(xdr, req, &hdr);
2279 encode_sequence(xdr, &args->seq_args, &hdr);
2280 encode_putfh(xdr, args->fh, &hdr);
2281 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002282 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283}
2284
2285/*
2286 * Encode a LOCKU request
2287 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002288static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2289 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Chuck Lever9f06c712010-12-14 14:59:18 +00002295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002299 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
Chuck Lever9f06c712010-12-14 14:59:18 +00002302static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2303 struct xdr_stream *xdr,
2304 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002305{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002306 struct compound_hdr hdr = {
2307 .minorversion = 0,
2308 };
2309
Chuck Lever9f06c712010-12-14 14:59:18 +00002310 encode_compound_hdr(xdr, req, &hdr);
2311 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002312 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002313}
2314
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315/*
2316 * Encode a READLINK request
2317 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002318static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2319 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002322 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_sequence(xdr, &args->seq_args, &hdr);
2327 encode_putfh(xdr, args->fh, &hdr);
2328 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002329
Benny Halevy28f56692009-04-01 09:22:09 -04002330 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002331 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002332 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333}
2334
2335/*
2336 * Encode a READDIR request
2337 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002338static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2339 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002342 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Chuck Lever9f06c712010-12-14 14:59:18 +00002345 encode_compound_hdr(xdr, req, &hdr);
2346 encode_sequence(xdr, &args->seq_args, &hdr);
2347 encode_putfh(xdr, args->fh, &hdr);
2348 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002349
Benny Halevy28f56692009-04-01 09:22:09 -04002350 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002351 args->pgbase, args->count);
2352 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002353 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002354 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002355 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
2358/*
2359 * Encode a READ request
2360 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002361static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2362 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002365 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
Chuck Lever9f06c712010-12-14 14:59:18 +00002368 encode_compound_hdr(xdr, req, &hdr);
2369 encode_sequence(xdr, &args->seq_args, &hdr);
2370 encode_putfh(xdr, args->fh, &hdr);
2371 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
Benny Halevy28f56692009-04-01 09:22:09 -04002373 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002375 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002376 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377}
2378
2379/*
2380 * Encode an SETATTR request
2381 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002382static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2383 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Andy Adamson05d564f2008-12-23 16:06:15 -05002385 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002387 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Chuck Lever9f06c712010-12-14 14:59:18 +00002389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
2392 encode_setattr(xdr, args, args->server, &hdr);
2393 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002398 * Encode a GETACL request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002402{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002403 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002405 };
Benny Halevy28f56692009-04-01 09:22:09 -04002406 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002407
Chuck Lever9f06c712010-12-14 14:59:18 +00002408 encode_compound_hdr(xdr, req, &hdr);
2409 encode_sequence(xdr, &args->seq_args, &hdr);
2410 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002411 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002412 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002413
Benny Halevy28f56692009-04-01 09:22:09 -04002414 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002415 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002416
Andy Adamsond0179312008-12-23 16:06:17 -05002417 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002418}
2419
2420/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 * Encode a WRITE request
2422 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002423static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2424 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Chuck Lever9f06c712010-12-14 14:59:18 +00002430 encode_compound_hdr(xdr, req, &hdr);
2431 encode_sequence(xdr, &args->seq_args, &hdr);
2432 encode_putfh(xdr, args->fh, &hdr);
2433 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002434 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002435 if (args->bitmask)
2436 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002437 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438}
2439
2440/*
2441 * a COMMIT request
2442 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002443static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2444 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002447 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449
Chuck Lever9f06c712010-12-14 14:59:18 +00002450 encode_compound_hdr(xdr, req, &hdr);
2451 encode_sequence(xdr, &args->seq_args, &hdr);
2452 encode_putfh(xdr, args->fh, &hdr);
2453 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002454 if (args->bitmask)
2455 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002456 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457}
2458
2459/*
2460 * FSINFO request
2461 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002462static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2463 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002466 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Chuck Lever9f06c712010-12-14 14:59:18 +00002469 encode_compound_hdr(xdr, req, &hdr);
2470 encode_sequence(xdr, &args->seq_args, &hdr);
2471 encode_putfh(xdr, args->fh, &hdr);
2472 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002473 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
2475
2476/*
2477 * a PATHCONF request
2478 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002479static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2480 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002483 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
2489 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002490 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002491 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492}
2493
2494/*
2495 * a STATFS request
2496 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002497static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2498 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002501 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
Chuck Lever9f06c712010-12-14 14:59:18 +00002504 encode_compound_hdr(xdr, req, &hdr);
2505 encode_sequence(xdr, &args->seq_args, &hdr);
2506 encode_putfh(xdr, args->fh, &hdr);
2507 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002508 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002509 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * GETATTR_BITMAP request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2516 struct xdr_stream *xdr,
2517 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002520 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Chuck Lever9f06c712010-12-14 14:59:18 +00002523 encode_compound_hdr(xdr, req, &hdr);
2524 encode_sequence(xdr, &args->seq_args, &hdr);
2525 encode_putfh(xdr, args->fhandle, &hdr);
2526 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002527 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002528 FATTR4_WORD0_LINK_SUPPORT|
2529 FATTR4_WORD0_SYMLINK_SUPPORT|
2530 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002531 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532}
2533
2534/*
2535 * a RENEW request
2536 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002537static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2538 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002541 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 };
2543
Chuck Lever9f06c712010-12-14 14:59:18 +00002544 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002545 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002546 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
2549/*
2550 * a SETCLIENTID request
2551 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002552static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2553 struct xdr_stream *xdr,
2554 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002557 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 };
2559
Chuck Lever9f06c712010-12-14 14:59:18 +00002560 encode_compound_hdr(xdr, req, &hdr);
2561 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002562 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565/*
2566 * a SETCLIENTID_CONFIRM request
2567 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002568static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2569 struct xdr_stream *xdr,
2570 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002573 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 };
Fred Isamandae100c2011-07-30 20:52:37 -04002575 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Chuck Lever9f06c712010-12-14 14:59:18 +00002577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_setclientid_confirm(xdr, arg, &hdr);
2579 encode_putrootfh(xdr, &hdr);
2580 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002581 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
2584/*
2585 * DELEGRETURN request
2586 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002587static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2588 struct xdr_stream *xdr,
2589 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002592 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
Chuck Lever9f06c712010-12-14 14:59:18 +00002595 encode_compound_hdr(xdr, req, &hdr);
2596 encode_sequence(xdr, &args->seq_args, &hdr);
2597 encode_putfh(xdr, args->fhandle, &hdr);
2598 encode_delegreturn(xdr, args->stateid, &hdr);
2599 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002600 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601}
2602
2603/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002604 * Encode FS_LOCATIONS request
2605 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002606static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2607 struct xdr_stream *xdr,
2608 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002609{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002610 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002611 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002612 };
Benny Halevy28f56692009-04-01 09:22:09 -04002613 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002614
Chuck Lever9f06c712010-12-14 14:59:18 +00002615 encode_compound_hdr(xdr, req, &hdr);
2616 encode_sequence(xdr, &args->seq_args, &hdr);
2617 encode_putfh(xdr, args->dir_fh, &hdr);
2618 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002619 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002621
Benny Halevy28f56692009-04-01 09:22:09 -04002622 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002623 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002624 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002625}
2626
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002627/*
2628 * Encode SECINFO request
2629 */
2630static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2631 struct xdr_stream *xdr,
2632 struct nfs4_secinfo_arg *args)
2633{
2634 struct compound_hdr hdr = {
2635 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2636 };
2637
2638 encode_compound_hdr(xdr, req, &hdr);
2639 encode_sequence(xdr, &args->seq_args, &hdr);
2640 encode_putfh(xdr, args->dir_fh, &hdr);
2641 encode_secinfo(xdr, args->name, &hdr);
2642 encode_nops(&hdr);
2643}
2644
Benny Halevy99fe60d2009-04-01 09:22:29 -04002645#if defined(CONFIG_NFS_V4_1)
2646/*
2647 * EXCHANGE_ID request
2648 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002649static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2650 struct xdr_stream *xdr,
2651 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002652{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002653 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002654 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002655 };
2656
Chuck Lever9f06c712010-12-14 14:59:18 +00002657 encode_compound_hdr(xdr, req, &hdr);
2658 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002659 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002660}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002661
2662/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002663 * a CREATE_SESSION request
2664 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002665static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2666 struct xdr_stream *xdr,
2667 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002668{
Andy Adamsonfc931582009-04-01 09:22:31 -04002669 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002670 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002671 };
2672
Chuck Lever9f06c712010-12-14 14:59:18 +00002673 encode_compound_hdr(xdr, req, &hdr);
2674 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002675 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002676}
2677
2678/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002679 * a DESTROY_SESSION request
2680 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002681static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2682 struct xdr_stream *xdr,
2683 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002684{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002685 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002686 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002687 };
2688
Chuck Lever9f06c712010-12-14 14:59:18 +00002689 encode_compound_hdr(xdr, req, &hdr);
2690 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002691 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002692}
2693
2694/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002695 * a SEQUENCE request
2696 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002697static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2698 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002699{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002700 struct compound_hdr hdr = {
2701 .minorversion = nfs4_xdr_minorversion(args),
2702 };
2703
Chuck Lever9f06c712010-12-14 14:59:18 +00002704 encode_compound_hdr(xdr, req, &hdr);
2705 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002706 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002707}
2708
2709/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002710 * a GET_LEASE_TIME request
2711 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002712static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2713 struct xdr_stream *xdr,
2714 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002715{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002716 struct compound_hdr hdr = {
2717 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2718 };
Fred Isamandae100c2011-07-30 20:52:37 -04002719 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002720
Chuck Lever9f06c712010-12-14 14:59:18 +00002721 encode_compound_hdr(xdr, req, &hdr);
2722 encode_sequence(xdr, &args->la_seq_args, &hdr);
2723 encode_putrootfh(xdr, &hdr);
2724 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002725 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002726}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002727
2728/*
2729 * a RECLAIM_COMPLETE request
2730 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002731static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
2733 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002734{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002735 struct compound_hdr hdr = {
2736 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2737 };
2738
Chuck Lever9f06c712010-12-14 14:59:18 +00002739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_sequence(xdr, &args->seq_args, &hdr);
2741 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002742 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002743}
2744
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002745/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002746 * Encode GETDEVICELIST request
2747 */
2748static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
2750 struct nfs4_getdevicelist_args *args)
2751{
2752 struct compound_hdr hdr = {
2753 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2754 };
2755
2756 encode_compound_hdr(xdr, req, &hdr);
2757 encode_sequence(xdr, &args->seq_args, &hdr);
2758 encode_putfh(xdr, args->fh, &hdr);
2759 encode_getdevicelist(xdr, args, &hdr);
2760 encode_nops(&hdr);
2761}
2762
2763/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002764 * Encode GETDEVICEINFO request
2765 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002766static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2767 struct xdr_stream *xdr,
2768 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002769{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002770 struct compound_hdr hdr = {
2771 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2772 };
2773
Chuck Lever9f06c712010-12-14 14:59:18 +00002774 encode_compound_hdr(xdr, req, &hdr);
2775 encode_sequence(xdr, &args->seq_args, &hdr);
2776 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002777
2778 /* set up reply kvec. Subtract notification bitmap max size (2)
2779 * so that notification bitmap is put in xdr_buf tail */
2780 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2781 args->pdev->pages, args->pdev->pgbase,
2782 args->pdev->pglen);
2783
2784 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002785}
2786
2787/*
2788 * Encode LAYOUTGET request
2789 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002790static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2791 struct xdr_stream *xdr,
2792 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002793{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002794 struct compound_hdr hdr = {
2795 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2796 };
2797
Chuck Lever9f06c712010-12-14 14:59:18 +00002798 encode_compound_hdr(xdr, req, &hdr);
2799 encode_sequence(xdr, &args->seq_args, &hdr);
2800 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2801 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002802
2803 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2804 args->layout.pages, 0, args->layout.pglen);
2805
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002806 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002807}
Andy Adamson863a3c62011-03-23 13:27:54 +00002808
2809/*
2810 * Encode LAYOUTCOMMIT request
2811 */
Benny Halevycbe82602011-05-22 19:52:37 +03002812static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2813 struct xdr_stream *xdr,
2814 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002815{
Benny Halevyac7db722011-05-22 19:53:48 +03002816 struct nfs4_layoutcommit_data *data =
2817 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002818 struct compound_hdr hdr = {
2819 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2820 };
2821
2822 encode_compound_hdr(xdr, req, &hdr);
2823 encode_sequence(xdr, &args->seq_args, &hdr);
2824 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002825 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002826 encode_getfattr(xdr, args->bitmask, &hdr);
2827 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002828}
2829
2830/*
2831 * Encode LAYOUTRETURN request
2832 */
2833static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2834 struct xdr_stream *xdr,
2835 struct nfs4_layoutreturn_args *args)
2836{
2837 struct compound_hdr hdr = {
2838 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2839 };
2840
2841 encode_compound_hdr(xdr, req, &hdr);
2842 encode_sequence(xdr, &args->seq_args, &hdr);
2843 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2844 encode_layoutreturn(xdr, args, &hdr);
2845 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002846}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002847
2848/*
2849 * Encode SECINFO_NO_NAME request
2850 */
2851static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2852 struct xdr_stream *xdr,
2853 struct nfs41_secinfo_no_name_args *args)
2854{
2855 struct compound_hdr hdr = {
2856 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2857 };
2858
2859 encode_compound_hdr(xdr, req, &hdr);
2860 encode_sequence(xdr, &args->seq_args, &hdr);
2861 encode_putrootfh(xdr, &hdr);
2862 encode_secinfo_no_name(xdr, args, &hdr);
2863 encode_nops(&hdr);
2864 return 0;
2865}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002866
2867/*
2868 * Encode TEST_STATEID request
2869 */
2870static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2871 struct xdr_stream *xdr,
2872 struct nfs41_test_stateid_args *args)
2873{
2874 struct compound_hdr hdr = {
2875 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2876 };
2877
2878 encode_compound_hdr(xdr, req, &hdr);
2879 encode_sequence(xdr, &args->seq_args, &hdr);
2880 encode_test_stateid(xdr, args, &hdr);
2881 encode_nops(&hdr);
2882}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002883
2884/*
2885 * Encode FREE_STATEID request
2886 */
2887static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2888 struct xdr_stream *xdr,
2889 struct nfs41_free_stateid_args *args)
2890{
2891 struct compound_hdr hdr = {
2892 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2893 };
2894
2895 encode_compound_hdr(xdr, req, &hdr);
2896 encode_sequence(xdr, &args->seq_args, &hdr);
2897 encode_free_stateid(xdr, args, &hdr);
2898 encode_nops(&hdr);
2899}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002900#endif /* CONFIG_NFS_V4_1 */
2901
Benny Halevy686841b2009-08-14 17:19:48 +03002902static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2903{
2904 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2905 "Remaining buffer length is %tu words.\n",
2906 func, xdr->end - xdr->p);
2907}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
Trond Myklebust683b57b2006-06-09 09:34:22 -04002909static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910{
Al Viro8687b632006-10-19 23:28:48 -07002911 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
Benny Halevyc0eae662009-08-14 17:20:14 +03002913 p = xdr_inline_decode(xdr, 4);
2914 if (unlikely(!p))
2915 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002916 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002917 p = xdr_inline_decode(xdr, *len);
2918 if (unlikely(!p))
2919 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 *string = (char *)p;
2921 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002922out_overflow:
2923 print_overflow_msg(__func__, xdr);
2924 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925}
2926
2927static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2928{
Al Viro8687b632006-10-19 23:28:48 -07002929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930
Benny Halevyc0eae662009-08-14 17:20:14 +03002931 p = xdr_inline_decode(xdr, 8);
2932 if (unlikely(!p))
2933 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002934 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002935 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002936
Benny Halevyc0eae662009-08-14 17:20:14 +03002937 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2938 if (unlikely(!p))
2939 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 hdr->tag = (char *)p;
2941 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002942 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002943 if (unlikely(hdr->nops < 1))
2944 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002946out_overflow:
2947 print_overflow_msg(__func__, xdr);
2948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949}
2950
2951static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2952{
Al Viro8687b632006-10-19 23:28:48 -07002953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 uint32_t opnum;
2955 int32_t nfserr;
2956
Benny Halevyc0eae662009-08-14 17:20:14 +03002957 p = xdr_inline_decode(xdr, 8);
2958 if (unlikely(!p))
2959 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002960 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002962 dprintk("nfs: Server returned operation"
2963 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 opnum, expected);
2965 return -EIO;
2966 }
Benny Halevycccddf42009-08-14 17:20:19 +03002967 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002969 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002971out_overflow:
2972 print_overflow_msg(__func__, xdr);
2973 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974}
2975
2976/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002977static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Al Viro8687b632006-10-19 23:28:48 -07002979 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002980 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 char *str;
2982
Benny Halevyc0eae662009-08-14 17:20:14 +03002983 p = xdr_inline_decode(xdr, 12);
2984 if (likely(p))
2985 return decode_opaque_inline(xdr, &strlen, &str);
2986 print_overflow_msg(__func__, xdr);
2987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988}
2989
2990static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2991{
Al Viro8687b632006-10-19 23:28:48 -07002992 uint32_t bmlen;
2993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, 4);
2996 if (unlikely(!p))
2997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002998 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Fred Isamandae100c2011-07-30 20:52:37 -04003000 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003001 p = xdr_inline_decode(xdr, (bmlen << 2));
3002 if (unlikely(!p))
3003 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003005 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003006 if (bmlen > 1) {
3007 bitmap[1] = be32_to_cpup(p++);
3008 if (bmlen > 2)
3009 bitmap[2] = be32_to_cpup(p);
3010 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 }
3012 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003013out_overflow:
3014 print_overflow_msg(__func__, xdr);
3015 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016}
3017
Al Viro8687b632006-10-19 23:28:48 -07003018static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019{
Al Viro8687b632006-10-19 23:28:48 -07003020 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
Benny Halevyc0eae662009-08-14 17:20:14 +03003022 p = xdr_inline_decode(xdr, 4);
3023 if (unlikely(!p))
3024 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003025 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 *savep = xdr->p;
3027 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003028out_overflow:
3029 print_overflow_msg(__func__, xdr);
3030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031}
3032
3033static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3034{
3035 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003036 int ret;
3037 ret = decode_attr_bitmap(xdr, bitmask);
3038 if (unlikely(ret < 0))
3039 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3041 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003042 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3043 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3044 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 return 0;
3046}
3047
3048static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3049{
Al Viro8687b632006-10-19 23:28:48 -07003050 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003051 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052
3053 *type = 0;
3054 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3055 return -EIO;
3056 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003057 p = xdr_inline_decode(xdr, 4);
3058 if (unlikely(!p))
3059 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003060 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003062 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 return -EIO;
3064 }
3065 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003066 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003068 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003069 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003070out_overflow:
3071 print_overflow_msg(__func__, xdr);
3072 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073}
3074
Chuck Lever264e6352012-03-01 17:02:05 -05003075static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3076 uint32_t *bitmap, uint32_t *type)
3077{
3078 __be32 *p;
3079
3080 *type = 0;
3081 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3082 return -EIO;
3083 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3084 p = xdr_inline_decode(xdr, 4);
3085 if (unlikely(!p))
3086 goto out_overflow;
3087 *type = be32_to_cpup(p);
3088 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3089 }
3090 dprintk("%s: expire type=0x%x\n", __func__, *type);
3091 return 0;
3092out_overflow:
3093 print_overflow_msg(__func__, xdr);
3094 return -EIO;
3095}
3096
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3098{
Al Viro8687b632006-10-19 23:28:48 -07003099 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003100 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
3102 *change = 0;
3103 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3104 return -EIO;
3105 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003106 p = xdr_inline_decode(xdr, 8);
3107 if (unlikely(!p))
3108 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003109 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003111 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003113 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003115 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003116out_overflow:
3117 print_overflow_msg(__func__, xdr);
3118 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119}
3120
3121static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3122{
Al Viro8687b632006-10-19 23:28:48 -07003123 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003124 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125
3126 *size = 0;
3127 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3128 return -EIO;
3129 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003130 p = xdr_inline_decode(xdr, 8);
3131 if (unlikely(!p))
3132 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003133 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003135 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003137 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003138 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003139out_overflow:
3140 print_overflow_msg(__func__, xdr);
3141 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
3144static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3145{
Al Viro8687b632006-10-19 23:28:48 -07003146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
3148 *res = 0;
3149 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3150 return -EIO;
3151 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003152 p = xdr_inline_decode(xdr, 4);
3153 if (unlikely(!p))
3154 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003155 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3157 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003158 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003160out_overflow:
3161 print_overflow_msg(__func__, xdr);
3162 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163}
3164
3165static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
3169 *res = 0;
3170 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3171 return -EIO;
3172 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3178 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003179 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003181out_overflow:
3182 print_overflow_msg(__func__, xdr);
3183 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003186static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
Al Viro8687b632006-10-19 23:28:48 -07003188 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003189 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 fsid->major = 0;
3192 fsid->minor = 0;
3193 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3194 return -EIO;
3195 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003196 p = xdr_inline_decode(xdr, 16);
3197 if (unlikely(!p))
3198 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003199 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003200 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003204 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 (unsigned long long)fsid->major,
3206 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003207 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003208out_overflow:
3209 print_overflow_msg(__func__, xdr);
3210 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211}
3212
3213static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3214{
Al Viro8687b632006-10-19 23:28:48 -07003215 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
3217 *res = 60;
3218 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3219 return -EIO;
3220 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003221 p = xdr_inline_decode(xdr, 4);
3222 if (unlikely(!p))
3223 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003224 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3226 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003227 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003229out_overflow:
3230 print_overflow_msg(__func__, xdr);
3231 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003234static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003235{
3236 __be32 *p;
3237
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3239 return -EIO;
3240 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3241 p = xdr_inline_decode(xdr, 4);
3242 if (unlikely(!p))
3243 goto out_overflow;
3244 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003245 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003246 }
3247 return 0;
3248out_overflow:
3249 print_overflow_msg(__func__, xdr);
3250 return -EIO;
3251}
3252
3253static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3254{
3255 __be32 *p;
3256 int len;
3257
Trond Myklebust7ad07352010-10-23 15:34:20 -04003258 if (fh != NULL)
3259 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003260
3261 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3262 return -EIO;
3263 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3264 p = xdr_inline_decode(xdr, 4);
3265 if (unlikely(!p))
3266 goto out_overflow;
3267 len = be32_to_cpup(p);
3268 if (len > NFS4_FHSIZE)
3269 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003270 p = xdr_inline_decode(xdr, len);
3271 if (unlikely(!p))
3272 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003273 if (fh != NULL) {
3274 memcpy(fh->data, p, len);
3275 fh->size = len;
3276 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003277 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3278 }
3279 return 0;
3280out_overflow:
3281 print_overflow_msg(__func__, xdr);
3282 return -EIO;
3283}
3284
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3286{
Al Viro8687b632006-10-19 23:28:48 -07003287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
3289 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3291 return -EIO;
3292 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003293 p = xdr_inline_decode(xdr, 4);
3294 if (unlikely(!p))
3295 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003296 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003299 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003301out_overflow:
3302 print_overflow_msg(__func__, xdr);
3303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304}
3305
3306static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3307{
Al Viro8687b632006-10-19 23:28:48 -07003308 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003309 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
3311 *fileid = 0;
3312 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3313 return -EIO;
3314 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003315 p = xdr_inline_decode(xdr, 8);
3316 if (unlikely(!p))
3317 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003318 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003320 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003322 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003323 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003324out_overflow:
3325 print_overflow_msg(__func__, xdr);
3326 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327}
3328
Manoj Naik99baf622006-06-09 09:34:24 -04003329static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3330{
Al Viro8687b632006-10-19 23:28:48 -07003331 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003333
3334 *fileid = 0;
3335 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3336 return -EIO;
3337 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003338 p = xdr_inline_decode(xdr, 8);
3339 if (unlikely(!p))
3340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003341 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003342 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003343 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003344 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003345 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003346 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003347out_overflow:
3348 print_overflow_msg(__func__, xdr);
3349 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003350}
3351
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3353{
Al Viro8687b632006-10-19 23:28:48 -07003354 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 int status = 0;
3356
3357 *res = 0;
3358 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3359 return -EIO;
3360 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003361 p = xdr_inline_decode(xdr, 8);
3362 if (unlikely(!p))
3363 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003364 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372}
3373
3374static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 int status = 0;
3378
3379 *res = 0;
3380 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 8);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3388 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003389 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003391out_overflow:
3392 print_overflow_msg(__func__, xdr);
3393 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394}
3395
3396static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3397{
Al Viro8687b632006-10-19 23:28:48 -07003398 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 int status = 0;
3400
3401 *res = 0;
3402 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3403 return -EIO;
3404 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003405 p = xdr_inline_decode(xdr, 8);
3406 if (unlikely(!p))
3407 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003408 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3410 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003411 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003413out_overflow:
3414 print_overflow_msg(__func__, xdr);
3415 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416}
3417
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003418static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3419{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003420 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003421 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003422 int status = 0;
3423
Benny Halevyc0eae662009-08-14 17:20:14 +03003424 p = xdr_inline_decode(xdr, 4);
3425 if (unlikely(!p))
3426 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003427 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003428 if (n == 0)
3429 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003430 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003431 path->ncomponents = 0;
3432 while (path->ncomponents < n) {
3433 struct nfs4_string *component = &path->components[path->ncomponents];
3434 status = decode_opaque_inline(xdr, &component->len, &component->data);
3435 if (unlikely(status != 0))
3436 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003437 if (unlikely(nfs_debug & NFSDBG_XDR))
3438 pr_cont("%s%.*s ",
3439 (path->ncomponents != n ? "/ " : ""),
3440 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003441 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3442 path->ncomponents++;
3443 else {
3444 dprintk("cannot parse %d components in path\n", n);
3445 goto out_eio;
3446 }
3447 }
3448out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003449 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003450root_path:
3451/* a root pathname is sent as a zero component4 */
3452 path->ncomponents = 1;
3453 path->components[0].len=0;
3454 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003455 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003456 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003457out_eio:
3458 dprintk(" status %d", status);
3459 status = -EIO;
3460 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003461out_overflow:
3462 print_overflow_msg(__func__, xdr);
3463 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003464}
3465
3466static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003467{
3468 int n;
Al Viro8687b632006-10-19 23:28:48 -07003469 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003470 int status = -EIO;
3471
3472 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3473 goto out;
3474 status = 0;
3475 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3476 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003477 status = -EIO;
3478 /* Ignore borken servers that return unrequested attrs */
3479 if (unlikely(res == NULL))
3480 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003481 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003482 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003483 if (unlikely(status != 0))
3484 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003485 p = xdr_inline_decode(xdr, 4);
3486 if (unlikely(!p))
3487 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003488 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003489 if (n <= 0)
3490 goto out_eio;
3491 res->nlocations = 0;
3492 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003493 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003494 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003495
Benny Halevyc0eae662009-08-14 17:20:14 +03003496 p = xdr_inline_decode(xdr, 4);
3497 if (unlikely(!p))
3498 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003499 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003500
3501 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003502 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003503 while (loc->nservers < m) {
3504 struct nfs4_string *server = &loc->servers[loc->nservers];
3505 status = decode_opaque_inline(xdr, &server->len, &server->data);
3506 if (unlikely(status != 0))
3507 goto out_eio;
3508 dprintk("%s ", server->data);
3509 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3510 loc->nservers++;
3511 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003512 unsigned int i;
3513 dprintk("%s: using first %u of %u servers "
3514 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003515 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003516 NFS4_FS_LOCATION_MAXSERVERS,
3517 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003518 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003519 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003520 char *data;
3521 status = decode_opaque_inline(xdr, &len, &data);
3522 if (unlikely(status != 0))
3523 goto out_eio;
3524 }
3525 }
3526 }
3527 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003528 if (unlikely(status != 0))
3529 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003530 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003531 res->nlocations++;
3532 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003533 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003534 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003535out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003536 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003537 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003538out_overflow:
3539 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003540out_eio:
3541 status = -EIO;
3542 goto out;
3543}
3544
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3546{
Al Viro8687b632006-10-19 23:28:48 -07003547 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 int status = 0;
3549
3550 *res = 0;
3551 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3552 return -EIO;
3553 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003554 p = xdr_inline_decode(xdr, 8);
3555 if (unlikely(!p))
3556 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003557 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3559 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003560 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003562out_overflow:
3563 print_overflow_msg(__func__, xdr);
3564 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565}
3566
3567static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3568{
Al Viro8687b632006-10-19 23:28:48 -07003569 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 int status = 0;
3571
3572 *maxlink = 1;
3573 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3574 return -EIO;
3575 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003576 p = xdr_inline_decode(xdr, 4);
3577 if (unlikely(!p))
3578 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003579 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3581 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003582 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003584out_overflow:
3585 print_overflow_msg(__func__, xdr);
3586 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587}
3588
3589static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3590{
Al Viro8687b632006-10-19 23:28:48 -07003591 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 int status = 0;
3593
3594 *maxname = 1024;
3595 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3596 return -EIO;
3597 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003598 p = xdr_inline_decode(xdr, 4);
3599 if (unlikely(!p))
3600 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003601 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3603 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003604 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003606out_overflow:
3607 print_overflow_msg(__func__, xdr);
3608 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609}
3610
3611static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3612{
Al Viro8687b632006-10-19 23:28:48 -07003613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 int status = 0;
3615
3616 *res = 1024;
3617 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3618 return -EIO;
3619 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3620 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003621 p = xdr_inline_decode(xdr, 8);
3622 if (unlikely(!p))
3623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003624 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 if (maxread > 0x7FFFFFFF)
3626 maxread = 0x7FFFFFFF;
3627 *res = (uint32_t)maxread;
3628 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3629 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003630 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003632out_overflow:
3633 print_overflow_msg(__func__, xdr);
3634 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635}
3636
3637static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3638{
Al Viro8687b632006-10-19 23:28:48 -07003639 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 int status = 0;
3641
3642 *res = 1024;
3643 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3644 return -EIO;
3645 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3646 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003647 p = xdr_inline_decode(xdr, 8);
3648 if (unlikely(!p))
3649 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003650 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 if (maxwrite > 0x7FFFFFFF)
3652 maxwrite = 0x7FFFFFFF;
3653 *res = (uint32_t)maxwrite;
3654 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3655 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003656 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003658out_overflow:
3659 print_overflow_msg(__func__, xdr);
3660 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661}
3662
Trond Myklebustbca79472009-03-11 14:10:26 -04003663static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664{
Trond Myklebustbca79472009-03-11 14:10:26 -04003665 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003666 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003667 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668
3669 *mode = 0;
3670 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3671 return -EIO;
3672 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003673 p = xdr_inline_decode(xdr, 4);
3674 if (unlikely(!p))
3675 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003676 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003677 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003679 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003681 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003682 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003683out_overflow:
3684 print_overflow_msg(__func__, xdr);
3685 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686}
3687
3688static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3689{
Al Viro8687b632006-10-19 23:28:48 -07003690 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692
3693 *nlink = 1;
3694 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3695 return -EIO;
3696 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003697 p = xdr_inline_decode(xdr, 4);
3698 if (unlikely(!p))
3699 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003700 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003702 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003704 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003705 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003706out_overflow:
3707 print_overflow_msg(__func__, xdr);
3708 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709}
3710
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003711static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003712 const struct nfs_server *server, uint32_t *uid,
3713 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714{
Al Viro8687b632006-10-19 23:28:48 -07003715 uint32_t len;
3716 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003717 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718
3719 *uid = -2;
3720 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3721 return -EIO;
3722 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003723 p = xdr_inline_decode(xdr, 4);
3724 if (unlikely(!p))
3725 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003726 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003727 p = xdr_inline_decode(xdr, len);
3728 if (unlikely(!p))
3729 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003730 if (owner_name != NULL) {
3731 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3732 if (owner_name->data != NULL) {
3733 owner_name->len = len;
3734 ret = NFS_ATTR_FATTR_OWNER_NAME;
3735 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003736 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003737 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003738 ret = NFS_ATTR_FATTR_OWNER;
3739 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003741 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003743 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003744 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3746 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003747 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003748 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003749out_overflow:
3750 print_overflow_msg(__func__, xdr);
3751 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752}
3753
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003754static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003755 const struct nfs_server *server, uint32_t *gid,
3756 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757{
Al Viro8687b632006-10-19 23:28:48 -07003758 uint32_t len;
3759 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003760 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761
3762 *gid = -2;
3763 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3764 return -EIO;
3765 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003766 p = xdr_inline_decode(xdr, 4);
3767 if (unlikely(!p))
3768 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003769 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003770 p = xdr_inline_decode(xdr, len);
3771 if (unlikely(!p))
3772 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003773 if (group_name != NULL) {
3774 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3775 if (group_name->data != NULL) {
3776 group_name->len = len;
3777 ret = NFS_ATTR_FATTR_GROUP_NAME;
3778 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003779 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003780 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 ret = NFS_ATTR_FATTR_GROUP;
3782 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003784 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003786 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003787 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003790 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003792out_overflow:
3793 print_overflow_msg(__func__, xdr);
3794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795}
3796
3797static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3798{
Al Viro8687b632006-10-19 23:28:48 -07003799 uint32_t major = 0, minor = 0;
3800 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003801 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802
3803 *rdev = MKDEV(0,0);
3804 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3805 return -EIO;
3806 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3807 dev_t tmp;
3808
Benny Halevyc0eae662009-08-14 17:20:14 +03003809 p = xdr_inline_decode(xdr, 8);
3810 if (unlikely(!p))
3811 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003812 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003813 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 tmp = MKDEV(major, minor);
3815 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3816 *rdev = tmp;
3817 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003820 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003821 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003822out_overflow:
3823 print_overflow_msg(__func__, xdr);
3824 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825}
3826
3827static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3828{
Al Viro8687b632006-10-19 23:28:48 -07003829 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 int status = 0;
3831
3832 *res = 0;
3833 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3834 return -EIO;
3835 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003836 p = xdr_inline_decode(xdr, 8);
3837 if (unlikely(!p))
3838 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003839 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3841 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003842 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003844out_overflow:
3845 print_overflow_msg(__func__, xdr);
3846 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847}
3848
3849static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3850{
Al Viro8687b632006-10-19 23:28:48 -07003851 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 int status = 0;
3853
3854 *res = 0;
3855 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3856 return -EIO;
3857 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003858 p = xdr_inline_decode(xdr, 8);
3859 if (unlikely(!p))
3860 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003861 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3863 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003864 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003866out_overflow:
3867 print_overflow_msg(__func__, xdr);
3868 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869}
3870
3871static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3872{
Al Viro8687b632006-10-19 23:28:48 -07003873 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 int status = 0;
3875
3876 *res = 0;
3877 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3878 return -EIO;
3879 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003880 p = xdr_inline_decode(xdr, 8);
3881 if (unlikely(!p))
3882 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003883 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3885 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003886 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003888out_overflow:
3889 print_overflow_msg(__func__, xdr);
3890 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891}
3892
3893static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3894{
Al Viro8687b632006-10-19 23:28:48 -07003895 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003896 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897
3898 *used = 0;
3899 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3900 return -EIO;
3901 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003902 p = xdr_inline_decode(xdr, 8);
3903 if (unlikely(!p))
3904 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003905 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003907 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003909 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003911 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003912out_overflow:
3913 print_overflow_msg(__func__, xdr);
3914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915}
3916
3917static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3918{
Al Viro8687b632006-10-19 23:28:48 -07003919 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 uint64_t sec;
3921 uint32_t nsec;
3922
Benny Halevyc0eae662009-08-14 17:20:14 +03003923 p = xdr_inline_decode(xdr, 12);
3924 if (unlikely(!p))
3925 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003926 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003927 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 time->tv_sec = (time_t)sec;
3929 time->tv_nsec = (long)nsec;
3930 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003931out_overflow:
3932 print_overflow_msg(__func__, xdr);
3933 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934}
3935
3936static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3937{
3938 int status = 0;
3939
3940 time->tv_sec = 0;
3941 time->tv_nsec = 0;
3942 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3943 return -EIO;
3944 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3945 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003946 if (status == 0)
3947 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3949 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003950 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 return status;
3952}
3953
3954static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3955{
3956 int status = 0;
3957
3958 time->tv_sec = 0;
3959 time->tv_nsec = 0;
3960 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3961 return -EIO;
3962 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3963 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003964 if (status == 0)
3965 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3967 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003968 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 return status;
3970}
3971
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003972static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3973 struct timespec *time)
3974{
3975 int status = 0;
3976
3977 time->tv_sec = 0;
3978 time->tv_nsec = 0;
3979 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3980 return -EIO;
3981 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3982 status = decode_attr_time(xdr, time);
3983 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3984 }
3985 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3986 (long)time->tv_nsec);
3987 return status;
3988}
3989
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3991{
3992 int status = 0;
3993
3994 time->tv_sec = 0;
3995 time->tv_nsec = 0;
3996 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3997 return -EIO;
3998 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3999 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004000 if (status == 0)
4001 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4003 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004004 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 return status;
4006}
4007
Al Viro8687b632006-10-19 23:28:48 -07004008static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009{
4010 unsigned int attrwords = XDR_QUADLEN(attrlen);
4011 unsigned int nwords = xdr->p - savep;
4012
4013 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004014 dprintk("%s: server returned incorrect attribute length: "
4015 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004016 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 attrwords << 2,
4018 (attrwords < nwords) ? '<' : '>',
4019 nwords << 2);
4020 return -EIO;
4021 }
4022 return 0;
4023}
4024
4025static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4026{
Al Viro8687b632006-10-19 23:28:48 -07004027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028
Benny Halevyc0eae662009-08-14 17:20:14 +03004029 p = xdr_inline_decode(xdr, 20);
4030 if (unlikely(!p))
4031 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004032 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004033 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004034 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004036out_overflow:
4037 print_overflow_msg(__func__, xdr);
4038 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039}
4040
4041static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4042{
Al Viro8687b632006-10-19 23:28:48 -07004043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 uint32_t supp, acc;
4045 int status;
4046
4047 status = decode_op_hdr(xdr, OP_ACCESS);
4048 if (status)
4049 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004050 p = xdr_inline_decode(xdr, 8);
4051 if (unlikely(!p))
4052 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004053 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004054 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 access->supported = supp;
4056 access->access = acc;
4057 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004058out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061}
4062
Benny Halevy07d30432009-08-14 17:19:52 +03004063static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064{
Al Viro8687b632006-10-19 23:28:48 -07004065 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004066
4067 p = xdr_inline_decode(xdr, len);
4068 if (likely(p)) {
4069 memcpy(buf, p, len);
4070 return 0;
4071 }
4072 print_overflow_msg(__func__, xdr);
4073 return -EIO;
4074}
4075
4076static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4077{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004078 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079}
4080
4081static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4082{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 int status;
4084
4085 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004086 if (status != -EIO)
4087 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004088 if (!status)
4089 status = decode_stateid(xdr, &res->stateid);
4090 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091}
4092
Benny Halevydb942bb2009-08-14 17:19:56 +03004093static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4094{
Chuck Levercd937102012-03-02 17:14:31 -05004095 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
4098static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4099{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 int status;
4101
4102 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004103 if (!status)
4104 status = decode_verifier(xdr, res->verf->verifier);
4105 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106}
4107
4108static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4109{
Al Viro8687b632006-10-19 23:28:48 -07004110 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 uint32_t bmlen;
4112 int status;
4113
4114 status = decode_op_hdr(xdr, OP_CREATE);
4115 if (status)
4116 return status;
4117 if ((status = decode_change_info(xdr, cinfo)))
4118 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004119 p = xdr_inline_decode(xdr, 4);
4120 if (unlikely(!p))
4121 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004122 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004123 p = xdr_inline_decode(xdr, bmlen << 2);
4124 if (likely(p))
4125 return 0;
4126out_overflow:
4127 print_overflow_msg(__func__, xdr);
4128 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129}
4130
4131static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4132{
Al Viro8687b632006-10-19 23:28:48 -07004133 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004134 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 int status;
4136
4137 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4138 goto xdr_error;
4139 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4140 goto xdr_error;
4141 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4142 goto xdr_error;
4143 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4144 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004145 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4146 &res->fh_expire_type)) != 0)
4147 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4149 goto xdr_error;
4150 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4151 goto xdr_error;
4152 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4153 goto xdr_error;
4154 status = verify_attr_len(xdr, savep, attrlen);
4155xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004156 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 return status;
4158}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004159
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4161{
Al Viro8687b632006-10-19 23:28:48 -07004162 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004163 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004165
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4167 goto xdr_error;
4168 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4169 goto xdr_error;
4170 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4171 goto xdr_error;
4172
4173 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4174 goto xdr_error;
4175 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4176 goto xdr_error;
4177 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4178 goto xdr_error;
4179 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4180 goto xdr_error;
4181 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4182 goto xdr_error;
4183 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4184 goto xdr_error;
4185
4186 status = verify_attr_len(xdr, savep, attrlen);
4187xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004188 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 return status;
4190}
4191
4192static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4193{
Al Viro8687b632006-10-19 23:28:48 -07004194 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004195 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004197
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4199 goto xdr_error;
4200 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4201 goto xdr_error;
4202 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4203 goto xdr_error;
4204
4205 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4206 goto xdr_error;
4207 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4208 goto xdr_error;
4209
4210 status = verify_attr_len(xdr, savep, attrlen);
4211xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004212 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 return status;
4214}
4215
Bryan Schumakerae42c702010-10-21 16:33:17 -04004216static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4217 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004218 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004219 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220{
Trond Myklebustbca79472009-03-11 14:10:26 -04004221 int status;
4222 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004223 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004224 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004226 status = decode_attr_type(xdr, bitmap, &type);
4227 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004229 fattr->mode = 0;
4230 if (status != 0) {
4231 fattr->mode |= nfs_type2fmt[type];
4232 fattr->valid |= status;
4233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004235 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4236 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004238 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004239
4240 status = decode_attr_size(xdr, bitmap, &fattr->size);
4241 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004243 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004244
4245 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4246 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004248 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004249
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004250 err = 0;
4251 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004252 if (status < 0)
4253 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004254 if (err == -NFS4ERR_WRONGSEC)
4255 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004256
4257 status = decode_attr_filehandle(xdr, bitmap, fh);
4258 if (status < 0)
4259 goto xdr_error;
4260
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004261 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4262 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004264 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004265
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004266 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004267 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004268 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004269 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004270
4271 status = decode_attr_mode(xdr, bitmap, &fmode);
4272 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004274 if (status != 0) {
4275 fattr->mode |= fmode;
4276 fattr->valid |= status;
4277 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004278
4279 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4280 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004282 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004283
Trond Myklebust6926afd2012-01-07 13:22:46 -05004284 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004285 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004287 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004288
Trond Myklebust6926afd2012-01-07 13:22:46 -05004289 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004290 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004292 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004293
4294 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4295 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004297 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004298
4299 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4300 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004302 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004303
4304 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4305 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004307 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004308
4309 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4310 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004312 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004313
4314 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4315 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004317 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004318
Trond Myklebust28331a42011-04-27 13:47:52 -04004319 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004320 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004321 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004322 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004323
Bryan Schumakerae42c702010-10-21 16:33:17 -04004324xdr_error:
4325 dprintk("%s: xdr returned %d\n", __func__, -status);
4326 return status;
4327}
4328
4329static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004330 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4331 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004332{
4333 __be32 *savep;
4334 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004335 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004336 int status;
4337
4338 status = decode_op_hdr(xdr, OP_GETATTR);
4339 if (status < 0)
4340 goto xdr_error;
4341
4342 status = decode_attr_bitmap(xdr, bitmap);
4343 if (status < 0)
4344 goto xdr_error;
4345
4346 status = decode_attr_length(xdr, &attrlen, &savep);
4347 if (status < 0)
4348 goto xdr_error;
4349
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004350 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004351 if (status < 0)
4352 goto xdr_error;
4353
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004354 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004356 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 return status;
4358}
4359
Bryan Schumakerae42c702010-10-21 16:33:17 -04004360static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004361 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004362{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004363 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004364}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365
Andy Adamson504913f2010-10-20 00:17:57 -04004366/*
4367 * Decode potentially multiple layout types. Currently we only support
4368 * one layout driver per file system.
4369 */
4370static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4371 uint32_t *layouttype)
4372{
4373 uint32_t *p;
4374 int num;
4375
4376 p = xdr_inline_decode(xdr, 4);
4377 if (unlikely(!p))
4378 goto out_overflow;
4379 num = be32_to_cpup(p);
4380
4381 /* pNFS is not supported by the underlying file system */
4382 if (num == 0) {
4383 *layouttype = 0;
4384 return 0;
4385 }
4386 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004387 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4388 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004389
4390 /* Decode and set first layout type, move xdr->p past unused types */
4391 p = xdr_inline_decode(xdr, num * 4);
4392 if (unlikely(!p))
4393 goto out_overflow;
4394 *layouttype = be32_to_cpup(p);
4395 return 0;
4396out_overflow:
4397 print_overflow_msg(__func__, xdr);
4398 return -EIO;
4399}
4400
4401/*
4402 * The type of file system exported.
4403 * Note we must ensure that layouttype is set in any non-error case.
4404 */
4405static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4406 uint32_t *layouttype)
4407{
4408 int status = 0;
4409
4410 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4411 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4412 return -EIO;
4413 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4414 status = decode_first_pnfs_layout_type(xdr, layouttype);
4415 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4416 } else
4417 *layouttype = 0;
4418 return status;
4419}
4420
Fred Isamandae100c2011-07-30 20:52:37 -04004421/*
4422 * The prefered block size for layout directed io
4423 */
4424static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4425 uint32_t *res)
4426{
4427 __be32 *p;
4428
4429 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4430 *res = 0;
4431 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4432 p = xdr_inline_decode(xdr, 4);
4433 if (unlikely(!p)) {
4434 print_overflow_msg(__func__, xdr);
4435 return -EIO;
4436 }
4437 *res = be32_to_cpup(p);
4438 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4439 }
4440 return 0;
4441}
4442
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4444{
Al Viro8687b632006-10-19 23:28:48 -07004445 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004446 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 int status;
4448
4449 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4450 goto xdr_error;
4451 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4452 goto xdr_error;
4453 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4454 goto xdr_error;
4455
4456 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4457
4458 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4459 goto xdr_error;
4460 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4461 goto xdr_error;
4462 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4463 goto xdr_error;
4464 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4465 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4466 goto xdr_error;
4467 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004468 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4469 if (status != 0)
4470 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004471 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4472 if (status != 0)
4473 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004474 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4475 if (status)
4476 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477
4478 status = verify_attr_len(xdr, savep, attrlen);
4479xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004480 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 return status;
4482}
4483
4484static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4485{
Al Viro8687b632006-10-19 23:28:48 -07004486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 uint32_t len;
4488 int status;
4489
Trond Myklebust99367812007-07-17 21:52:41 -04004490 /* Zero handle first to allow comparisons */
4491 memset(fh, 0, sizeof(*fh));
4492
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 status = decode_op_hdr(xdr, OP_GETFH);
4494 if (status)
4495 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496
Benny Halevyc0eae662009-08-14 17:20:14 +03004497 p = xdr_inline_decode(xdr, 4);
4498 if (unlikely(!p))
4499 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004500 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501 if (len > NFS4_FHSIZE)
4502 return -EIO;
4503 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004504 p = xdr_inline_decode(xdr, len);
4505 if (unlikely(!p))
4506 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004507 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004509out_overflow:
4510 print_overflow_msg(__func__, xdr);
4511 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512}
4513
4514static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4515{
4516 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004517
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 status = decode_op_hdr(xdr, OP_LINK);
4519 if (status)
4520 return status;
4521 return decode_change_info(xdr, cinfo);
4522}
4523
4524/*
4525 * We create the owner, so we know a proper owner.id length is 4.
4526 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004527static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004529 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004530 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004531 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004533 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004534 if (unlikely(!p))
4535 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004536 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004537 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004538 type = be32_to_cpup(p++); /* 4 byte read */
4539 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004540 fl->fl_start = (loff_t)offset;
4541 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4542 if (length == ~(uint64_t)0)
4543 fl->fl_end = OFFSET_MAX;
4544 fl->fl_type = F_WRLCK;
4545 if (type & 1)
4546 fl->fl_type = F_RDLCK;
4547 fl->fl_pid = 0;
4548 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004549 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4550 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4551 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004552 if (likely(p))
4553 return -NFS4ERR_DENIED;
4554out_overflow:
4555 print_overflow_msg(__func__, xdr);
4556 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557}
4558
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004559static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 int status;
4562
4563 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004564 if (status == -EIO)
4565 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004567 status = decode_stateid(xdr, &res->stateid);
4568 if (unlikely(status))
4569 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004571 status = decode_lock_denied(xdr, NULL);
4572 if (res->open_seqid != NULL)
4573 nfs_increment_open_seqid(status, res->open_seqid);
4574 nfs_increment_lock_seqid(status, res->lock_seqid);
4575out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 return status;
4577}
4578
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004579static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580{
4581 int status;
4582 status = decode_op_hdr(xdr, OP_LOCKT);
4583 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004584 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 return status;
4586}
4587
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004588static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 int status;
4591
4592 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004593 if (status != -EIO)
4594 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004595 if (status == 0)
4596 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 return status;
4598}
4599
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004600static int decode_release_lockowner(struct xdr_stream *xdr)
4601{
4602 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4603}
4604
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605static int decode_lookup(struct xdr_stream *xdr)
4606{
4607 return decode_op_hdr(xdr, OP_LOOKUP);
4608}
4609
4610/* This is too sick! */
4611static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4612{
Andy Adamson05d564f2008-12-23 16:06:15 -05004613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614 uint32_t limit_type, nblocks, blocksize;
4615
Benny Halevyc0eae662009-08-14 17:20:14 +03004616 p = xdr_inline_decode(xdr, 12);
4617 if (unlikely(!p))
4618 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004619 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004621 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004622 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004623 break;
4624 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004625 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004626 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004627 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 }
4629 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004630out_overflow:
4631 print_overflow_msg(__func__, xdr);
4632 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633}
4634
4635static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4636{
Andy Adamson05d564f2008-12-23 16:06:15 -05004637 __be32 *p;
4638 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004639 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
Benny Halevyc0eae662009-08-14 17:20:14 +03004641 p = xdr_inline_decode(xdr, 4);
4642 if (unlikely(!p))
4643 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004644 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4646 res->delegation_type = 0;
4647 return 0;
4648 }
Benny Halevy07d30432009-08-14 17:19:52 +03004649 status = decode_stateid(xdr, &res->delegation);
4650 if (unlikely(status))
4651 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004652 p = xdr_inline_decode(xdr, 4);
4653 if (unlikely(!p))
4654 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004655 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004656
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004658 case NFS4_OPEN_DELEGATE_READ:
4659 res->delegation_type = FMODE_READ;
4660 break;
4661 case NFS4_OPEN_DELEGATE_WRITE:
4662 res->delegation_type = FMODE_WRITE|FMODE_READ;
4663 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 return -EIO;
4665 }
David Howells7539bba2006-08-22 20:06:09 -04004666 return decode_ace(xdr, NULL, res->server->nfs_client);
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_open(struct xdr_stream *xdr, struct nfs_openres *res)
4673{
Andy Adamson05d564f2008-12-23 16:06:15 -05004674 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004675 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004676 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677
Andy Adamson05d564f2008-12-23 16:06:15 -05004678 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004679 if (status != -EIO)
4680 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004681 if (!status)
4682 status = decode_stateid(xdr, &res->stateid);
4683 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004684 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685
Andy Adamson05d564f2008-12-23 16:06:15 -05004686 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687
Benny Halevyc0eae662009-08-14 17:20:14 +03004688 p = xdr_inline_decode(xdr, 8);
4689 if (unlikely(!p))
4690 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004691 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004692 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004693 if (bmlen > 10)
4694 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695
Benny Halevyc0eae662009-08-14 17:20:14 +03004696 p = xdr_inline_decode(xdr, bmlen << 2);
4697 if (unlikely(!p))
4698 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004699 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4700 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004701 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004702 for (; i < NFS4_BITMAP_SIZE; i++)
4703 res->attrset[i] = 0;
4704
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705 return decode_delegation(xdr, res);
4706xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004707 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004709out_overflow:
4710 print_overflow_msg(__func__, xdr);
4711 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712}
4713
4714static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4715{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 int status;
4717
Andy Adamson05d564f2008-12-23 16:06:15 -05004718 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004719 if (status != -EIO)
4720 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004721 if (!status)
4722 status = decode_stateid(xdr, &res->stateid);
4723 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724}
4725
4726static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4727{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 int status;
4729
4730 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004731 if (status != -EIO)
4732 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004733 if (!status)
4734 status = decode_stateid(xdr, &res->stateid);
4735 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736}
4737
4738static int decode_putfh(struct xdr_stream *xdr)
4739{
4740 return decode_op_hdr(xdr, OP_PUTFH);
4741}
4742
4743static int decode_putrootfh(struct xdr_stream *xdr)
4744{
4745 return decode_op_hdr(xdr, OP_PUTROOTFH);
4746}
4747
4748static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4749{
4750 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004751 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 uint32_t count, eof, recvd, hdrlen;
4753 int status;
4754
4755 status = decode_op_hdr(xdr, OP_READ);
4756 if (status)
4757 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004758 p = xdr_inline_decode(xdr, 8);
4759 if (unlikely(!p))
4760 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004761 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004762 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004763 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 recvd = req->rq_rcv_buf.len - hdrlen;
4765 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004766 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 "count %u > recvd %u\n", count, recvd);
4768 count = recvd;
4769 eof = 0;
4770 }
4771 xdr_read_pages(xdr, count);
4772 res->eof = eof;
4773 res->count = count;
4774 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004775out_overflow:
4776 print_overflow_msg(__func__, xdr);
4777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778}
4779
4780static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4781{
4782 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004784 size_t hdrlen;
4785 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004786 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004787 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788
4789 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004790 if (!status)
4791 status = decode_verifier(xdr, readdir->verifier.data);
4792 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004794 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004795 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004796 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797
Benny Halevydb942bb2009-08-14 17:19:56 +03004798 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 recvd = rcvbuf->len - hdrlen;
4800 if (pglen > recvd)
4801 pglen = recvd;
4802 xdr_read_pages(xdr, pglen);
4803
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004804
Trond Myklebustac396122010-11-15 20:26:22 -05004805 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806}
4807
4808static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4809{
4810 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4811 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004812 size_t hdrlen;
4813 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004814 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 int status;
4816
4817 status = decode_op_hdr(xdr, OP_READLINK);
4818 if (status)
4819 return status;
4820
4821 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004822 p = xdr_inline_decode(xdr, 4);
4823 if (unlikely(!p))
4824 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004825 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004827 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828 return -ENAMETOOLONG;
4829 }
4830 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4831 recvd = req->rq_rcv_buf.len - hdrlen;
4832 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004833 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 "count %u > recvd %u\n", len, recvd);
4835 return -EIO;
4836 }
4837 xdr_read_pages(xdr, len);
4838 /*
4839 * The XDR encode routine has set things up so that
4840 * the link text will be copied directly into the
4841 * buffer. We just have to do overflow-checking,
4842 * and and null-terminate the text (the VFS expects
4843 * null-termination).
4844 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004845 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004847out_overflow:
4848 print_overflow_msg(__func__, xdr);
4849 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850}
4851
4852static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4853{
4854 int status;
4855
4856 status = decode_op_hdr(xdr, OP_REMOVE);
4857 if (status)
4858 goto out;
4859 status = decode_change_info(xdr, cinfo);
4860out:
4861 return status;
4862}
4863
4864static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4865 struct nfs4_change_info *new_cinfo)
4866{
4867 int status;
4868
4869 status = decode_op_hdr(xdr, OP_RENAME);
4870 if (status)
4871 goto out;
4872 if ((status = decode_change_info(xdr, old_cinfo)))
4873 goto out;
4874 status = decode_change_info(xdr, new_cinfo);
4875out:
4876 return status;
4877}
4878
4879static int decode_renew(struct xdr_stream *xdr)
4880{
4881 return decode_op_hdr(xdr, OP_RENEW);
4882}
4883
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004884static int
4885decode_restorefh(struct xdr_stream *xdr)
4886{
4887 return decode_op_hdr(xdr, OP_RESTOREFH);
4888}
4889
J. Bruce Fields029d1052005-06-22 17:16:22 +00004890static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004891 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004892{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004893 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004894 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004895 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004896 struct kvec *iov = req->rq_rcv_buf.head;
4897 int status;
4898
Andy Adamsonbf118a32011-12-07 11:55:27 -05004899 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004900 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4901 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004902 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004903 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4904 goto out;
4905 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4906 goto out;
4907
4908 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4909 return -EIO;
4910 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004911 size_t hdrlen;
4912 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004913
Andy Adamsonbf118a32011-12-07 11:55:27 -05004914 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4915 * are stored with the acl data to handle the problem of
4916 * variable length bitmaps.*/
4917 xdr->p = bm_p;
4918 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4919 res->acl_data_offset <<= 2;
4920
J. Bruce Fields029d1052005-06-22 17:16:22 +00004921 /* We ignore &savep and don't do consistency checks on
4922 * the attr length. Let userspace figure it out.... */
4923 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004924 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004925 recvd = req->rq_rcv_buf.len - hdrlen;
4926 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004927 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4928 /* getxattr interface called with a NULL buf */
4929 res->acl_len = attrlen;
4930 goto out;
4931 }
4932 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00004933 attrlen, recvd);
4934 return -EINVAL;
4935 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004936 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004937 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004938 } else
4939 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004940
4941out:
4942 return status;
4943}
4944
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945static int
4946decode_savefh(struct xdr_stream *xdr)
4947{
4948 return decode_op_hdr(xdr, OP_SAVEFH);
4949}
4950
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004951static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952{
Al Viro8687b632006-10-19 23:28:48 -07004953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 uint32_t bmlen;
4955 int status;
4956
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 status = decode_op_hdr(xdr, OP_SETATTR);
4958 if (status)
4959 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004960 p = xdr_inline_decode(xdr, 4);
4961 if (unlikely(!p))
4962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004963 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004964 p = xdr_inline_decode(xdr, bmlen << 2);
4965 if (likely(p))
4966 return 0;
4967out_overflow:
4968 print_overflow_msg(__func__, xdr);
4969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970}
4971
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004972static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973{
Al Viro8687b632006-10-19 23:28:48 -07004974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 uint32_t opnum;
4976 int32_t nfserr;
4977
Benny Halevyc0eae662009-08-14 17:20:14 +03004978 p = xdr_inline_decode(xdr, 8);
4979 if (unlikely(!p))
4980 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004981 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004983 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004984 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 return -EIO;
4986 }
Benny Halevycccddf42009-08-14 17:20:19 +03004987 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004989 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4990 if (unlikely(!p))
4991 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004992 p = xdr_decode_hyper(p, &res->clientid);
4993 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 } else if (nfserr == NFSERR_CLID_INUSE) {
4995 uint32_t len;
4996
4997 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004998 p = xdr_inline_decode(xdr, 4);
4999 if (unlikely(!p))
5000 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005001 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, len);
5003 if (unlikely(!p))
5004 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005
5006 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005007 p = xdr_inline_decode(xdr, 4);
5008 if (unlikely(!p))
5009 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005010 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005011 p = xdr_inline_decode(xdr, len);
5012 if (unlikely(!p))
5013 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014 return -NFSERR_CLID_INUSE;
5015 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005016 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017
5018 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005019out_overflow:
5020 print_overflow_msg(__func__, xdr);
5021 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022}
5023
5024static int decode_setclientid_confirm(struct xdr_stream *xdr)
5025{
5026 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5027}
5028
5029static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5030{
Al Viro8687b632006-10-19 23:28:48 -07005031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 int status;
5033
5034 status = decode_op_hdr(xdr, OP_WRITE);
5035 if (status)
5036 return status;
5037
Benny Halevyc0eae662009-08-14 17:20:14 +03005038 p = xdr_inline_decode(xdr, 16);
5039 if (unlikely(!p))
5040 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005041 res->count = be32_to_cpup(p++);
5042 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005043 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005045out_overflow:
5046 print_overflow_msg(__func__, xdr);
5047 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048}
5049
5050static int decode_delegreturn(struct xdr_stream *xdr)
5051{
5052 return decode_op_hdr(xdr, OP_DELEGRETURN);
5053}
5054
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005055static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5056{
5057 __be32 *p;
5058
5059 p = xdr_inline_decode(xdr, 4);
5060 if (unlikely(!p))
5061 goto out_overflow;
5062 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5063 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5064 goto out_err;
5065
5066 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5067 if (unlikely(!p))
5068 goto out_overflow;
5069 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5070
5071 p = xdr_inline_decode(xdr, 8);
5072 if (unlikely(!p))
5073 goto out_overflow;
5074 flavor->gss.qop4 = be32_to_cpup(p++);
5075 flavor->gss.service = be32_to_cpup(p);
5076
5077 return 0;
5078
5079out_overflow:
5080 print_overflow_msg(__func__, xdr);
5081 return -EIO;
5082out_err:
5083 return -EINVAL;
5084}
5085
5086static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5087{
5088 struct nfs4_secinfo_flavor *sec_flavor;
5089 int status;
5090 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005091 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005092
5093 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005094 if (status)
5095 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005096 p = xdr_inline_decode(xdr, 4);
5097 if (unlikely(!p))
5098 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005099
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005100 res->flavors->num_flavors = 0;
5101 num_flavors = be32_to_cpup(p);
5102
5103 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005104 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005105 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005106 break;
5107
5108 p = xdr_inline_decode(xdr, 4);
5109 if (unlikely(!p))
5110 goto out_overflow;
5111 sec_flavor->flavor = be32_to_cpup(p);
5112
5113 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005114 status = decode_secinfo_gss(xdr, sec_flavor);
5115 if (status)
5116 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005117 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005118 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005119 }
5120
Bryan Schumaker613e9012011-04-27 15:28:44 -04005121out:
5122 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005123out_overflow:
5124 print_overflow_msg(__func__, xdr);
5125 return -EIO;
5126}
5127
Benny Halevy99fe60d2009-04-01 09:22:29 -04005128#if defined(CONFIG_NFS_V4_1)
5129static int decode_exchange_id(struct xdr_stream *xdr,
5130 struct nfs41_exchange_id_res *res)
5131{
5132 __be32 *p;
5133 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005134 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005135 int status;
5136 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005137 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005138
5139 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5140 if (status)
5141 return status;
5142
Benny Halevyc0eae662009-08-14 17:20:14 +03005143 p = xdr_inline_decode(xdr, 8);
5144 if (unlikely(!p))
5145 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005146 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005147 p = xdr_inline_decode(xdr, 12);
5148 if (unlikely(!p))
5149 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005150 clp->cl_seqid = be32_to_cpup(p++);
5151 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005152
5153 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005154 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005155 if (dummy != SP4_NONE)
5156 return -EIO;
5157
5158 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005159 p = xdr_inline_decode(xdr, 8);
5160 if (unlikely(!p))
5161 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005162
5163 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005164 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5165 if (unlikely(status))
5166 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005167
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005168 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005169 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5170 if (unlikely(status))
5171 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005172
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005173 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5174 return -EIO;
5175
5176 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5177 res->server_scope->server_scope_sz = dummy;
5178
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005179 /* Implementation Id */
5180 p = xdr_inline_decode(xdr, 4);
5181 if (unlikely(!p))
5182 goto out_overflow;
5183 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005184
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005185 if (impl_id_count) {
5186 /* nii_domain */
5187 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5188 if (unlikely(status))
5189 return status;
5190 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5191 return -EIO;
5192 memcpy(res->impl_id->domain, dummy_str, dummy);
5193
5194 /* nii_name */
5195 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5196 if (unlikely(status))
5197 return status;
5198 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5199 return -EIO;
5200 memcpy(res->impl_id->name, dummy_str, dummy);
5201
5202 /* nii_date */
5203 p = xdr_inline_decode(xdr, 12);
5204 if (unlikely(!p))
5205 goto out_overflow;
5206 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5207 res->impl_id->date.nseconds = be32_to_cpup(p);
5208
5209 /* if there's more than one entry, ignore the rest */
5210 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005211 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005212out_overflow:
5213 print_overflow_msg(__func__, xdr);
5214 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005215}
Andy Adamsonfc931582009-04-01 09:22:31 -04005216
5217static int decode_chan_attrs(struct xdr_stream *xdr,
5218 struct nfs4_channel_attrs *attrs)
5219{
5220 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005221 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005222
Benny Halevyc0eae662009-08-14 17:20:14 +03005223 p = xdr_inline_decode(xdr, 28);
5224 if (unlikely(!p))
5225 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005226 val = be32_to_cpup(p++); /* headerpadsz */
5227 if (val)
5228 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005229 attrs->max_rqst_sz = be32_to_cpup(p++);
5230 attrs->max_resp_sz = be32_to_cpup(p++);
5231 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5232 attrs->max_ops = be32_to_cpup(p++);
5233 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005234 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005235 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005236 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5237 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005238 return -EINVAL;
5239 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005240 if (nr_attrs == 1) {
5241 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5242 if (unlikely(!p))
5243 goto out_overflow;
5244 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005245 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005246out_overflow:
5247 print_overflow_msg(__func__, xdr);
5248 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005249}
5250
Benny Halevye78291e2009-08-14 17:20:00 +03005251static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5252{
5253 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005254}
5255
5256static int decode_create_session(struct xdr_stream *xdr,
5257 struct nfs41_create_session_res *res)
5258{
5259 __be32 *p;
5260 int status;
5261 struct nfs_client *clp = res->client;
5262 struct nfs4_session *session = clp->cl_session;
5263
5264 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005265 if (!status)
5266 status = decode_sessionid(xdr, &session->sess_id);
5267 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005268 return status;
5269
Andy Adamsonfc931582009-04-01 09:22:31 -04005270 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005271 p = xdr_inline_decode(xdr, 8);
5272 if (unlikely(!p))
5273 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005274 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005275 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005276
5277 /* Channel attributes */
5278 status = decode_chan_attrs(xdr, &session->fc_attrs);
5279 if (!status)
5280 status = decode_chan_attrs(xdr, &session->bc_attrs);
5281 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005282out_overflow:
5283 print_overflow_msg(__func__, xdr);
5284 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005285}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005286
5287static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5288{
5289 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5290}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005291
5292static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5293{
5294 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5295}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005296#endif /* CONFIG_NFS_V4_1 */
5297
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005298static int decode_sequence(struct xdr_stream *xdr,
5299 struct nfs4_sequence_res *res,
5300 struct rpc_rqst *rqstp)
5301{
5302#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005303 struct nfs4_sessionid id;
5304 u32 dummy;
5305 int status;
5306 __be32 *p;
5307
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005308 if (!res->sr_session)
5309 return 0;
5310
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005311 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005312 if (!status)
5313 status = decode_sessionid(xdr, &id);
5314 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005315 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005316
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005317 /*
5318 * If the server returns different values for sessionID, slotID or
5319 * sequence number, the server is looney tunes.
5320 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005321 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005322
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005323 if (memcmp(id.data, res->sr_session->sess_id.data,
5324 NFS4_MAX_SESSIONID_LEN)) {
5325 dprintk("%s Invalid session id\n", __func__);
5326 goto out_err;
5327 }
Benny Halevye78291e2009-08-14 17:20:00 +03005328
Benny Halevyc0eae662009-08-14 17:20:14 +03005329 p = xdr_inline_decode(xdr, 20);
5330 if (unlikely(!p))
5331 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005332
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005333 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005334 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005335 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005336 dprintk("%s Invalid sequence number\n", __func__);
5337 goto out_err;
5338 }
5339 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005340 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005341 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005342 dprintk("%s Invalid slot id\n", __func__);
5343 goto out_err;
5344 }
5345 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005346 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005347 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005348 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005349 /* result flags */
5350 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005351 status = 0;
5352out_err:
5353 res->sr_status = status;
5354 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005355out_overflow:
5356 print_overflow_msg(__func__, xdr);
5357 status = -EIO;
5358 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005359#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005360 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005361#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005362}
5363
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005364#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005365/*
5366 * TODO: Need to handle case when EOF != true;
5367 */
5368static int decode_getdevicelist(struct xdr_stream *xdr,
5369 struct pnfs_devicelist *res)
5370{
5371 __be32 *p;
5372 int status, i;
5373 struct nfs_writeverf verftemp;
5374
5375 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5376 if (status)
5377 return status;
5378
5379 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5380 if (unlikely(!p))
5381 goto out_overflow;
5382
5383 /* TODO: Skip cookie for now */
5384 p += 2;
5385
5386 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005387 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005388
5389 res->num_devs = be32_to_cpup(p);
5390
5391 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5392
5393 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005394 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005395 __func__, res->num_devs);
5396 return -EIO;
5397 }
5398
5399 p = xdr_inline_decode(xdr,
5400 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5401 if (unlikely(!p))
5402 goto out_overflow;
5403 for (i = 0; i < res->num_devs; i++)
5404 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5405 NFS4_DEVICEID4_SIZE);
5406 res->eof = be32_to_cpup(p);
5407 return 0;
5408out_overflow:
5409 print_overflow_msg(__func__, xdr);
5410 return -EIO;
5411}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005412
5413static int decode_getdeviceinfo(struct xdr_stream *xdr,
5414 struct pnfs_device *pdev)
5415{
5416 __be32 *p;
5417 uint32_t len, type;
5418 int status;
5419
5420 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5421 if (status) {
5422 if (status == -ETOOSMALL) {
5423 p = xdr_inline_decode(xdr, 4);
5424 if (unlikely(!p))
5425 goto out_overflow;
5426 pdev->mincount = be32_to_cpup(p);
5427 dprintk("%s: Min count too small. mincnt = %u\n",
5428 __func__, pdev->mincount);
5429 }
5430 return status;
5431 }
5432
5433 p = xdr_inline_decode(xdr, 8);
5434 if (unlikely(!p))
5435 goto out_overflow;
5436 type = be32_to_cpup(p++);
5437 if (type != pdev->layout_type) {
5438 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5439 __func__, pdev->layout_type, type);
5440 return -EINVAL;
5441 }
5442 /*
5443 * Get the length of the opaque device_addr4. xdr_read_pages places
5444 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5445 * and places the remaining xdr data in xdr_buf->tail
5446 */
5447 pdev->mincount = be32_to_cpup(p);
5448 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5449
5450 /* Parse notification bitmap, verifying that it is zero. */
5451 p = xdr_inline_decode(xdr, 4);
5452 if (unlikely(!p))
5453 goto out_overflow;
5454 len = be32_to_cpup(p);
5455 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005456 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005457
5458 p = xdr_inline_decode(xdr, 4 * len);
5459 if (unlikely(!p))
5460 goto out_overflow;
5461 for (i = 0; i < len; i++, p++) {
5462 if (be32_to_cpup(p)) {
5463 dprintk("%s: notifications not supported\n",
5464 __func__);
5465 return -EIO;
5466 }
5467 }
5468 }
5469 return 0;
5470out_overflow:
5471 print_overflow_msg(__func__, xdr);
5472 return -EIO;
5473}
5474
5475static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5476 struct nfs4_layoutget_res *res)
5477{
5478 __be32 *p;
5479 int status;
5480 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005481 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5482 struct kvec *iov = rcvbuf->head;
5483 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005484
5485 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5486 if (status)
5487 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005488 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005489 if (unlikely(!p))
5490 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005491 res->return_on_close = be32_to_cpup(p);
5492 decode_stateid(xdr, &res->stateid);
5493 p = xdr_inline_decode(xdr, 4);
5494 if (unlikely(!p))
5495 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005496 layout_count = be32_to_cpup(p);
5497 if (!layout_count) {
5498 dprintk("%s: server responded with empty layout array\n",
5499 __func__);
5500 return -EINVAL;
5501 }
5502
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005503 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005504 if (unlikely(!p))
5505 goto out_overflow;
5506 p = xdr_decode_hyper(p, &res->range.offset);
5507 p = xdr_decode_hyper(p, &res->range.length);
5508 res->range.iomode = be32_to_cpup(p++);
5509 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005510 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005511
5512 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5513 __func__,
5514 (unsigned long)res->range.offset,
5515 (unsigned long)res->range.length,
5516 res->range.iomode,
5517 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005518 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005519
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005520 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5521 recvd = req->rq_rcv_buf.len - hdrlen;
5522 if (res->layoutp->len > recvd) {
5523 dprintk("NFS: server cheating in layoutget reply: "
5524 "layout len %u > recvd %u\n",
5525 res->layoutp->len, recvd);
5526 return -EINVAL;
5527 }
5528
5529 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005530
5531 if (layout_count > 1) {
5532 /* We only handle a length one array at the moment. Any
5533 * further entries are just ignored. Note that this means
5534 * the client may see a response that is less than the
5535 * minimum it requested.
5536 */
5537 dprintk("%s: server responded with %d layouts, dropping tail\n",
5538 __func__, layout_count);
5539 }
5540
5541 return 0;
5542out_overflow:
5543 print_overflow_msg(__func__, xdr);
5544 return -EIO;
5545}
Andy Adamson863a3c62011-03-23 13:27:54 +00005546
Benny Halevycbe82602011-05-22 19:52:37 +03005547static int decode_layoutreturn(struct xdr_stream *xdr,
5548 struct nfs4_layoutreturn_res *res)
5549{
5550 __be32 *p;
5551 int status;
5552
5553 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5554 if (status)
5555 return status;
5556 p = xdr_inline_decode(xdr, 4);
5557 if (unlikely(!p))
5558 goto out_overflow;
5559 res->lrs_present = be32_to_cpup(p);
5560 if (res->lrs_present)
5561 status = decode_stateid(xdr, &res->stateid);
5562 return status;
5563out_overflow:
5564 print_overflow_msg(__func__, xdr);
5565 return -EIO;
5566}
5567
Andy Adamson863a3c62011-03-23 13:27:54 +00005568static int decode_layoutcommit(struct xdr_stream *xdr,
5569 struct rpc_rqst *req,
5570 struct nfs4_layoutcommit_res *res)
5571{
5572 __be32 *p;
5573 __u32 sizechanged;
5574 int status;
5575
5576 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005577 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005578 if (status)
5579 return status;
5580
5581 p = xdr_inline_decode(xdr, 4);
5582 if (unlikely(!p))
5583 goto out_overflow;
5584 sizechanged = be32_to_cpup(p);
5585
5586 if (sizechanged) {
5587 /* throw away new size */
5588 p = xdr_inline_decode(xdr, 8);
5589 if (unlikely(!p))
5590 goto out_overflow;
5591 }
5592 return 0;
5593out_overflow:
5594 print_overflow_msg(__func__, xdr);
5595 return -EIO;
5596}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005597
5598static int decode_test_stateid(struct xdr_stream *xdr,
5599 struct nfs41_test_stateid_res *res)
5600{
5601 __be32 *p;
5602 int status;
5603 int num_res;
5604
5605 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5606 if (status)
5607 return status;
5608
5609 p = xdr_inline_decode(xdr, 4);
5610 if (unlikely(!p))
5611 goto out_overflow;
5612 num_res = be32_to_cpup(p++);
5613 if (num_res != 1)
5614 goto out;
5615
5616 p = xdr_inline_decode(xdr, 4);
5617 if (unlikely(!p))
5618 goto out_overflow;
5619 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005620
5621 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005622out_overflow:
5623 print_overflow_msg(__func__, xdr);
5624out:
5625 return -EIO;
5626}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005627
5628static int decode_free_stateid(struct xdr_stream *xdr,
5629 struct nfs41_free_stateid_res *res)
5630{
5631 __be32 *p;
5632 int status;
5633
5634 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5635 if (status)
5636 return status;
5637
5638 p = xdr_inline_decode(xdr, 4);
5639 if (unlikely(!p))
5640 goto out_overflow;
5641 res->status = be32_to_cpup(p++);
5642 return res->status;
5643out_overflow:
5644 print_overflow_msg(__func__, xdr);
5645 return -EIO;
5646}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005647#endif /* CONFIG_NFS_V4_1 */
5648
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649/*
Benny Halevy49c25592008-12-23 16:06:16 -05005650 * END OF "GENERIC" DECODE ROUTINES.
5651 */
5652
5653/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654 * Decode OPEN_DOWNGRADE response
5655 */
Chuck Leverbf269552010-12-14 14:59:29 +00005656static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5657 struct xdr_stream *xdr,
5658 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659{
Andy Adamson05d564f2008-12-23 16:06:15 -05005660 struct compound_hdr hdr;
5661 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662
Chuck Leverbf269552010-12-14 14:59:29 +00005663 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005664 if (status)
5665 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005666 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005667 if (status)
5668 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005669 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005670 if (status)
5671 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005672 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005673 if (status != 0)
5674 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005675 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005677 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678}
5679
5680/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681 * Decode ACCESS response
5682 */
Chuck Leverbf269552010-12-14 14:59:29 +00005683static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5684 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 struct compound_hdr hdr;
5687 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005688
Chuck Leverbf269552010-12-14 14:59:29 +00005689 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005690 if (status)
5691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005692 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005693 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005695 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005696 if (status != 0)
5697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005698 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005699 if (status != 0)
5700 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005701 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702out:
5703 return status;
5704}
5705
5706/*
5707 * Decode LOOKUP response
5708 */
Chuck Leverbf269552010-12-14 14:59:29 +00005709static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5710 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712 struct compound_hdr hdr;
5713 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005714
Chuck Leverbf269552010-12-14 14:59:29 +00005715 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005716 if (status)
5717 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005718 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005719 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005721 status = decode_putfh(xdr);
5722 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005724 status = decode_lookup(xdr);
5725 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005727 status = decode_getfh(xdr, res->fh);
5728 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005730 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731out:
5732 return status;
5733}
5734
5735/*
5736 * Decode LOOKUP_ROOT response
5737 */
Chuck Leverbf269552010-12-14 14:59:29 +00005738static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5739 struct xdr_stream *xdr,
5740 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 struct compound_hdr hdr;
5743 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005744
Chuck Leverbf269552010-12-14 14:59:29 +00005745 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005746 if (status)
5747 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005748 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005749 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005751 status = decode_putrootfh(xdr);
5752 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005754 status = decode_getfh(xdr, res->fh);
5755 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005756 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757out:
5758 return status;
5759}
5760
5761/*
5762 * Decode REMOVE response
5763 */
Chuck Leverbf269552010-12-14 14:59:29 +00005764static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5765 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 struct compound_hdr hdr;
5768 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005769
Chuck Leverbf269552010-12-14 14:59:29 +00005770 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005771 if (status)
5772 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005773 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005774 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005776 status = decode_putfh(xdr);
5777 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005778 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_remove(xdr, &res->cinfo);
5780 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005781 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005782 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783out:
5784 return status;
5785}
5786
5787/*
5788 * Decode RENAME response
5789 */
Chuck Leverbf269552010-12-14 14:59:29 +00005790static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5791 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005792{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 struct compound_hdr hdr;
5794 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005795
Chuck Leverbf269552010-12-14 14:59:29 +00005796 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005797 if (status)
5798 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005799 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005800 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005802 status = decode_putfh(xdr);
5803 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005805 status = decode_savefh(xdr);
5806 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_putfh(xdr);
5809 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5812 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005813 goto out;
5814 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005815 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005817 status = decode_restorefh(xdr);
5818 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005819 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005820 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821out:
5822 return status;
5823}
5824
5825/*
5826 * Decode LINK response
5827 */
Chuck Leverbf269552010-12-14 14:59:29 +00005828static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5829 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 struct compound_hdr hdr;
5832 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005833
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005835 if (status)
5836 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005837 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005838 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_putfh(xdr);
5841 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005843 status = decode_savefh(xdr);
5844 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005846 status = decode_putfh(xdr);
5847 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005849 status = decode_link(xdr, &res->cinfo);
5850 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005851 goto out;
5852 /*
5853 * Note order: OP_LINK leaves the directory as the current
5854 * filehandle.
5855 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005856 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005857 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_restorefh(xdr);
5859 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005860 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005861 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862out:
5863 return status;
5864}
5865
5866/*
5867 * Decode CREATE response
5868 */
Chuck Leverbf269552010-12-14 14:59:29 +00005869static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5870 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872 struct compound_hdr hdr;
5873 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005874
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005876 if (status)
5877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005879 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005881 status = decode_putfh(xdr);
5882 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005884 status = decode_savefh(xdr);
5885 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_create(xdr, &res->dir_cinfo);
5888 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_getfh(xdr, res->fh);
5891 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005893 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_restorefh(xdr);
5896 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005897 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005898 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899out:
5900 return status;
5901}
5902
5903/*
5904 * Decode SYMLINK response
5905 */
Chuck Leverbf269552010-12-14 14:59:29 +00005906static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5907 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908{
Chuck Leverbf269552010-12-14 14:59:29 +00005909 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910}
5911
5912/*
5913 * Decode GETATTR response
5914 */
Chuck Leverbf269552010-12-14 14:59:29 +00005915static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5916 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 struct compound_hdr hdr;
5919 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005920
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922 if (status)
5923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005924 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005925 if (status)
5926 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005927 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928 if (status)
5929 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005930 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931out:
5932 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933}
5934
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005935/*
5936 * Encode an SETACL request
5937 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005938static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5939 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005940{
Andy Adamson05d564f2008-12-23 16:06:15 -05005941 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005942 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005943 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005944
Chuck Lever9f06c712010-12-14 14:59:18 +00005945 encode_compound_hdr(xdr, req, &hdr);
5946 encode_sequence(xdr, &args->seq_args, &hdr);
5947 encode_putfh(xdr, args->fh, &hdr);
5948 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005949 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005950}
Andy Adamson05d564f2008-12-23 16:06:15 -05005951
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005952/*
5953 * Decode SETACL response
5954 */
5955static int
Chuck Leverbf269552010-12-14 14:59:29 +00005956nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005957 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005958{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005959 struct compound_hdr hdr;
5960 int status;
5961
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005963 if (status)
5964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005966 if (status)
5967 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005969 if (status)
5970 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005972out:
5973 return status;
5974}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975
5976/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005977 * Decode GETACL response
5978 */
5979static int
Chuck Leverbf269552010-12-14 14:59:29 +00005980nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005981 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005982{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005983 struct compound_hdr hdr;
5984 int status;
5985
Trond Myklebust331818f2012-02-03 18:30:53 -05005986 if (res->acl_scratch != NULL) {
5987 void *p = page_address(res->acl_scratch);
5988 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5989 }
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005991 if (status)
5992 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005994 if (status)
5995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005997 if (status)
5998 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005999 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006000
6001out:
6002 return status;
6003}
6004
6005/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006 * Decode CLOSE response
6007 */
Chuck Leverbf269552010-12-14 14:59:29 +00006008static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6009 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010{
Andy Adamson05d564f2008-12-23 16:06:15 -05006011 struct compound_hdr hdr;
6012 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006015 if (status)
6016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006018 if (status)
6019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006021 if (status)
6022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006024 if (status != 0)
6025 goto out;
6026 /*
6027 * Note: Server may do delete on close for this file
6028 * in which case the getattr call will fail with
6029 * an ESTALE error. Shouldn't be a problem,
6030 * though, since fattr->valid will remain unset.
6031 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006032 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006034 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035}
6036
6037/*
6038 * Decode OPEN response
6039 */
Chuck Leverbf269552010-12-14 14:59:29 +00006040static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6041 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042{
Andy Adamson05d564f2008-12-23 16:06:15 -05006043 struct compound_hdr hdr;
6044 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006047 if (status)
6048 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006053 if (status)
6054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006056 if (status)
6057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006059 if (status)
6060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006061 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006063 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006066 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006067 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006068out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006069 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070}
6071
6072/*
6073 * Decode OPEN_CONFIRM response
6074 */
Chuck Leverbf269552010-12-14 14:59:29 +00006075static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6076 struct xdr_stream *xdr,
6077 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078{
Andy Adamson05d564f2008-12-23 16:06:15 -05006079 struct compound_hdr hdr;
6080 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006083 if (status)
6084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006086 if (status)
6087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006090 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091}
6092
6093/*
6094 * Decode OPEN response
6095 */
Chuck Leverbf269552010-12-14 14:59:29 +00006096static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6097 struct xdr_stream *xdr,
6098 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099{
Andy Adamson05d564f2008-12-23 16:06:15 -05006100 struct compound_hdr hdr;
6101 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006104 if (status)
6105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006107 if (status)
6108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006110 if (status)
6111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006113 if (status)
6114 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006115 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006117 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118}
6119
6120/*
6121 * Decode SETATTR response
6122 */
Chuck Leverbf269552010-12-14 14:59:29 +00006123static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6124 struct xdr_stream *xdr,
6125 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126{
Andy Adamson05d564f2008-12-23 16:06:15 -05006127 struct compound_hdr hdr;
6128 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006140 if (status)
6141 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006142 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006144 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145}
6146
6147/*
6148 * Decode LOCK response
6149 */
Chuck Leverbf269552010-12-14 14:59:29 +00006150static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6151 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153 struct compound_hdr hdr;
6154 int status;
6155
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 if (status)
6158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006160 if (status)
6161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163 if (status)
6164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166out:
6167 return status;
6168}
6169
6170/*
6171 * Decode LOCKT response
6172 */
Chuck Leverbf269552010-12-14 14:59:29 +00006173static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6174 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176 struct compound_hdr hdr;
6177 int status;
6178
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 if (status)
6181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006183 if (status)
6184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186 if (status)
6187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189out:
6190 return status;
6191}
6192
6193/*
6194 * Decode LOCKU response
6195 */
Chuck Leverbf269552010-12-14 14:59:29 +00006196static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6197 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199 struct compound_hdr hdr;
6200 int status;
6201
Chuck Leverbf269552010-12-14 14:59:29 +00006202 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 if (status)
6204 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006206 if (status)
6207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 if (status)
6210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212out:
6213 return status;
6214}
6215
Chuck Leverbf269552010-12-14 14:59:29 +00006216static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6217 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006218{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006219 struct compound_hdr hdr;
6220 int status;
6221
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006223 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006224 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006225 return status;
6226}
6227
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228/*
6229 * Decode READLINK response
6230 */
Chuck Leverbf269552010-12-14 14:59:29 +00006231static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6232 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006233 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 struct compound_hdr hdr;
6236 int status;
6237
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006242 if (status)
6243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 if (status)
6246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248out:
6249 return status;
6250}
6251
6252/*
6253 * Decode READDIR response
6254 */
Chuck Leverbf269552010-12-14 14:59:29 +00006255static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6256 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 struct compound_hdr hdr;
6259 int status;
6260
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262 if (status)
6263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006265 if (status)
6266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268 if (status)
6269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271out:
6272 return status;
6273}
6274
6275/*
6276 * Decode Read response
6277 */
Chuck Leverbf269552010-12-14 14:59:29 +00006278static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 struct compound_hdr hdr;
6282 int status;
6283
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006288 if (status)
6289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 if (status)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 if (!status)
6295 status = res->count;
6296out:
6297 return status;
6298}
6299
6300/*
6301 * Decode WRITE response
6302 */
Chuck Leverbf269552010-12-14 14:59:29 +00006303static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6304 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 struct compound_hdr hdr;
6307 int status;
6308
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 if (status)
6311 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006313 if (status)
6314 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 if (status)
6317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006319 if (status)
6320 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006321 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006322 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 if (!status)
6324 status = res->count;
6325out:
6326 return status;
6327}
6328
6329/*
6330 * Decode COMMIT response
6331 */
Chuck Leverbf269552010-12-14 14:59:29 +00006332static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6333 struct nfs_writeres *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_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006348 if (status)
6349 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006350 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006351 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352out:
6353 return status;
6354}
6355
6356/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006357 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 */
Chuck Leverbf269552010-12-14 14:59:29 +00006359static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006360 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 struct compound_hdr hdr;
6363 int status;
6364
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006368 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 return status;
6373}
6374
6375/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006376 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 */
Chuck Leverbf269552010-12-14 14:59:29 +00006378static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006379 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 struct compound_hdr hdr;
6382 int status;
6383
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006387 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 return status;
6392}
6393
6394/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006395 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 */
Chuck Leverbf269552010-12-14 14:59:29 +00006397static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006398 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 struct compound_hdr hdr;
6401 int status;
6402
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006406 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 return status;
6411}
6412
6413/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006414 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 */
Chuck Leverbf269552010-12-14 14:59:29 +00006416static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6417 struct xdr_stream *xdr,
6418 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 struct compound_hdr hdr;
6421 int status;
6422
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006424 if (status)
6425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006426 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006427 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_putfh(xdr);
6430 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006432 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433out:
6434 return status;
6435}
6436
6437/*
6438 * Decode RENEW response
6439 */
Chuck Leverbf269552010-12-14 14:59:29 +00006440static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6441 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 struct compound_hdr hdr;
6444 int status;
6445
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 return status;
6450}
6451
6452/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006453 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 */
Chuck Leverbf269552010-12-14 14:59:29 +00006455static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6456 struct xdr_stream *xdr,
6457 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 struct compound_hdr hdr;
6460 int status;
6461
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 return status;
6466}
6467
6468/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006469 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 */
Chuck Leverbf269552010-12-14 14:59:29 +00006471static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6472 struct xdr_stream *xdr,
6473 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 struct compound_hdr hdr;
6476 int status;
6477
Chuck Leverbf269552010-12-14 14:59:29 +00006478 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006482 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 return status;
6486}
6487
6488/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006489 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 */
Chuck Leverbf269552010-12-14 14:59:29 +00006491static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6492 struct xdr_stream *xdr,
6493 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 struct compound_hdr hdr;
6496 int status;
6497
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006499 if (status)
6500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006502 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006505 if (status != 0)
6506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006508 if (status != 0)
6509 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006510 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006511out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512 return status;
6513}
6514
Trond Myklebust683b57b2006-06-09 09:34:22 -04006515/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006516 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006517 */
Chuck Leverbf269552010-12-14 14:59:29 +00006518static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6519 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006520 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006521{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006522 struct compound_hdr hdr;
6523 int status;
6524
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006526 if (status)
6527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006529 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_putfh(xdr);
6532 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_lookup(xdr);
6535 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006537 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006538 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6539 NULL, res->fs_locations,
6540 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006541out:
6542 return status;
6543}
6544
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006545/*
6546 * Decode SECINFO response
6547 */
6548static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6549 struct xdr_stream *xdr,
6550 struct nfs4_secinfo_res *res)
6551{
6552 struct compound_hdr hdr;
6553 int status;
6554
6555 status = decode_compound_hdr(xdr, &hdr);
6556 if (status)
6557 goto out;
6558 status = decode_sequence(xdr, &res->seq_res, rqstp);
6559 if (status)
6560 goto out;
6561 status = decode_putfh(xdr);
6562 if (status)
6563 goto out;
6564 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006565out:
6566 return status;
6567}
6568
Benny Halevy99fe60d2009-04-01 09:22:29 -04006569#if defined(CONFIG_NFS_V4_1)
6570/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006571 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006572 */
Chuck Leverbf269552010-12-14 14:59:29 +00006573static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6574 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006575 void *res)
6576{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006577 struct compound_hdr hdr;
6578 int status;
6579
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006581 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006583 return status;
6584}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006585
6586/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006587 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006588 */
Chuck Leverbf269552010-12-14 14:59:29 +00006589static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6590 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006591 struct nfs41_create_session_res *res)
6592{
Andy Adamsonfc931582009-04-01 09:22:31 -04006593 struct compound_hdr hdr;
6594 int status;
6595
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006597 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006599 return status;
6600}
6601
6602/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006603 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006604 */
Chuck Leverbf269552010-12-14 14:59:29 +00006605static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6606 struct xdr_stream *xdr,
6607 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006608{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006609 struct compound_hdr hdr;
6610 int status;
6611
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006613 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006614 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006615 return status;
6616}
6617
6618/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006619 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006620 */
Chuck Leverbf269552010-12-14 14:59:29 +00006621static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6622 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006623 struct nfs4_sequence_res *res)
6624{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006625 struct compound_hdr hdr;
6626 int status;
6627
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006629 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006631 return status;
6632}
6633
6634/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006635 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006636 */
Chuck Leverbf269552010-12-14 14:59:29 +00006637static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6638 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006639 struct nfs4_get_lease_time_res *res)
6640{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006641 struct compound_hdr hdr;
6642 int status;
6643
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006645 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006647 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006649 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006651 return status;
6652}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006653
6654/*
6655 * Decode RECLAIM_COMPLETE response
6656 */
Chuck Leverbf269552010-12-14 14:59:29 +00006657static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6658 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006659 struct nfs41_reclaim_complete_res *res)
6660{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006661 struct compound_hdr hdr;
6662 int status;
6663
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006665 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006667 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006668 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006669 return status;
6670}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006671
6672/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006673 * Decode GETDEVICELIST response
6674 */
6675static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6676 struct xdr_stream *xdr,
6677 struct nfs4_getdevicelist_res *res)
6678{
6679 struct compound_hdr hdr;
6680 int status;
6681
6682 dprintk("encoding getdevicelist!\n");
6683
6684 status = decode_compound_hdr(xdr, &hdr);
6685 if (status != 0)
6686 goto out;
6687 status = decode_sequence(xdr, &res->seq_res, rqstp);
6688 if (status != 0)
6689 goto out;
6690 status = decode_putfh(xdr);
6691 if (status != 0)
6692 goto out;
6693 status = decode_getdevicelist(xdr, res->devlist);
6694out:
6695 return status;
6696}
6697
6698/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006699 * Decode GETDEVINFO response
6700 */
Chuck Leverbf269552010-12-14 14:59:29 +00006701static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6702 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006703 struct nfs4_getdeviceinfo_res *res)
6704{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006705 struct compound_hdr hdr;
6706 int status;
6707
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006709 if (status != 0)
6710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006712 if (status != 0)
6713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006715out:
6716 return status;
6717}
6718
6719/*
6720 * Decode LAYOUTGET response
6721 */
Chuck Leverbf269552010-12-14 14:59:29 +00006722static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6723 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006724 struct nfs4_layoutget_res *res)
6725{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006726 struct compound_hdr hdr;
6727 int status;
6728
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006733 if (status)
6734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006736 if (status)
6737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006739out:
6740 return status;
6741}
Andy Adamson863a3c62011-03-23 13:27:54 +00006742
6743/*
Benny Halevycbe82602011-05-22 19:52:37 +03006744 * Decode LAYOUTRETURN response
6745 */
6746static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6747 struct xdr_stream *xdr,
6748 struct nfs4_layoutreturn_res *res)
6749{
6750 struct compound_hdr hdr;
6751 int status;
6752
6753 status = decode_compound_hdr(xdr, &hdr);
6754 if (status)
6755 goto out;
6756 status = decode_sequence(xdr, &res->seq_res, rqstp);
6757 if (status)
6758 goto out;
6759 status = decode_putfh(xdr);
6760 if (status)
6761 goto out;
6762 status = decode_layoutreturn(xdr, res);
6763out:
6764 return status;
6765}
6766
6767/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006768 * Decode LAYOUTCOMMIT response
6769 */
6770static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6771 struct xdr_stream *xdr,
6772 struct nfs4_layoutcommit_res *res)
6773{
6774 struct compound_hdr hdr;
6775 int status;
6776
6777 status = decode_compound_hdr(xdr, &hdr);
6778 if (status)
6779 goto out;
6780 status = decode_sequence(xdr, &res->seq_res, rqstp);
6781 if (status)
6782 goto out;
6783 status = decode_putfh(xdr);
6784 if (status)
6785 goto out;
6786 status = decode_layoutcommit(xdr, rqstp, res);
6787 if (status)
6788 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006789 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006790out:
6791 return status;
6792}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006793
6794/*
6795 * Decode SECINFO_NO_NAME response
6796 */
6797static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6798 struct xdr_stream *xdr,
6799 struct nfs4_secinfo_res *res)
6800{
6801 struct compound_hdr hdr;
6802 int status;
6803
6804 status = decode_compound_hdr(xdr, &hdr);
6805 if (status)
6806 goto out;
6807 status = decode_sequence(xdr, &res->seq_res, rqstp);
6808 if (status)
6809 goto out;
6810 status = decode_putrootfh(xdr);
6811 if (status)
6812 goto out;
6813 status = decode_secinfo(xdr, res);
6814out:
6815 return status;
6816}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006817
6818/*
6819 * Decode TEST_STATEID response
6820 */
6821static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6822 struct xdr_stream *xdr,
6823 struct nfs41_test_stateid_res *res)
6824{
6825 struct compound_hdr hdr;
6826 int status;
6827
6828 status = decode_compound_hdr(xdr, &hdr);
6829 if (status)
6830 goto out;
6831 status = decode_sequence(xdr, &res->seq_res, rqstp);
6832 if (status)
6833 goto out;
6834 status = decode_test_stateid(xdr, res);
6835out:
6836 return status;
6837}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006838
6839/*
6840 * Decode FREE_STATEID response
6841 */
6842static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6843 struct xdr_stream *xdr,
6844 struct nfs41_free_stateid_res *res)
6845{
6846 struct compound_hdr hdr;
6847 int status;
6848
6849 status = decode_compound_hdr(xdr, &hdr);
6850 if (status)
6851 goto out;
6852 status = decode_sequence(xdr, &res->seq_res, rqstp);
6853 if (status)
6854 goto out;
6855 status = decode_free_stateid(xdr, res);
6856out:
6857 return status;
6858}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006859#endif /* CONFIG_NFS_V4_1 */
6860
Chuck Lever573c4e12010-12-14 14:58:11 +00006861/**
6862 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6863 * the local page cache.
6864 * @xdr: XDR stream where entry resides
6865 * @entry: buffer to fill in with entry data
6866 * @plus: boolean indicating whether this should be a readdirplus entry
6867 *
6868 * Returns zero if successful, otherwise a negative errno value is
6869 * returned.
6870 *
6871 * This function is not invoked during READDIR reply decoding, but
6872 * rather whenever an application invokes the getdents(2) system call
6873 * on a directory already in our cache.
6874 */
6875int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6876 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877{
Fred Isamandae100c2011-07-30 20:52:37 -04006878 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006880 __be32 *p = xdr_inline_decode(xdr, 4);
6881 if (unlikely(!p))
6882 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006883 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006884 p = xdr_inline_decode(xdr, 4);
6885 if (unlikely(!p))
6886 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006887 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006888 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006890 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 }
6892
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006893 p = xdr_inline_decode(xdr, 12);
6894 if (unlikely(!p))
6895 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 entry->prev_cookie = entry->cookie;
6897 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006898 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006899
Trond Myklebust9af8c222010-10-24 11:52:55 -04006900 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006901 if (unlikely(!p))
6902 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904
6905 /*
6906 * In case the server doesn't return an inode number,
6907 * we fake one here. (We don't use inode number 0,
6908 * since glibc seems to choke on it...)
6909 */
6910 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006911 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912
Trond Myklebust9af8c222010-10-24 11:52:55 -04006913 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006914 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006915
6916 if (decode_attr_length(xdr, &len, &p) < 0)
6917 goto out_overflow;
6918
Chuck Lever573c4e12010-12-14 14:58:11 +00006919 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006920 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006921 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006922 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6923 entry->ino = entry->fattr->mounted_on_fileid;
6924 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006925 entry->ino = entry->fattr->fileid;
6926
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006927 entry->d_type = DT_UNKNOWN;
6928 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6929 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6930
Chuck Lever573c4e12010-12-14 14:58:11 +00006931 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006932
6933out_overflow:
6934 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006935 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006936}
6937
6938/*
6939 * We need to translate between nfs status return values and
6940 * the local errno values which may not be the same.
6941 */
6942static struct {
6943 int stat;
6944 int errno;
6945} nfs_errtbl[] = {
6946 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006947 { NFS4ERR_PERM, -EPERM },
6948 { NFS4ERR_NOENT, -ENOENT },
6949 { NFS4ERR_IO, -errno_NFSERR_IO},
6950 { NFS4ERR_NXIO, -ENXIO },
6951 { NFS4ERR_ACCESS, -EACCES },
6952 { NFS4ERR_EXIST, -EEXIST },
6953 { NFS4ERR_XDEV, -EXDEV },
6954 { NFS4ERR_NOTDIR, -ENOTDIR },
6955 { NFS4ERR_ISDIR, -EISDIR },
6956 { NFS4ERR_INVAL, -EINVAL },
6957 { NFS4ERR_FBIG, -EFBIG },
6958 { NFS4ERR_NOSPC, -ENOSPC },
6959 { NFS4ERR_ROFS, -EROFS },
6960 { NFS4ERR_MLINK, -EMLINK },
6961 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6962 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6963 { NFS4ERR_DQUOT, -EDQUOT },
6964 { NFS4ERR_STALE, -ESTALE },
6965 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006966 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6967 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6968 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006969 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006970 { NFS4ERR_BADTYPE, -EBADTYPE },
6971 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006972 { NFS4ERR_SYMLINK, -ELOOP },
6973 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6974 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006975 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976};
6977
6978/*
6979 * Convert an NFS error code to a local one.
6980 * This one is used jointly by NFSv2 and NFSv3.
6981 */
6982static int
David Howells0a8ea432006-08-22 20:06:08 -04006983nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984{
6985 int i;
6986 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6987 if (nfs_errtbl[i].stat == stat)
6988 return nfs_errtbl[i].errno;
6989 }
6990 if (stat <= 10000 || stat > 10100) {
6991 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006992 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006993 }
6994 /* If we cannot translate the error, the recovery routines should
6995 * handle it.
6996 * Note: remaining NFSv4 error codes have values > 10000, so should
6997 * not conflict with native Linux error codes.
6998 */
Benny Halevy856dff32008-03-31 17:39:06 +03006999 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000}
7001
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002#define PROC(proc, argtype, restype) \
7003[NFSPROC4_CLNT_##proc] = { \
7004 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007005 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007006 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007007 .p_arglen = NFS4_##argtype##_sz, \
7008 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007009 .p_statidx = NFSPROC4_CLNT_##proc, \
7010 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007011}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007012
7013struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007014 PROC(READ, enc_read, dec_read),
7015 PROC(WRITE, enc_write, dec_write),
7016 PROC(COMMIT, enc_commit, dec_commit),
7017 PROC(OPEN, enc_open, dec_open),
7018 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7019 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7020 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7021 PROC(CLOSE, enc_close, dec_close),
7022 PROC(SETATTR, enc_setattr, dec_setattr),
7023 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7024 PROC(RENEW, enc_renew, dec_renew),
7025 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7026 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7027 PROC(LOCK, enc_lock, dec_lock),
7028 PROC(LOCKT, enc_lockt, dec_lockt),
7029 PROC(LOCKU, enc_locku, dec_locku),
7030 PROC(ACCESS, enc_access, dec_access),
7031 PROC(GETATTR, enc_getattr, dec_getattr),
7032 PROC(LOOKUP, enc_lookup, dec_lookup),
7033 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7034 PROC(REMOVE, enc_remove, dec_remove),
7035 PROC(RENAME, enc_rename, dec_rename),
7036 PROC(LINK, enc_link, dec_link),
7037 PROC(SYMLINK, enc_symlink, dec_symlink),
7038 PROC(CREATE, enc_create, dec_create),
7039 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7040 PROC(STATFS, enc_statfs, dec_statfs),
7041 PROC(READLINK, enc_readlink, dec_readlink),
7042 PROC(READDIR, enc_readdir, dec_readdir),
7043 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7044 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7045 PROC(GETACL, enc_getacl, dec_getacl),
7046 PROC(SETACL, enc_setacl, dec_setacl),
7047 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7048 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007049 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007050#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007051 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7052 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7053 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7054 PROC(SEQUENCE, enc_sequence, dec_sequence),
7055 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7056 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7057 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7058 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007059 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007060 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007061 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007062 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007063 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007064 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007065#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007066};
7067
Trond Myklebusta613fa12012-01-20 13:53:56 -05007068const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007069 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007070 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071 .procs = nfs4_procedures
7072};
7073
7074/*
7075 * Local variables:
7076 * c-basic-offset: 8
7077 * End:
7078 */