blob: b5c5212cd18459dec27332dcd7865fbed8ec04e8 [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
888static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
889{
Al Viro8687b632006-10-19 23:28:48 -0700890 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 p = xdr_reserve_space(xdr, 4 + len);
893 BUG_ON(p == NULL);
894 xdr_encode_opaque(p, str, len);
895}
896
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897static void encode_compound_hdr(struct xdr_stream *xdr,
898 struct rpc_rqst *req,
899 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Al Viro8687b632006-10-19 23:28:48 -0700901 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400902 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903
904 /* initialize running count of expected bytes in reply.
905 * NOTE: the replied tag SHOULD be the same is the one sent,
906 * but this is not required as a MUST for the server to do so. */
907 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
910 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300911 p = reserve_space(xdr, 4 + hdr->taglen + 8);
912 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300913 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500914 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300915 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500916}
917
918static void encode_nops(struct compound_hdr *hdr)
919{
Andy Adamsonfc931582009-04-01 09:22:31 -0400920 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
924static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
929 BUG_ON(p == NULL);
930 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
931}
932
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500933static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 char owner_name[IDMAP_NAMESZ];
936 char owner_group[IDMAP_NAMESZ];
937 int owner_namelen = 0;
938 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700939 __be32 *p;
940 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 int len;
942 uint32_t bmval0 = 0;
943 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 /*
946 * We reserve enough space to write the entire attribute buffer at once.
947 * In the worst-case, this would be
948 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
949 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000950 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 */
952 len = 16;
953
954 /* Sigh */
955 if (iap->ia_valid & ATTR_SIZE)
956 len += 8;
957 if (iap->ia_valid & ATTR_MODE)
958 len += 4;
959 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800960 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400962 dprintk("nfs: couldn't resolve uid %d to string\n",
963 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 /* XXX */
965 strcpy(owner_name, "nobody");
966 owner_namelen = sizeof("nobody") - 1;
967 /* goto out; */
968 }
969 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
970 }
971 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800972 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400974 dprintk("nfs: couldn't resolve gid %d to string\n",
975 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 strcpy(owner_group, "nobody");
977 owner_grouplen = sizeof("nobody") - 1;
978 /* goto out; */
979 }
980 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
981 }
982 if (iap->ia_valid & ATTR_ATIME_SET)
983 len += 16;
984 else if (iap->ia_valid & ATTR_ATIME)
985 len += 4;
986 if (iap->ia_valid & ATTR_MTIME_SET)
987 len += 16;
988 else if (iap->ia_valid & ATTR_MTIME)
989 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300990 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 /*
993 * We write the bitmap length now, but leave the bitmap and the attribute
994 * buffer length to be backfilled at the end of this routine.
995 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300996 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 q = p;
998 p += 3;
999
1000 if (iap->ia_valid & ATTR_SIZE) {
1001 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001002 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
1004 if (iap->ia_valid & ATTR_MODE) {
1005 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001006 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008 if (iap->ia_valid & ATTR_UID) {
1009 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001010 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 if (iap->ia_valid & ATTR_GID) {
1013 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001014 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 if (iap->ia_valid & ATTR_ATIME_SET) {
1017 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001018 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1019 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001020 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1021 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 else if (iap->ia_valid & ATTR_ATIME) {
1024 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027 if (iap->ia_valid & ATTR_MTIME_SET) {
1028 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001029 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1030 *p++ = cpu_to_be32(0);
1031 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1032 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 else if (iap->ia_valid & ATTR_MTIME) {
1035 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001036 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /*
1040 * Now we backfill the bitmap and the attribute buffer length.
1041 */
1042 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001043 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 len, ((char *)p - (char *)q) + 4);
1045 BUG();
1046 }
1047 len = (char *)p - (char *)q - 12;
1048 *q++ = htonl(bmval0);
1049 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001050 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053}
1054
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001055static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
Al Viro8687b632006-10-19 23:28:48 -07001057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Benny Halevy13c65ce2009-08-14 17:19:25 +03001059 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001061 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001062 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001063 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001066static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Al Viro8687b632006-10-19 23:28:48 -07001068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Benny Halevy13c65ce2009-08-14 17:19:25 +03001070 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(OP_CLOSE);
1072 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001073 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001074 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001075 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001078static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Al Viro8687b632006-10-19 23:28:48 -07001080 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001081
Benny Halevy13c65ce2009-08-14 17:19:25 +03001082 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001083 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001084 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001085 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001087 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Al Viro8687b632006-10-19 23:28:48 -07001092 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001093
Benny Halevy13c65ce2009-08-14 17:19:25 +03001094 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001095 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001096 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 switch (create->ftype) {
1099 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001100 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001101 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001102 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 break;
1104
1105 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001106 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001107 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001108 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
1110
1111 default:
1112 break;
1113 }
1114
Benny Halevy811652b2009-08-14 17:19:34 +03001115 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001116 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001117 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Benny Halevy13c65ce2009-08-14 17:19:25 +03001126 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001127 *p++ = cpu_to_be32(OP_GETATTR);
1128 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001129 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001130 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001131 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001134static 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 -07001135{
Andy Adamson05d564f2008-12-23 16:06:15 -05001136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Benny Halevy13c65ce2009-08-14 17:19:25 +03001138 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001139 *p++ = cpu_to_be32(OP_GETATTR);
1140 *p++ = cpu_to_be32(2);
1141 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001142 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001143 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001144 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Fred Isamandae100c2011-07-30 20:52:37 -04001147static void
1148encode_getattr_three(struct xdr_stream *xdr,
1149 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1150 struct compound_hdr *hdr)
1151{
1152 __be32 *p;
1153
1154 p = reserve_space(xdr, 4);
1155 *p = cpu_to_be32(OP_GETATTR);
1156 if (bm2) {
1157 p = reserve_space(xdr, 16);
1158 *p++ = cpu_to_be32(3);
1159 *p++ = cpu_to_be32(bm0);
1160 *p++ = cpu_to_be32(bm1);
1161 *p = cpu_to_be32(bm2);
1162 } else if (bm1) {
1163 p = reserve_space(xdr, 12);
1164 *p++ = cpu_to_be32(2);
1165 *p++ = cpu_to_be32(bm0);
1166 *p = cpu_to_be32(bm1);
1167 } else {
1168 p = reserve_space(xdr, 8);
1169 *p++ = cpu_to_be32(1);
1170 *p = cpu_to_be32(bm0);
1171 }
1172 hdr->nops++;
1173 hdr->replen += decode_getattr_maxsz;
1174}
1175
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001178 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1179 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Fred Isamandae100c2011-07-30 20:52:37 -04001184 encode_getattr_three(xdr,
1185 bitmask[0] & nfs4_fsinfo_bitmap[0],
1186 bitmask[1] & nfs4_fsinfo_bitmap[1],
1187 bitmask[2] & nfs4_fsinfo_bitmap[2],
1188 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001192{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1194 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Al Viro8687b632006-10-19 23:28:48 -07001199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Benny Halevy13c65ce2009-08-14 17:19:25 +03001201 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001202 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001203 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001204 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205}
1206
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001207static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Al Viro8687b632006-10-19 23:28:48 -07001209 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Benny Halevy13c65ce2009-08-14 17:19:25 +03001211 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001212 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001213 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001214 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001215 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001218static inline int nfs4_lock_type(struct file_lock *fl, int block)
1219{
1220 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1221 return block ? NFS4_READW_LT : NFS4_READ_LT;
1222 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1223}
1224
1225static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1226{
1227 if (fl->fl_end == OFFSET_MAX)
1228 return ~(uint64_t)0;
1229 return fl->fl_end - fl->fl_start + 1;
1230}
1231
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001232static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1233{
1234 __be32 *p;
1235
Trond Myklebustd035c362010-12-21 10:45:27 -05001236 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001238 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001239 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001240 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001241 xdr_encode_hyper(p, lowner->id);
1242}
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244/*
1245 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1246 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1247 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Al Viro8687b632006-10-19 23:28:48 -07001250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Benny Halevy13c65ce2009-08-14 17:19:25 +03001252 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(OP_LOCK);
1254 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1255 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001256 p = xdr_encode_hyper(p, args->fl->fl_start);
1257 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001258 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001259 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001260 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001261 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001262 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001263 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001264 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
1266 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001267 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001268 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001269 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
Andy Adamsond0179312008-12-23 16:06:17 -05001271 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001272 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273}
1274
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001275static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Al Viro8687b632006-10-19 23:28:48 -07001277 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001279 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001280 *p++ = cpu_to_be32(OP_LOCKT);
1281 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001282 p = xdr_encode_hyper(p, args->fl->fl_start);
1283 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001284 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001285 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001286 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Benny Halevy13c65ce2009-08-14 17:19:25 +03001293 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001294 *p++ = cpu_to_be32(OP_LOCKU);
1295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1296 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001297 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001298 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001299 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001300 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001301 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001304static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1305{
1306 __be32 *p;
1307
1308 p = reserve_space(xdr, 4);
1309 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1310 encode_lockowner(xdr, lowner);
1311 hdr->nops++;
1312 hdr->replen += decode_release_lockowner_maxsz;
1313}
1314
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001315static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
1317 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Benny Halevy13c65ce2009-08-14 17:19:25 +03001320 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001321 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001322 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001323 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001324 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001327static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Benny Halevy13c65ce2009-08-14 17:19:25 +03001331 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001332 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001333 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001334 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001335 break;
1336 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001337 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001338 break;
1339 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001340 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001341 break;
1342 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Benny Halevy34558512009-08-14 17:19:30 +03001345 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
1348static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 /*
1352 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1353 * owner 4 = 32
1354 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001357 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001358 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001359 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001360 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001361 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001362 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001363 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001364 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001370 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001376 encode_attrs(xdr, arg->u.attrs, arg->server);
1377 break;
1378 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001379 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001380 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001381 if (nfs4_has_persistent_session(clp)) {
1382 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1383 encode_attrs(xdr, arg->u.attrs, arg->server);
1384 } else {
1385 struct iattr dummy;
1386
1387 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1388 encode_nfs4_verifier(xdr, &arg->u.verifier);
1389 dummy.ia_valid = 0;
1390 encode_attrs(xdr, &dummy, arg->server);
1391 }
1392 } else {
1393 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1394 encode_nfs4_verifier(xdr, &arg->u.verifier);
1395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
1399static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 break;
1408 default:
1409 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001411 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413}
1414
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001415static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
1424 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 break;
1427 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001428 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 break;
1430 default:
1431 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
1433}
1434
1435static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1436{
Al Viro8687b632006-10-19 23:28:48 -07001437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Benny Halevy13c65ce2009-08-14 17:19:25 +03001439 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 encode_string(xdr, name->len, name->name);
1442}
1443
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001444static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Al Viro8687b632006-10-19 23:28:48 -07001446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Benny Halevy13c65ce2009-08-14 17:19:25 +03001448 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001449 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 encode_delegation_type(xdr, type);
1451}
1452
1453static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1454{
Al Viro8687b632006-10-19 23:28:48 -07001455 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001458 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001459 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 encode_string(xdr, name->len, name->name);
1461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
1465 encode_openhdr(xdr, arg);
1466 encode_opentype(xdr, arg);
1467 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001468 case NFS4_OPEN_CLAIM_NULL:
1469 encode_claim_null(xdr, arg->name);
1470 break;
1471 case NFS4_OPEN_CLAIM_PREVIOUS:
1472 encode_claim_previous(xdr, arg->u.delegation_type);
1473 break;
1474 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1475 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1476 break;
1477 default:
1478 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
Andy Adamsond0179312008-12-23 16:06:17 -05001480 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001481 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static 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 -07001485{
Al Viro8687b632006-10-19 23:28:48 -07001486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Benny Halevy13c65ce2009-08-14 17:19:25 +03001488 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001489 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001490 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001491 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001492 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001493 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001502 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001503 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001504 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001505 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001506 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001509static void
Andy Adamsond0179312008-12-23 16:06:17 -05001510encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
1512 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Benny Halevy13c65ce2009-08-14 17:19:25 +03001515 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001516 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001517 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001518 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001519 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001522static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Andy Adamson05d564f2008-12-23 16:06:15 -05001524 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001525
Benny Halevy13c65ce2009-08-14 17:19:25 +03001526 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001527 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001528 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001529 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamson89d1ea62011-03-01 01:34:09 +00001532static void encode_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 -07001533{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Benny Halevy13c65ce2009-08-14 17:19:25 +03001537 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001539 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001540 if (zero_seqid)
1541 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001542 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } else
Benny Halevy34558512009-08-14 17:19:30 +03001544 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Al Viro8687b632006-10-19 23:28:48 -07001549 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001552 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Andy Adamson89d1ea62011-03-01 01:34:09 +00001554 encode_stateid(xdr, args->context, args->lock_context,
1555 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001558 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001560 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001561 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001564static 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 -07001565{
Trond Myklebust28331a42011-04-27 13:47:52 -04001566 uint32_t attrs[2] = {
1567 FATTR4_WORD0_RDATTR_ERROR,
1568 FATTR4_WORD1_MOUNTED_ON_FILEID,
1569 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001570 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001571 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573 if (readdir->plus) {
1574 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001575 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001576 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1577 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1578 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1579 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001580 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001582 /* Use mounted_on_fileid only if the server supports it */
1583 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1584 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001588 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001589 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001590 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001591 *p++ = cpu_to_be32(readdir->count);
1592 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001593
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001595 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001596 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001597 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001598 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1599 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001600 (unsigned long long)readdir->cookie,
1601 ((u32 *)readdir->verifier.data)[0],
1602 ((u32 *)readdir->verifier.data)[1],
1603 attrs[0] & readdir->bitmask[0],
1604 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001607static 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 -07001608{
Al Viro8687b632006-10-19 23:28:48 -07001609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Benny Halevy13c65ce2009-08-14 17:19:25 +03001611 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001612 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001613 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001614 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, 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
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001622 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001623 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001624 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001625 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static 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 -07001629{
Al Viro8687b632006-10-19 23:28:48 -07001630 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Benny Halevy811652b2009-08-14 17:19:34 +03001632 p = reserve_space(xdr, 4);
1633 *p = cpu_to_be32(OP_RENAME);
1634 encode_string(xdr, oldname->len, oldname->name);
1635 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001636 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001637 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001640static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Al Viro8687b632006-10-19 23:28:48 -07001642 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Benny Halevy13c65ce2009-08-14 17:19:25 +03001644 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001645 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001646 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001647 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001648 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static void
Andy Adamsond0179312008-12-23 16:06:17 -05001652encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001653{
Al Viro8687b632006-10-19 23:28:48 -07001654 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001655
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001657 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001658 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001659 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001660}
1661
Chuck Lever9f06c712010-12-14 14:59:18 +00001662static void
Andy Adamsond0179312008-12-23 16:06:17 -05001663encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001666
Benny Halevy13c65ce2009-08-14 17:19:25 +03001667 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001668 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001669 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001671 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001672 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001673 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001675 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001676 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001677 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001678 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001679}
1680
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681static void
Andy Adamsond0179312008-12-23 16:06:17 -05001682encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
Al Viro8687b632006-10-19 23:28:48 -07001684 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Benny Halevy13c65ce2009-08-14 17:19:25 +03001686 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001687 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001688 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001689 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001692static 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 -07001693{
Al Viro8687b632006-10-19 23:28:48 -07001694 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001695
Benny Halevy13c65ce2009-08-14 17:19:25 +03001696 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001697 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001698 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001699 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001700 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001704static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Al Viro8687b632006-10-19 23:28:48 -07001706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Benny Halevy13c65ce2009-08-14 17:19:25 +03001708 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001709 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001710 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001713 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001714 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1716 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001717 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001718 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001719 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001720 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721}
1722
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001723static 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 -07001724{
Andy Adamson05d564f2008-12-23 16:06:15 -05001725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Benny Halevy13c65ce2009-08-14 17:19:25 +03001727 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001728 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001729 p = xdr_encode_hyper(p, arg->clientid);
1730 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001731 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001732 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001735static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
Al Viro8687b632006-10-19 23:28:48 -07001737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Benny Halevy13c65ce2009-08-14 17:19:25 +03001739 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001740 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Andy Adamson89d1ea62011-03-01 01:34:09 +00001742 encode_stateid(xdr, args->context, args->lock_context,
1743 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Benny Halevy13c65ce2009-08-14 17:19:25 +03001745 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001746 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001747 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001748 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001751 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001752 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753}
1754
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001755static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Al Viro8687b632006-10-19 23:28:48 -07001757 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Benny Halevy13c65ce2009-08-14 17:19:25 +03001759 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Benny Halevye75bc1c2009-08-14 17:18:54 +03001761 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001762 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001763 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001764 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001766
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001767static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1768{
1769 int len = name->len;
1770 __be32 *p;
1771
1772 p = reserve_space(xdr, 8 + len);
1773 *p++ = cpu_to_be32(OP_SECINFO);
1774 xdr_encode_opaque(p, name->name, len);
1775 hdr->nops++;
1776 hdr->replen += decode_secinfo_maxsz;
1777}
1778
Benny Halevy99fe60d2009-04-01 09:22:29 -04001779#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001780/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001781static void encode_exchange_id(struct xdr_stream *xdr,
1782 struct nfs41_exchange_id_args *args,
1783 struct compound_hdr *hdr)
1784{
1785 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001786 char impl_name[NFS4_OPAQUE_LIMIT];
1787 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001788
Benny Halevy13c65ce2009-08-14 17:19:25 +03001789 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001790 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001791 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792
1793 encode_string(xdr, args->id_len, args->id);
1794
Benny Halevy13c65ce2009-08-14 17:19:25 +03001795 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001796 *p++ = cpu_to_be32(args->flags);
1797 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001798
1799 if (send_implementation_id &&
1800 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1801 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1802 <= NFS4_OPAQUE_LIMIT + 1)
1803 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1804 utsname()->sysname, utsname()->release,
1805 utsname()->version, utsname()->machine);
1806
1807 if (len > 0) {
1808 *p = cpu_to_be32(1); /* implementation id array length=1 */
1809
1810 encode_string(xdr,
1811 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1812 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1813 encode_string(xdr, len, impl_name);
1814 /* just send zeros for nii_date - the date is in nii_name */
1815 p = reserve_space(xdr, 12);
1816 p = xdr_encode_hyper(p, 0);
1817 *p = cpu_to_be32(0);
1818 } else
1819 *p = cpu_to_be32(0); /* implementation id array length=0 */
1820
Benny Halevy99fe60d2009-04-01 09:22:29 -04001821 hdr->nops++;
1822 hdr->replen += decode_exchange_id_maxsz;
1823}
Andy Adamsonfc931582009-04-01 09:22:31 -04001824
1825static void encode_create_session(struct xdr_stream *xdr,
1826 struct nfs41_create_session_args *args,
1827 struct compound_hdr *hdr)
1828{
1829 __be32 *p;
1830 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1831 uint32_t len;
1832 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001833 u32 max_resp_sz_cached;
1834
1835 /*
1836 * Assumes OPEN is the biggest non-idempotent compound.
1837 * 2 is the verifier.
1838 */
1839 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1840 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001841
Andy Adamsonfc931582009-04-01 09:22:31 -04001842 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1843 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001844
Benny Halevy13c65ce2009-08-14 17:19:25 +03001845 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001846 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001847 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1849 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001850
Andy Adamsonfc931582009-04-01 09:22:31 -04001851 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001852 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001853 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1854 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001855 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001856 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1857 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1858 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001859
1860 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001861 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001862 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1863 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1864 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1867 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001868
Benny Halevye75bc1c2009-08-14 17:18:54 +03001869 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001872
1873 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001874 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001875 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001876 *p++ = cpu_to_be32(0); /* UID */
1877 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001878 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001879 hdr->nops++;
1880 hdr->replen += decode_create_session_maxsz;
1881}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001882
1883static void encode_destroy_session(struct xdr_stream *xdr,
1884 struct nfs4_session *session,
1885 struct compound_hdr *hdr)
1886{
1887 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001888 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001889 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001890 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001891 hdr->nops++;
1892 hdr->replen += decode_destroy_session_maxsz;
1893}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001894
1895static void encode_reclaim_complete(struct xdr_stream *xdr,
1896 struct nfs41_reclaim_complete_args *args,
1897 struct compound_hdr *hdr)
1898{
1899 __be32 *p;
1900
1901 p = reserve_space(xdr, 8);
1902 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1903 *p++ = cpu_to_be32(args->one_fs);
1904 hdr->nops++;
1905 hdr->replen += decode_reclaim_complete_maxsz;
1906}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001907#endif /* CONFIG_NFS_V4_1 */
1908
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909static void encode_sequence(struct xdr_stream *xdr,
1910 const struct nfs4_sequence_args *args,
1911 struct compound_hdr *hdr)
1912{
1913#if defined(CONFIG_NFS_V4_1)
1914 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001915 struct nfs4_slot_table *tp;
1916 struct nfs4_slot *slot;
1917 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001918
1919 if (!session)
1920 return;
1921
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001922 tp = &session->fc_slot_table;
1923
1924 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1925 slot = tp->slots + args->sa_slotid;
1926
Benny Halevy13c65ce2009-08-14 17:19:25 +03001927 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001928 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001929
1930 /*
1931 * Sessionid + seqid + slotid + max slotid + cache_this
1932 */
1933 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1934 "max_slotid=%d cache_this=%d\n",
1935 __func__,
1936 ((u32 *)session->sess_id.data)[0],
1937 ((u32 *)session->sess_id.data)[1],
1938 ((u32 *)session->sess_id.data)[2],
1939 ((u32 *)session->sess_id.data)[3],
1940 slot->seq_nr, args->sa_slotid,
1941 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001942 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001943 *p++ = cpu_to_be32(slot->seq_nr);
1944 *p++ = cpu_to_be32(args->sa_slotid);
1945 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001946 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001947 hdr->nops++;
1948 hdr->replen += decode_sequence_maxsz;
1949#endif /* CONFIG_NFS_V4_1 */
1950}
1951
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001952#ifdef CONFIG_NFS_V4_1
1953static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001954encode_getdevicelist(struct xdr_stream *xdr,
1955 const struct nfs4_getdevicelist_args *args,
1956 struct compound_hdr *hdr)
1957{
1958 __be32 *p;
1959 nfs4_verifier dummy = {
1960 .data = "dummmmmy",
1961 };
1962
1963 p = reserve_space(xdr, 20);
1964 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1965 *p++ = cpu_to_be32(args->layoutclass);
1966 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1967 xdr_encode_hyper(p, 0ULL); /* cookie */
1968 encode_nfs4_verifier(xdr, &dummy);
1969 hdr->nops++;
1970 hdr->replen += decode_getdevicelist_maxsz;
1971}
1972
1973static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001974encode_getdeviceinfo(struct xdr_stream *xdr,
1975 const struct nfs4_getdeviceinfo_args *args,
1976 struct compound_hdr *hdr)
1977{
1978 __be32 *p;
1979
1980 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1981 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1982 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1983 NFS4_DEVICEID4_SIZE);
1984 *p++ = cpu_to_be32(args->pdev->layout_type);
1985 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1986 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1987 hdr->nops++;
1988 hdr->replen += decode_getdeviceinfo_maxsz;
1989}
1990
1991static void
1992encode_layoutget(struct xdr_stream *xdr,
1993 const struct nfs4_layoutget_args *args,
1994 struct compound_hdr *hdr)
1995{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001996 __be32 *p;
1997
1998 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1999 *p++ = cpu_to_be32(OP_LAYOUTGET);
2000 *p++ = cpu_to_be32(0); /* Signal layout available */
2001 *p++ = cpu_to_be32(args->type);
2002 *p++ = cpu_to_be32(args->range.iomode);
2003 p = xdr_encode_hyper(p, args->range.offset);
2004 p = xdr_encode_hyper(p, args->range.length);
2005 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00002006 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002007 *p = cpu_to_be32(args->maxcount);
2008
2009 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2010 __func__,
2011 args->type,
2012 args->range.iomode,
2013 (unsigned long)args->range.offset,
2014 (unsigned long)args->range.length,
2015 args->maxcount);
2016 hdr->nops++;
2017 hdr->replen += decode_layoutget_maxsz;
2018}
Andy Adamson863a3c62011-03-23 13:27:54 +00002019
2020static int
2021encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002022 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002023 const struct nfs4_layoutcommit_args *args,
2024 struct compound_hdr *hdr)
2025{
2026 __be32 *p;
2027
2028 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2029 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2030
Benny Halevyac7db722011-05-22 19:53:48 +03002031 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00002032 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2033 /* Only whole file layouts */
2034 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002035 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00002036 *p++ = cpu_to_be32(0); /* reclaim */
2037 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2038 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2039 p = xdr_encode_hyper(p, args->lastbytewritten);
2040 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2041 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002042
2043 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2044 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2045 NFS_I(inode)->layout, xdr, args);
2046 else {
2047 p = reserve_space(xdr, 4);
2048 *p = cpu_to_be32(0); /* no layout-type payload */
2049 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002050
2051 hdr->nops++;
2052 hdr->replen += decode_layoutcommit_maxsz;
2053 return 0;
2054}
Benny Halevycbe82602011-05-22 19:52:37 +03002055
2056static void
2057encode_layoutreturn(struct xdr_stream *xdr,
2058 const struct nfs4_layoutreturn_args *args,
2059 struct compound_hdr *hdr)
2060{
2061 __be32 *p;
2062
2063 p = reserve_space(xdr, 20);
2064 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2065 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2066 *p++ = cpu_to_be32(args->layout_type);
2067 *p++ = cpu_to_be32(IOMODE_ANY);
2068 *p = cpu_to_be32(RETURN_FILE);
2069 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2070 p = xdr_encode_hyper(p, 0);
2071 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2072 spin_lock(&args->inode->i_lock);
2073 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2074 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002075 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2076 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2077 NFS_I(args->inode)->layout, xdr, args);
2078 } else {
2079 p = reserve_space(xdr, 4);
2080 *p = cpu_to_be32(0);
2081 }
Benny Halevycbe82602011-05-22 19:52:37 +03002082 hdr->nops++;
2083 hdr->replen += decode_layoutreturn_maxsz;
2084}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002085
2086static int
2087encode_secinfo_no_name(struct xdr_stream *xdr,
2088 const struct nfs41_secinfo_no_name_args *args,
2089 struct compound_hdr *hdr)
2090{
2091 __be32 *p;
2092 p = reserve_space(xdr, 8);
2093 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2094 *p++ = cpu_to_be32(args->style);
2095 hdr->nops++;
2096 hdr->replen += decode_secinfo_no_name_maxsz;
2097 return 0;
2098}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002099
2100static void encode_test_stateid(struct xdr_stream *xdr,
2101 struct nfs41_test_stateid_args *args,
2102 struct compound_hdr *hdr)
2103{
2104 __be32 *p;
2105
2106 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2107 *p++ = cpu_to_be32(OP_TEST_STATEID);
2108 *p++ = cpu_to_be32(1);
2109 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2110 hdr->nops++;
2111 hdr->replen += decode_test_stateid_maxsz;
2112}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002113
2114static void encode_free_stateid(struct xdr_stream *xdr,
2115 struct nfs41_free_stateid_args *args,
2116 struct compound_hdr *hdr)
2117{
2118 __be32 *p;
2119 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2120 *p++ = cpu_to_be32(OP_FREE_STATEID);
2121 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2122 hdr->nops++;
2123 hdr->replen += decode_free_stateid_maxsz;
2124}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002125#endif /* CONFIG_NFS_V4_1 */
2126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127/*
2128 * END OF "GENERIC" ENCODE ROUTINES.
2129 */
2130
Benny Halevy66cc0422009-04-01 09:22:10 -04002131static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2132{
2133#if defined(CONFIG_NFS_V4_1)
2134 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002135 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002136#endif /* CONFIG_NFS_V4_1 */
2137 return 0;
2138}
2139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140/*
2141 * Encode an ACCESS request
2142 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002143static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2144 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_sequence(xdr, &args->seq_args, &hdr);
2152 encode_putfh(xdr, args->fh, &hdr);
2153 encode_access(xdr, args->access, &hdr);
2154 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002155 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156}
2157
2158/*
2159 * Encode LOOKUP request
2160 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002161static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2162 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002165 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Chuck Lever9f06c712010-12-14 14:59:18 +00002168 encode_compound_hdr(xdr, req, &hdr);
2169 encode_sequence(xdr, &args->seq_args, &hdr);
2170 encode_putfh(xdr, args->dir_fh, &hdr);
2171 encode_lookup(xdr, args->name, &hdr);
2172 encode_getfh(xdr, &hdr);
2173 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002174 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175}
2176
2177/*
2178 * Encode LOOKUP_ROOT request
2179 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002180static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2181 struct xdr_stream *xdr,
2182 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002185 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_compound_hdr(xdr, req, &hdr);
2189 encode_sequence(xdr, &args->seq_args, &hdr);
2190 encode_putrootfh(xdr, &hdr);
2191 encode_getfh(xdr, &hdr);
2192 encode_getfattr(xdr, args->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 REMOVE request
2198 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002199static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2200 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002203 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Chuck Lever9f06c712010-12-14 14:59:18 +00002206 encode_compound_hdr(xdr, req, &hdr);
2207 encode_sequence(xdr, &args->seq_args, &hdr);
2208 encode_putfh(xdr, args->fh, &hdr);
2209 encode_remove(xdr, &args->name, &hdr);
2210 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002211 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212}
2213
2214/*
2215 * Encode RENAME request
2216 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002217static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2218 const struct nfs_renameargs *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->old_dir, &hdr);
2227 encode_savefh(xdr, &hdr);
2228 encode_putfh(xdr, args->new_dir, &hdr);
2229 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2230 encode_getfattr(xdr, args->bitmask, &hdr);
2231 encode_restorefh(xdr, &hdr);
2232 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002233 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234}
2235
2236/*
2237 * Encode LINK request
2238 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002239static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2240 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002243 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Chuck Lever9f06c712010-12-14 14:59:18 +00002246 encode_compound_hdr(xdr, req, &hdr);
2247 encode_sequence(xdr, &args->seq_args, &hdr);
2248 encode_putfh(xdr, args->fh, &hdr);
2249 encode_savefh(xdr, &hdr);
2250 encode_putfh(xdr, args->dir_fh, &hdr);
2251 encode_link(xdr, args->name, &hdr);
2252 encode_getfattr(xdr, args->bitmask, &hdr);
2253 encode_restorefh(xdr, &hdr);
2254 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002255 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256}
2257
2258/*
2259 * Encode CREATE request
2260 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002261static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2262 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002265 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Chuck Lever9f06c712010-12-14 14:59:18 +00002268 encode_compound_hdr(xdr, req, &hdr);
2269 encode_sequence(xdr, &args->seq_args, &hdr);
2270 encode_putfh(xdr, args->dir_fh, &hdr);
2271 encode_savefh(xdr, &hdr);
2272 encode_create(xdr, args, &hdr);
2273 encode_getfh(xdr, &hdr);
2274 encode_getfattr(xdr, args->bitmask, &hdr);
2275 encode_restorefh(xdr, &hdr);
2276 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002277 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278}
2279
2280/*
2281 * Encode SYMLINK request
2282 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002283static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2284 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode GETATTR request
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2293 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002296 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_sequence(xdr, &args->seq_args, &hdr);
2301 encode_putfh(xdr, args->fh, &hdr);
2302 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/*
2307 * Encode a CLOSE request
2308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2310 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Andy Adamson05d564f2008-12-23 16:06:15 -05002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_close(xdr, args, &hdr);
2320 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode an OPEN request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_savefh(xdr, &hdr);
2338 encode_open(xdr, args, &hdr);
2339 encode_getfh(xdr, &hdr);
2340 encode_getfattr(xdr, args->bitmask, &hdr);
2341 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002342 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * Encode an OPEN_CONFIRM request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2350 struct xdr_stream *xdr,
2351 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002354 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Chuck Lever9f06c712010-12-14 14:59:18 +00002357 encode_compound_hdr(xdr, req, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
2364 * Encode an OPEN request with no attributes.
2365 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2367 struct xdr_stream *xdr,
2368 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002371 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_sequence(xdr, &args->seq_args, &hdr);
2376 encode_putfh(xdr, args->fh, &hdr);
2377 encode_open(xdr, args, &hdr);
2378 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002379 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
2382/*
2383 * Encode an OPEN_DOWNGRADE request
2384 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002385static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2386 struct xdr_stream *xdr,
2387 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002390 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_sequence(xdr, &args->seq_args, &hdr);
2395 encode_putfh(xdr, args->fh, &hdr);
2396 encode_open_downgrade(xdr, args, &hdr);
2397 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002398 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
2401/*
2402 * Encode a LOCK request
2403 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002404static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2405 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002408 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Chuck Lever9f06c712010-12-14 14:59:18 +00002411 encode_compound_hdr(xdr, req, &hdr);
2412 encode_sequence(xdr, &args->seq_args, &hdr);
2413 encode_putfh(xdr, args->fh, &hdr);
2414 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
2417
2418/*
2419 * Encode a LOCKT request
2420 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002421static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2422 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002425 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Chuck Lever9f06c712010-12-14 14:59:18 +00002428 encode_compound_hdr(xdr, req, &hdr);
2429 encode_sequence(xdr, &args->seq_args, &hdr);
2430 encode_putfh(xdr, args->fh, &hdr);
2431 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
2436 * Encode a LOCKU request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Chuck Lever9f06c712010-12-14 14:59:18 +00002445 encode_compound_hdr(xdr, req, &hdr);
2446 encode_sequence(xdr, &args->seq_args, &hdr);
2447 encode_putfh(xdr, args->fh, &hdr);
2448 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
Chuck Lever9f06c712010-12-14 14:59:18 +00002452static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2453 struct xdr_stream *xdr,
2454 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002455{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002456 struct compound_hdr hdr = {
2457 .minorversion = 0,
2458 };
2459
Chuck Lever9f06c712010-12-14 14:59:18 +00002460 encode_compound_hdr(xdr, req, &hdr);
2461 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002462 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463}
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/*
2466 * Encode a READLINK request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Chuck Lever9f06c712010-12-14 14:59:18 +00002475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_sequence(xdr, &args->seq_args, &hdr);
2477 encode_putfh(xdr, args->fh, &hdr);
2478 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002479
Benny Halevy28f56692009-04-01 09:22:09 -04002480 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002481 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002482 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
2485/*
2486 * Encode a READDIR request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2489 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002492 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Chuck Lever9f06c712010-12-14 14:59:18 +00002495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_sequence(xdr, &args->seq_args, &hdr);
2497 encode_putfh(xdr, args->fh, &hdr);
2498 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002499
Benny Halevy28f56692009-04-01 09:22:09 -04002500 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002501 args->pgbase, args->count);
2502 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002503 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002504 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * Encode a READ request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2512 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
2519 encode_sequence(xdr, &args->seq_args, &hdr);
2520 encode_putfh(xdr, args->fh, &hdr);
2521 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Benny Halevy28f56692009-04-01 09:22:09 -04002523 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002525 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002526 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527}
2528
2529/*
2530 * Encode an SETATTR request
2531 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002532static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2533 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534{
Andy Adamson05d564f2008-12-23 16:06:15 -05002535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Chuck Lever9f06c712010-12-14 14:59:18 +00002539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->seq_args, &hdr);
2541 encode_putfh(xdr, args->fh, &hdr);
2542 encode_setattr(xdr, args, args->server, &hdr);
2543 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002544 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002548 * Encode a GETACL request
2549 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002550static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2551 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002552{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002553 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002554 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002555 };
Benny Halevy28f56692009-04-01 09:22:09 -04002556 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002557
Chuck Lever9f06c712010-12-14 14:59:18 +00002558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002561 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002563
Benny Halevy28f56692009-04-01 09:22:09 -04002564 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002565 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002566 xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2567
Andy Adamsond0179312008-12-23 16:06:17 -05002568 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002569}
2570
2571/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 * Encode a WRITE request
2573 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002574static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2575 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002578 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
Chuck Lever9f06c712010-12-14 14:59:18 +00002581 encode_compound_hdr(xdr, req, &hdr);
2582 encode_sequence(xdr, &args->seq_args, &hdr);
2583 encode_putfh(xdr, args->fh, &hdr);
2584 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002585 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002586 if (args->bitmask)
2587 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002588 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589}
2590
2591/*
2592 * a COMMIT request
2593 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002594static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2595 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002598 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
Chuck Lever9f06c712010-12-14 14:59:18 +00002601 encode_compound_hdr(xdr, req, &hdr);
2602 encode_sequence(xdr, &args->seq_args, &hdr);
2603 encode_putfh(xdr, args->fh, &hdr);
2604 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002605 if (args->bitmask)
2606 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002607 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
2611 * FSINFO request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2614 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002617 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
2621 encode_sequence(xdr, &args->seq_args, &hdr);
2622 encode_putfh(xdr, args->fh, &hdr);
2623 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002624 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/*
2628 * a PATHCONF request
2629 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002630static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2631 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002634 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Chuck Lever9f06c712010-12-14 14:59:18 +00002637 encode_compound_hdr(xdr, req, &hdr);
2638 encode_sequence(xdr, &args->seq_args, &hdr);
2639 encode_putfh(xdr, args->fh, &hdr);
2640 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002641 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002642 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643}
2644
2645/*
2646 * a STATFS request
2647 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002648static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2649 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, args->fh, &hdr);
2658 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002659 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002660 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661}
2662
2663/*
2664 * GETATTR_BITMAP request
2665 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002666static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002671 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
Chuck Lever9f06c712010-12-14 14:59:18 +00002674 encode_compound_hdr(xdr, req, &hdr);
2675 encode_sequence(xdr, &args->seq_args, &hdr);
2676 encode_putfh(xdr, args->fhandle, &hdr);
2677 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002678 FATTR4_WORD0_LINK_SUPPORT|
2679 FATTR4_WORD0_SYMLINK_SUPPORT|
2680 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002681 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682}
2683
2684/*
2685 * a RENEW request
2686 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002687static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2688 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002691 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 };
2693
Chuck Lever9f06c712010-12-14 14:59:18 +00002694 encode_compound_hdr(xdr, req, &hdr);
2695 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002696 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697}
2698
2699/*
2700 * a SETCLIENTID request
2701 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002702static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2703 struct xdr_stream *xdr,
2704 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002707 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 };
2709
Chuck Lever9f06c712010-12-14 14:59:18 +00002710 encode_compound_hdr(xdr, req, &hdr);
2711 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002712 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713}
2714
2715/*
2716 * a SETCLIENTID_CONFIRM request
2717 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002718static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2719 struct xdr_stream *xdr,
2720 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002723 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 };
Fred Isamandae100c2011-07-30 20:52:37 -04002725 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
Chuck Lever9f06c712010-12-14 14:59:18 +00002727 encode_compound_hdr(xdr, req, &hdr);
2728 encode_setclientid_confirm(xdr, arg, &hdr);
2729 encode_putrootfh(xdr, &hdr);
2730 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002731 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732}
2733
2734/*
2735 * DELEGRETURN request
2736 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002737static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2738 struct xdr_stream *xdr,
2739 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002742 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Chuck Lever9f06c712010-12-14 14:59:18 +00002745 encode_compound_hdr(xdr, req, &hdr);
2746 encode_sequence(xdr, &args->seq_args, &hdr);
2747 encode_putfh(xdr, args->fhandle, &hdr);
2748 encode_delegreturn(xdr, args->stateid, &hdr);
2749 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002750 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751}
2752
2753/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002754 * Encode FS_LOCATIONS request
2755 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002756static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2757 struct xdr_stream *xdr,
2758 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002759{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002760 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002761 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002762 };
Benny Halevy28f56692009-04-01 09:22:09 -04002763 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002764
Chuck Lever9f06c712010-12-14 14:59:18 +00002765 encode_compound_hdr(xdr, req, &hdr);
2766 encode_sequence(xdr, &args->seq_args, &hdr);
2767 encode_putfh(xdr, args->dir_fh, &hdr);
2768 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002769 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002770 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002771
Benny Halevy28f56692009-04-01 09:22:09 -04002772 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002773 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002774 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002775}
2776
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002777/*
2778 * Encode SECINFO request
2779 */
2780static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs4_secinfo_arg *args)
2783{
2784 struct compound_hdr hdr = {
2785 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2786 };
2787
2788 encode_compound_hdr(xdr, req, &hdr);
2789 encode_sequence(xdr, &args->seq_args, &hdr);
2790 encode_putfh(xdr, args->dir_fh, &hdr);
2791 encode_secinfo(xdr, args->name, &hdr);
2792 encode_nops(&hdr);
2793}
2794
Benny Halevy99fe60d2009-04-01 09:22:29 -04002795#if defined(CONFIG_NFS_V4_1)
2796/*
2797 * EXCHANGE_ID request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2800 struct xdr_stream *xdr,
2801 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002802{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002803 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002804 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002805 };
2806
Chuck Lever9f06c712010-12-14 14:59:18 +00002807 encode_compound_hdr(xdr, req, &hdr);
2808 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002809 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002810}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002811
2812/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002813 * a CREATE_SESSION request
2814 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002815static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2816 struct xdr_stream *xdr,
2817 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002818{
Andy Adamsonfc931582009-04-01 09:22:31 -04002819 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002820 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002821 };
2822
Chuck Lever9f06c712010-12-14 14:59:18 +00002823 encode_compound_hdr(xdr, req, &hdr);
2824 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002825 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002826}
2827
2828/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002829 * a DESTROY_SESSION request
2830 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002831static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2832 struct xdr_stream *xdr,
2833 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002834{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002835 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002836 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002837 };
2838
Chuck Lever9f06c712010-12-14 14:59:18 +00002839 encode_compound_hdr(xdr, req, &hdr);
2840 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002841 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002842}
2843
2844/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002845 * a SEQUENCE request
2846 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002847static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2848 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002849{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002850 struct compound_hdr hdr = {
2851 .minorversion = nfs4_xdr_minorversion(args),
2852 };
2853
Chuck Lever9f06c712010-12-14 14:59:18 +00002854 encode_compound_hdr(xdr, req, &hdr);
2855 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002856 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002857}
2858
2859/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002860 * a GET_LEASE_TIME request
2861 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002862static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2863 struct xdr_stream *xdr,
2864 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002865{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002866 struct compound_hdr hdr = {
2867 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2868 };
Fred Isamandae100c2011-07-30 20:52:37 -04002869 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002870
Chuck Lever9f06c712010-12-14 14:59:18 +00002871 encode_compound_hdr(xdr, req, &hdr);
2872 encode_sequence(xdr, &args->la_seq_args, &hdr);
2873 encode_putrootfh(xdr, &hdr);
2874 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002875 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002876}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002877
2878/*
2879 * a RECLAIM_COMPLETE request
2880 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002881static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2882 struct xdr_stream *xdr,
2883 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002884{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002885 struct compound_hdr hdr = {
2886 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2887 };
2888
Chuck Lever9f06c712010-12-14 14:59:18 +00002889 encode_compound_hdr(xdr, req, &hdr);
2890 encode_sequence(xdr, &args->seq_args, &hdr);
2891 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002892 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002893}
2894
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002895/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002896 * Encode GETDEVICELIST request
2897 */
2898static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2899 struct xdr_stream *xdr,
2900 struct nfs4_getdevicelist_args *args)
2901{
2902 struct compound_hdr hdr = {
2903 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2904 };
2905
2906 encode_compound_hdr(xdr, req, &hdr);
2907 encode_sequence(xdr, &args->seq_args, &hdr);
2908 encode_putfh(xdr, args->fh, &hdr);
2909 encode_getdevicelist(xdr, args, &hdr);
2910 encode_nops(&hdr);
2911}
2912
2913/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002914 * Encode GETDEVICEINFO request
2915 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002916static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2917 struct xdr_stream *xdr,
2918 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002919{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920 struct compound_hdr hdr = {
2921 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922 };
2923
Chuck Lever9f06c712010-12-14 14:59:18 +00002924 encode_compound_hdr(xdr, req, &hdr);
2925 encode_sequence(xdr, &args->seq_args, &hdr);
2926 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002927
2928 /* set up reply kvec. Subtract notification bitmap max size (2)
2929 * so that notification bitmap is put in xdr_buf tail */
2930 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2931 args->pdev->pages, args->pdev->pgbase,
2932 args->pdev->pglen);
2933
2934 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002935}
2936
2937/*
2938 * Encode LAYOUTGET request
2939 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002940static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2941 struct xdr_stream *xdr,
2942 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002943{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002944 struct compound_hdr hdr = {
2945 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2946 };
2947
Chuck Lever9f06c712010-12-14 14:59:18 +00002948 encode_compound_hdr(xdr, req, &hdr);
2949 encode_sequence(xdr, &args->seq_args, &hdr);
2950 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2951 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002952
2953 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2954 args->layout.pages, 0, args->layout.pglen);
2955
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002956 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002957}
Andy Adamson863a3c62011-03-23 13:27:54 +00002958
2959/*
2960 * Encode LAYOUTCOMMIT request
2961 */
Benny Halevycbe82602011-05-22 19:52:37 +03002962static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2963 struct xdr_stream *xdr,
2964 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002965{
Benny Halevyac7db722011-05-22 19:53:48 +03002966 struct nfs4_layoutcommit_data *data =
2967 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970 };
2971
2972 encode_compound_hdr(xdr, req, &hdr);
2973 encode_sequence(xdr, &args->seq_args, &hdr);
2974 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002975 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002976 encode_getfattr(xdr, args->bitmask, &hdr);
2977 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002978}
2979
2980/*
2981 * Encode LAYOUTRETURN request
2982 */
2983static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2984 struct xdr_stream *xdr,
2985 struct nfs4_layoutreturn_args *args)
2986{
2987 struct compound_hdr hdr = {
2988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989 };
2990
2991 encode_compound_hdr(xdr, req, &hdr);
2992 encode_sequence(xdr, &args->seq_args, &hdr);
2993 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2994 encode_layoutreturn(xdr, args, &hdr);
2995 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002996}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002997
2998/*
2999 * Encode SECINFO_NO_NAME request
3000 */
3001static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3002 struct xdr_stream *xdr,
3003 struct nfs41_secinfo_no_name_args *args)
3004{
3005 struct compound_hdr hdr = {
3006 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007 };
3008
3009 encode_compound_hdr(xdr, req, &hdr);
3010 encode_sequence(xdr, &args->seq_args, &hdr);
3011 encode_putrootfh(xdr, &hdr);
3012 encode_secinfo_no_name(xdr, args, &hdr);
3013 encode_nops(&hdr);
3014 return 0;
3015}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003016
3017/*
3018 * Encode TEST_STATEID request
3019 */
3020static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3021 struct xdr_stream *xdr,
3022 struct nfs41_test_stateid_args *args)
3023{
3024 struct compound_hdr hdr = {
3025 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3026 };
3027
3028 encode_compound_hdr(xdr, req, &hdr);
3029 encode_sequence(xdr, &args->seq_args, &hdr);
3030 encode_test_stateid(xdr, args, &hdr);
3031 encode_nops(&hdr);
3032}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003033
3034/*
3035 * Encode FREE_STATEID request
3036 */
3037static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3038 struct xdr_stream *xdr,
3039 struct nfs41_free_stateid_args *args)
3040{
3041 struct compound_hdr hdr = {
3042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3043 };
3044
3045 encode_compound_hdr(xdr, req, &hdr);
3046 encode_sequence(xdr, &args->seq_args, &hdr);
3047 encode_free_stateid(xdr, args, &hdr);
3048 encode_nops(&hdr);
3049}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003050#endif /* CONFIG_NFS_V4_1 */
3051
Benny Halevy686841b2009-08-14 17:19:48 +03003052static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3053{
3054 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3055 "Remaining buffer length is %tu words.\n",
3056 func, xdr->end - xdr->p);
3057}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Trond Myklebust683b57b2006-06-09 09:34:22 -04003059static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
Al Viro8687b632006-10-19 23:28:48 -07003061 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Benny Halevyc0eae662009-08-14 17:20:14 +03003063 p = xdr_inline_decode(xdr, 4);
3064 if (unlikely(!p))
3065 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003066 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003067 p = xdr_inline_decode(xdr, *len);
3068 if (unlikely(!p))
3069 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 *string = (char *)p;
3071 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003072out_overflow:
3073 print_overflow_msg(__func__, xdr);
3074 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075}
3076
3077static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3078{
Al Viro8687b632006-10-19 23:28:48 -07003079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080
Benny Halevyc0eae662009-08-14 17:20:14 +03003081 p = xdr_inline_decode(xdr, 8);
3082 if (unlikely(!p))
3083 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003084 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003085 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003086
Benny Halevyc0eae662009-08-14 17:20:14 +03003087 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3088 if (unlikely(!p))
3089 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 hdr->tag = (char *)p;
3091 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003092 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003093 if (unlikely(hdr->nops < 1))
3094 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3102{
Al Viro8687b632006-10-19 23:28:48 -07003103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 uint32_t opnum;
3105 int32_t nfserr;
3106
Benny Halevyc0eae662009-08-14 17:20:14 +03003107 p = xdr_inline_decode(xdr, 8);
3108 if (unlikely(!p))
3109 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003110 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003112 dprintk("nfs: Server returned operation"
3113 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 opnum, expected);
3115 return -EIO;
3116 }
Benny Halevycccddf42009-08-14 17:20:19 +03003117 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003119 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003121out_overflow:
3122 print_overflow_msg(__func__, xdr);
3123 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124}
3125
3126/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003127static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
Al Viro8687b632006-10-19 23:28:48 -07003129 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003130 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 char *str;
3132
Benny Halevyc0eae662009-08-14 17:20:14 +03003133 p = xdr_inline_decode(xdr, 12);
3134 if (likely(p))
3135 return decode_opaque_inline(xdr, &strlen, &str);
3136 print_overflow_msg(__func__, xdr);
3137 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138}
3139
3140static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3141{
Al Viro8687b632006-10-19 23:28:48 -07003142 uint32_t bmlen;
3143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144
Benny Halevyc0eae662009-08-14 17:20:14 +03003145 p = xdr_inline_decode(xdr, 4);
3146 if (unlikely(!p))
3147 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003148 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
Fred Isamandae100c2011-07-30 20:52:37 -04003150 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003151 p = xdr_inline_decode(xdr, (bmlen << 2));
3152 if (unlikely(!p))
3153 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003155 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003156 if (bmlen > 1) {
3157 bitmap[1] = be32_to_cpup(p++);
3158 if (bmlen > 2)
3159 bitmap[2] = be32_to_cpup(p);
3160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 }
3162 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003163out_overflow:
3164 print_overflow_msg(__func__, xdr);
3165 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166}
3167
Al Viro8687b632006-10-19 23:28:48 -07003168static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
Al Viro8687b632006-10-19 23:28:48 -07003170 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
Benny Halevyc0eae662009-08-14 17:20:14 +03003172 p = xdr_inline_decode(xdr, 4);
3173 if (unlikely(!p))
3174 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003175 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 *savep = xdr->p;
3177 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003178out_overflow:
3179 print_overflow_msg(__func__, xdr);
3180 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181}
3182
3183static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3184{
3185 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003186 int ret;
3187 ret = decode_attr_bitmap(xdr, bitmask);
3188 if (unlikely(ret < 0))
3189 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3191 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003192 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3193 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3194 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 return 0;
3196}
3197
3198static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3199{
Al Viro8687b632006-10-19 23:28:48 -07003200 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003201 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202
3203 *type = 0;
3204 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3205 return -EIO;
3206 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003207 p = xdr_inline_decode(xdr, 4);
3208 if (unlikely(!p))
3209 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003210 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003212 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 return -EIO;
3214 }
3215 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003216 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003218 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003219 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003220out_overflow:
3221 print_overflow_msg(__func__, xdr);
3222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223}
3224
3225static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3226{
Al Viro8687b632006-10-19 23:28:48 -07003227 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230 *change = 0;
3231 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3232 return -EIO;
3233 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003234 p = xdr_inline_decode(xdr, 8);
3235 if (unlikely(!p))
3236 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003237 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003239 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003241 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003243 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003244out_overflow:
3245 print_overflow_msg(__func__, xdr);
3246 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247}
3248
3249static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3250{
Al Viro8687b632006-10-19 23:28:48 -07003251 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254 *size = 0;
3255 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3256 return -EIO;
3257 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003258 p = xdr_inline_decode(xdr, 8);
3259 if (unlikely(!p))
3260 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003261 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003263 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003265 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003266 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003267out_overflow:
3268 print_overflow_msg(__func__, xdr);
3269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270}
3271
3272static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3273{
Al Viro8687b632006-10-19 23:28:48 -07003274 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275
3276 *res = 0;
3277 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3278 return -EIO;
3279 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003280 p = xdr_inline_decode(xdr, 4);
3281 if (unlikely(!p))
3282 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003283 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3285 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003286 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003288out_overflow:
3289 print_overflow_msg(__func__, xdr);
3290 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291}
3292
3293static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3294{
Al Viro8687b632006-10-19 23:28:48 -07003295 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
3297 *res = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003301 p = xdr_inline_decode(xdr, 4);
3302 if (unlikely(!p))
3303 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003304 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3306 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003307 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003309out_overflow:
3310 print_overflow_msg(__func__, xdr);
3311 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312}
3313
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003314static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315{
Al Viro8687b632006-10-19 23:28:48 -07003316 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003317 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 fsid->major = 0;
3320 fsid->minor = 0;
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003324 p = xdr_inline_decode(xdr, 16);
3325 if (unlikely(!p))
3326 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003327 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003328 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003330 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003332 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 (unsigned long long)fsid->major,
3334 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003335 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003336out_overflow:
3337 print_overflow_msg(__func__, xdr);
3338 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339}
3340
3341static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3342{
Al Viro8687b632006-10-19 23:28:48 -07003343 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
3345 *res = 60;
3346 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3347 return -EIO;
3348 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003349 p = xdr_inline_decode(xdr, 4);
3350 if (unlikely(!p))
3351 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003352 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003357out_overflow:
3358 print_overflow_msg(__func__, xdr);
3359 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360}
3361
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003362static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003363{
3364 __be32 *p;
3365
3366 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3367 return -EIO;
3368 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3369 p = xdr_inline_decode(xdr, 4);
3370 if (unlikely(!p))
3371 goto out_overflow;
3372 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003373 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003374 }
3375 return 0;
3376out_overflow:
3377 print_overflow_msg(__func__, xdr);
3378 return -EIO;
3379}
3380
3381static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3382{
3383 __be32 *p;
3384 int len;
3385
Trond Myklebust7ad07352010-10-23 15:34:20 -04003386 if (fh != NULL)
3387 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003388
3389 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3390 return -EIO;
3391 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3392 p = xdr_inline_decode(xdr, 4);
3393 if (unlikely(!p))
3394 goto out_overflow;
3395 len = be32_to_cpup(p);
3396 if (len > NFS4_FHSIZE)
3397 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003398 p = xdr_inline_decode(xdr, len);
3399 if (unlikely(!p))
3400 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003401 if (fh != NULL) {
3402 memcpy(fh->data, p, len);
3403 fh->size = len;
3404 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003405 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3406 }
3407 return 0;
3408out_overflow:
3409 print_overflow_msg(__func__, xdr);
3410 return -EIO;
3411}
3412
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3414{
Al Viro8687b632006-10-19 23:28:48 -07003415 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
3417 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3418 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3419 return -EIO;
3420 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003421 p = xdr_inline_decode(xdr, 4);
3422 if (unlikely(!p))
3423 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003424 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3426 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003427 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003429out_overflow:
3430 print_overflow_msg(__func__, xdr);
3431 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432}
3433
3434static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3435{
Al Viro8687b632006-10-19 23:28:48 -07003436 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003437 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
3439 *fileid = 0;
3440 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3441 return -EIO;
3442 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003443 p = xdr_inline_decode(xdr, 8);
3444 if (unlikely(!p))
3445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003446 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003450 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003451 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003452out_overflow:
3453 print_overflow_msg(__func__, xdr);
3454 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455}
3456
Manoj Naik99baf622006-06-09 09:34:24 -04003457static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3458{
Al Viro8687b632006-10-19 23:28:48 -07003459 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003460 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003461
3462 *fileid = 0;
3463 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3464 return -EIO;
3465 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003466 p = xdr_inline_decode(xdr, 8);
3467 if (unlikely(!p))
3468 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003469 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003470 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003471 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003472 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003473 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003474 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003475out_overflow:
3476 print_overflow_msg(__func__, xdr);
3477 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003478}
3479
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3481{
Al Viro8687b632006-10-19 23:28:48 -07003482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 int status = 0;
3484
3485 *res = 0;
3486 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3487 return -EIO;
3488 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003489 p = xdr_inline_decode(xdr, 8);
3490 if (unlikely(!p))
3491 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003492 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3494 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003495 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003497out_overflow:
3498 print_overflow_msg(__func__, xdr);
3499 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500}
3501
3502static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3503{
Al Viro8687b632006-10-19 23:28:48 -07003504 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 int status = 0;
3506
3507 *res = 0;
3508 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3509 return -EIO;
3510 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003511 p = xdr_inline_decode(xdr, 8);
3512 if (unlikely(!p))
3513 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003514 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3516 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003517 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003519out_overflow:
3520 print_overflow_msg(__func__, xdr);
3521 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522}
3523
3524static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3525{
Al Viro8687b632006-10-19 23:28:48 -07003526 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 int status = 0;
3528
3529 *res = 0;
3530 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3531 return -EIO;
3532 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003533 p = xdr_inline_decode(xdr, 8);
3534 if (unlikely(!p))
3535 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003536 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3538 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003539 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003541out_overflow:
3542 print_overflow_msg(__func__, xdr);
3543 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544}
3545
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003546static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3547{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003548 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003549 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003550 int status = 0;
3551
Benny Halevyc0eae662009-08-14 17:20:14 +03003552 p = xdr_inline_decode(xdr, 4);
3553 if (unlikely(!p))
3554 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003555 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003556 if (n == 0)
3557 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003558 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003559 path->ncomponents = 0;
3560 while (path->ncomponents < n) {
3561 struct nfs4_string *component = &path->components[path->ncomponents];
3562 status = decode_opaque_inline(xdr, &component->len, &component->data);
3563 if (unlikely(status != 0))
3564 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003565 if (unlikely(nfs_debug & NFSDBG_XDR))
3566 pr_cont("%s%.*s ",
3567 (path->ncomponents != n ? "/ " : ""),
3568 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003569 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3570 path->ncomponents++;
3571 else {
3572 dprintk("cannot parse %d components in path\n", n);
3573 goto out_eio;
3574 }
3575 }
3576out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003577 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003578root_path:
3579/* a root pathname is sent as a zero component4 */
3580 path->ncomponents = 1;
3581 path->components[0].len=0;
3582 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003583 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003584 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003585out_eio:
3586 dprintk(" status %d", status);
3587 status = -EIO;
3588 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003589out_overflow:
3590 print_overflow_msg(__func__, xdr);
3591 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003592}
3593
3594static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003595{
3596 int n;
Al Viro8687b632006-10-19 23:28:48 -07003597 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003598 int status = -EIO;
3599
3600 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3601 goto out;
3602 status = 0;
3603 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3604 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003605 status = -EIO;
3606 /* Ignore borken servers that return unrequested attrs */
3607 if (unlikely(res == NULL))
3608 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003609 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003610 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003611 if (unlikely(status != 0))
3612 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003613 p = xdr_inline_decode(xdr, 4);
3614 if (unlikely(!p))
3615 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003616 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003617 if (n <= 0)
3618 goto out_eio;
3619 res->nlocations = 0;
3620 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003621 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003622 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003623
Benny Halevyc0eae662009-08-14 17:20:14 +03003624 p = xdr_inline_decode(xdr, 4);
3625 if (unlikely(!p))
3626 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003627 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003628
3629 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003630 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003631 while (loc->nservers < m) {
3632 struct nfs4_string *server = &loc->servers[loc->nservers];
3633 status = decode_opaque_inline(xdr, &server->len, &server->data);
3634 if (unlikely(status != 0))
3635 goto out_eio;
3636 dprintk("%s ", server->data);
3637 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3638 loc->nservers++;
3639 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003640 unsigned int i;
3641 dprintk("%s: using first %u of %u servers "
3642 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003643 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003644 NFS4_FS_LOCATION_MAXSERVERS,
3645 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003646 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003647 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003648 char *data;
3649 status = decode_opaque_inline(xdr, &len, &data);
3650 if (unlikely(status != 0))
3651 goto out_eio;
3652 }
3653 }
3654 }
3655 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003656 if (unlikely(status != 0))
3657 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003658 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659 res->nlocations++;
3660 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003661 if (res->nlocations != 0)
3662 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003663out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003664 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003665 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003666out_overflow:
3667 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003668out_eio:
3669 status = -EIO;
3670 goto out;
3671}
3672
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3674{
Al Viro8687b632006-10-19 23:28:48 -07003675 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 int status = 0;
3677
3678 *res = 0;
3679 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3680 return -EIO;
3681 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003682 p = xdr_inline_decode(xdr, 8);
3683 if (unlikely(!p))
3684 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003685 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3687 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003688 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003690out_overflow:
3691 print_overflow_msg(__func__, xdr);
3692 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693}
3694
3695static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3696{
Al Viro8687b632006-10-19 23:28:48 -07003697 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 int status = 0;
3699
3700 *maxlink = 1;
3701 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3702 return -EIO;
3703 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003704 p = xdr_inline_decode(xdr, 4);
3705 if (unlikely(!p))
3706 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003707 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3709 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003710 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003712out_overflow:
3713 print_overflow_msg(__func__, xdr);
3714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715}
3716
3717static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3718{
Al Viro8687b632006-10-19 23:28:48 -07003719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 int status = 0;
3721
3722 *maxname = 1024;
3723 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3724 return -EIO;
3725 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003726 p = xdr_inline_decode(xdr, 4);
3727 if (unlikely(!p))
3728 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003729 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3731 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003732 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003734out_overflow:
3735 print_overflow_msg(__func__, xdr);
3736 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737}
3738
3739static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3740{
Al Viro8687b632006-10-19 23:28:48 -07003741 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 int status = 0;
3743
3744 *res = 1024;
3745 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3746 return -EIO;
3747 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3748 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003749 p = xdr_inline_decode(xdr, 8);
3750 if (unlikely(!p))
3751 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003752 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 if (maxread > 0x7FFFFFFF)
3754 maxread = 0x7FFFFFFF;
3755 *res = (uint32_t)maxread;
3756 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3757 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003758 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003760out_overflow:
3761 print_overflow_msg(__func__, xdr);
3762 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763}
3764
3765static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3766{
Al Viro8687b632006-10-19 23:28:48 -07003767 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 int status = 0;
3769
3770 *res = 1024;
3771 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3772 return -EIO;
3773 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3774 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003775 p = xdr_inline_decode(xdr, 8);
3776 if (unlikely(!p))
3777 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003778 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 if (maxwrite > 0x7FFFFFFF)
3780 maxwrite = 0x7FFFFFFF;
3781 *res = (uint32_t)maxwrite;
3782 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3783 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003784 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003786out_overflow:
3787 print_overflow_msg(__func__, xdr);
3788 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789}
3790
Trond Myklebustbca79472009-03-11 14:10:26 -04003791static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792{
Trond Myklebustbca79472009-03-11 14:10:26 -04003793 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003794 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796
3797 *mode = 0;
3798 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3799 return -EIO;
3800 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003801 p = xdr_inline_decode(xdr, 4);
3802 if (unlikely(!p))
3803 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003804 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003805 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003807 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003809 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003810 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003811out_overflow:
3812 print_overflow_msg(__func__, xdr);
3813 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814}
3815
3816static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3817{
Al Viro8687b632006-10-19 23:28:48 -07003818 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
3821 *nlink = 1;
3822 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3823 return -EIO;
3824 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003825 p = xdr_inline_decode(xdr, 4);
3826 if (unlikely(!p))
3827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003828 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003832 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003833 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003834out_overflow:
3835 print_overflow_msg(__func__, xdr);
3836 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837}
3838
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003839static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003840 const struct nfs_server *server, uint32_t *uid,
3841 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842{
Al Viro8687b632006-10-19 23:28:48 -07003843 uint32_t len;
3844 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003845 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
3847 *uid = -2;
3848 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3849 return -EIO;
3850 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003851 p = xdr_inline_decode(xdr, 4);
3852 if (unlikely(!p))
3853 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003854 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003855 p = xdr_inline_decode(xdr, len);
3856 if (unlikely(!p))
3857 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003858 if (owner_name != NULL) {
3859 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3860 if (owner_name->data != NULL) {
3861 owner_name->len = len;
3862 ret = NFS_ATTR_FATTR_OWNER_NAME;
3863 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003864 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003865 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003866 ret = NFS_ATTR_FATTR_OWNER;
3867 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003869 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003871 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003872 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3874 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003875 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003876 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003877out_overflow:
3878 print_overflow_msg(__func__, xdr);
3879 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880}
3881
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003882static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003883 const struct nfs_server *server, uint32_t *gid,
3884 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885{
Al Viro8687b632006-10-19 23:28:48 -07003886 uint32_t len;
3887 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003888 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889
3890 *gid = -2;
3891 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3892 return -EIO;
3893 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003894 p = xdr_inline_decode(xdr, 4);
3895 if (unlikely(!p))
3896 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003897 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003898 p = xdr_inline_decode(xdr, len);
3899 if (unlikely(!p))
3900 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003901 if (group_name != NULL) {
3902 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3903 if (group_name->data != NULL) {
3904 group_name->len = len;
3905 ret = NFS_ATTR_FATTR_GROUP_NAME;
3906 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003907 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003908 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003909 ret = NFS_ATTR_FATTR_GROUP;
3910 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003912 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003914 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003915 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3917 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003918 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003919 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003920out_overflow:
3921 print_overflow_msg(__func__, xdr);
3922 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923}
3924
3925static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3926{
Al Viro8687b632006-10-19 23:28:48 -07003927 uint32_t major = 0, minor = 0;
3928 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003929 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
3931 *rdev = MKDEV(0,0);
3932 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3933 return -EIO;
3934 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3935 dev_t tmp;
3936
Benny Halevyc0eae662009-08-14 17:20:14 +03003937 p = xdr_inline_decode(xdr, 8);
3938 if (unlikely(!p))
3939 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003940 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003941 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 tmp = MKDEV(major, minor);
3943 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3944 *rdev = tmp;
3945 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003946 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003948 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003949 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003950out_overflow:
3951 print_overflow_msg(__func__, xdr);
3952 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953}
3954
3955static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3956{
Al Viro8687b632006-10-19 23:28:48 -07003957 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 int status = 0;
3959
3960 *res = 0;
3961 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3962 return -EIO;
3963 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003964 p = xdr_inline_decode(xdr, 8);
3965 if (unlikely(!p))
3966 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003967 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3969 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003970 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003972out_overflow:
3973 print_overflow_msg(__func__, xdr);
3974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
3977static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3978{
Al Viro8687b632006-10-19 23:28:48 -07003979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 int status = 0;
3981
3982 *res = 0;
3983 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3984 return -EIO;
3985 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003986 p = xdr_inline_decode(xdr, 8);
3987 if (unlikely(!p))
3988 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003989 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3991 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003992 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003994out_overflow:
3995 print_overflow_msg(__func__, xdr);
3996 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997}
3998
3999static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4000{
Al Viro8687b632006-10-19 23:28:48 -07004001 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 int status = 0;
4003
4004 *res = 0;
4005 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4006 return -EIO;
4007 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004008 p = xdr_inline_decode(xdr, 8);
4009 if (unlikely(!p))
4010 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004011 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4013 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004014 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004016out_overflow:
4017 print_overflow_msg(__func__, xdr);
4018 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019}
4020
4021static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4022{
Al Viro8687b632006-10-19 23:28:48 -07004023 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004024 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
4026 *used = 0;
4027 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4028 return -EIO;
4029 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004030 p = xdr_inline_decode(xdr, 8);
4031 if (unlikely(!p))
4032 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004033 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004035 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004037 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004039 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004040out_overflow:
4041 print_overflow_msg(__func__, xdr);
4042 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043}
4044
4045static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4046{
Al Viro8687b632006-10-19 23:28:48 -07004047 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 uint64_t sec;
4049 uint32_t nsec;
4050
Benny Halevyc0eae662009-08-14 17:20:14 +03004051 p = xdr_inline_decode(xdr, 12);
4052 if (unlikely(!p))
4053 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004054 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004055 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 time->tv_sec = (time_t)sec;
4057 time->tv_nsec = (long)nsec;
4058 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004059out_overflow:
4060 print_overflow_msg(__func__, xdr);
4061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062}
4063
4064static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4065{
4066 int status = 0;
4067
4068 time->tv_sec = 0;
4069 time->tv_nsec = 0;
4070 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4071 return -EIO;
4072 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4073 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004074 if (status == 0)
4075 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4077 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004078 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 return status;
4080}
4081
4082static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4083{
4084 int status = 0;
4085
4086 time->tv_sec = 0;
4087 time->tv_nsec = 0;
4088 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4089 return -EIO;
4090 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4091 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004092 if (status == 0)
4093 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4095 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004096 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 return status;
4098}
4099
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004100static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4101 struct timespec *time)
4102{
4103 int status = 0;
4104
4105 time->tv_sec = 0;
4106 time->tv_nsec = 0;
4107 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4108 return -EIO;
4109 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4110 status = decode_attr_time(xdr, time);
4111 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4112 }
4113 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4114 (long)time->tv_nsec);
4115 return status;
4116}
4117
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4119{
4120 int status = 0;
4121
4122 time->tv_sec = 0;
4123 time->tv_nsec = 0;
4124 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4125 return -EIO;
4126 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4127 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004128 if (status == 0)
4129 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4131 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004132 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 return status;
4134}
4135
Al Viro8687b632006-10-19 23:28:48 -07004136static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137{
4138 unsigned int attrwords = XDR_QUADLEN(attrlen);
4139 unsigned int nwords = xdr->p - savep;
4140
4141 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004142 dprintk("%s: server returned incorrect attribute length: "
4143 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004144 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 attrwords << 2,
4146 (attrwords < nwords) ? '<' : '>',
4147 nwords << 2);
4148 return -EIO;
4149 }
4150 return 0;
4151}
4152
4153static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4154{
Al Viro8687b632006-10-19 23:28:48 -07004155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
Benny Halevyc0eae662009-08-14 17:20:14 +03004157 p = xdr_inline_decode(xdr, 20);
4158 if (unlikely(!p))
4159 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004160 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004161 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004162 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004164out_overflow:
4165 print_overflow_msg(__func__, xdr);
4166 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167}
4168
4169static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4170{
Al Viro8687b632006-10-19 23:28:48 -07004171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 uint32_t supp, acc;
4173 int status;
4174
4175 status = decode_op_hdr(xdr, OP_ACCESS);
4176 if (status)
4177 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004178 p = xdr_inline_decode(xdr, 8);
4179 if (unlikely(!p))
4180 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004181 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004182 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 access->supported = supp;
4184 access->access = acc;
4185 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004186out_overflow:
4187 print_overflow_msg(__func__, xdr);
4188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189}
4190
Benny Halevy07d30432009-08-14 17:19:52 +03004191static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192{
Al Viro8687b632006-10-19 23:28:48 -07004193 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004194
4195 p = xdr_inline_decode(xdr, len);
4196 if (likely(p)) {
4197 memcpy(buf, p, len);
4198 return 0;
4199 }
4200 print_overflow_msg(__func__, xdr);
4201 return -EIO;
4202}
4203
4204static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4205{
4206 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207}
4208
4209static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4210{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 int status;
4212
4213 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004214 if (status != -EIO)
4215 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004216 if (!status)
4217 status = decode_stateid(xdr, &res->stateid);
4218 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219}
4220
Benny Halevydb942bb2009-08-14 17:19:56 +03004221static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4222{
4223 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224}
4225
4226static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4227{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 int status;
4229
4230 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004231 if (!status)
4232 status = decode_verifier(xdr, res->verf->verifier);
4233 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234}
4235
4236static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4237{
Al Viro8687b632006-10-19 23:28:48 -07004238 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 uint32_t bmlen;
4240 int status;
4241
4242 status = decode_op_hdr(xdr, OP_CREATE);
4243 if (status)
4244 return status;
4245 if ((status = decode_change_info(xdr, cinfo)))
4246 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004247 p = xdr_inline_decode(xdr, 4);
4248 if (unlikely(!p))
4249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004250 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004251 p = xdr_inline_decode(xdr, bmlen << 2);
4252 if (likely(p))
4253 return 0;
4254out_overflow:
4255 print_overflow_msg(__func__, xdr);
4256 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257}
4258
4259static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4260{
Al Viro8687b632006-10-19 23:28:48 -07004261 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004262 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 int status;
4264
4265 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4266 goto xdr_error;
4267 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4268 goto xdr_error;
4269 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4270 goto xdr_error;
4271 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4272 goto xdr_error;
4273 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4274 goto xdr_error;
4275 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4276 goto xdr_error;
4277 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4278 goto xdr_error;
4279 status = verify_attr_len(xdr, savep, attrlen);
4280xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004281 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 return status;
4283}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004284
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4286{
Al Viro8687b632006-10-19 23:28:48 -07004287 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004288 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004290
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4292 goto xdr_error;
4293 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4294 goto xdr_error;
4295 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4296 goto xdr_error;
4297
4298 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4299 goto xdr_error;
4300 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4301 goto xdr_error;
4302 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4303 goto xdr_error;
4304 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4305 goto xdr_error;
4306 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4307 goto xdr_error;
4308 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4309 goto xdr_error;
4310
4311 status = verify_attr_len(xdr, savep, attrlen);
4312xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004313 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 return status;
4315}
4316
4317static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4318{
Al Viro8687b632006-10-19 23:28:48 -07004319 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004320 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004322
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4324 goto xdr_error;
4325 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4326 goto xdr_error;
4327 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4328 goto xdr_error;
4329
4330 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4331 goto xdr_error;
4332 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4333 goto xdr_error;
4334
4335 status = verify_attr_len(xdr, savep, attrlen);
4336xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004337 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 return status;
4339}
4340
Bryan Schumakerae42c702010-10-21 16:33:17 -04004341static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4342 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004343 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004344 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345{
Trond Myklebustbca79472009-03-11 14:10:26 -04004346 int status;
4347 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004348 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004349 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004351 status = decode_attr_type(xdr, bitmap, &type);
4352 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004354 fattr->mode = 0;
4355 if (status != 0) {
4356 fattr->mode |= nfs_type2fmt[type];
4357 fattr->valid |= status;
4358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004360 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4361 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004363 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004364
4365 status = decode_attr_size(xdr, bitmap, &fattr->size);
4366 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004368 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004369
4370 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4371 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004373 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004374
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004375 err = 0;
4376 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004377 if (status < 0)
4378 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004379 if (err == -NFS4ERR_WRONGSEC)
4380 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004381
4382 status = decode_attr_filehandle(xdr, bitmap, fh);
4383 if (status < 0)
4384 goto xdr_error;
4385
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004386 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4387 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004389 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004390
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004391 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004392 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004393 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004394 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004395
4396 status = decode_attr_mode(xdr, bitmap, &fmode);
4397 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004399 if (status != 0) {
4400 fattr->mode |= fmode;
4401 fattr->valid |= status;
4402 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004403
4404 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4405 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004407 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004408
Trond Myklebust6926afd2012-01-07 13:22:46 -05004409 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004410 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004412 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004413
Trond Myklebust6926afd2012-01-07 13:22:46 -05004414 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004415 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004417 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004418
4419 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4420 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004422 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004423
4424 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4425 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004427 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004428
4429 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4430 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004432 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004433
4434 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4435 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004437 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004438
4439 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4440 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004442 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004443
Trond Myklebust28331a42011-04-27 13:47:52 -04004444 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004445 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004446 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004447 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004448
Bryan Schumakerae42c702010-10-21 16:33:17 -04004449xdr_error:
4450 dprintk("%s: xdr returned %d\n", __func__, -status);
4451 return status;
4452}
4453
4454static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004455 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4456 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004457{
4458 __be32 *savep;
4459 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004460 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004461 int status;
4462
4463 status = decode_op_hdr(xdr, OP_GETATTR);
4464 if (status < 0)
4465 goto xdr_error;
4466
4467 status = decode_attr_bitmap(xdr, bitmap);
4468 if (status < 0)
4469 goto xdr_error;
4470
4471 status = decode_attr_length(xdr, &attrlen, &savep);
4472 if (status < 0)
4473 goto xdr_error;
4474
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004475 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004476 if (status < 0)
4477 goto xdr_error;
4478
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004479 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004481 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 return status;
4483}
4484
Bryan Schumakerae42c702010-10-21 16:33:17 -04004485static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004486 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004487{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004488 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004489}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490
Andy Adamson504913f2010-10-20 00:17:57 -04004491/*
4492 * Decode potentially multiple layout types. Currently we only support
4493 * one layout driver per file system.
4494 */
4495static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4496 uint32_t *layouttype)
4497{
4498 uint32_t *p;
4499 int num;
4500
4501 p = xdr_inline_decode(xdr, 4);
4502 if (unlikely(!p))
4503 goto out_overflow;
4504 num = be32_to_cpup(p);
4505
4506 /* pNFS is not supported by the underlying file system */
4507 if (num == 0) {
4508 *layouttype = 0;
4509 return 0;
4510 }
4511 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004512 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4513 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004514
4515 /* Decode and set first layout type, move xdr->p past unused types */
4516 p = xdr_inline_decode(xdr, num * 4);
4517 if (unlikely(!p))
4518 goto out_overflow;
4519 *layouttype = be32_to_cpup(p);
4520 return 0;
4521out_overflow:
4522 print_overflow_msg(__func__, xdr);
4523 return -EIO;
4524}
4525
4526/*
4527 * The type of file system exported.
4528 * Note we must ensure that layouttype is set in any non-error case.
4529 */
4530static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4531 uint32_t *layouttype)
4532{
4533 int status = 0;
4534
4535 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4536 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4537 return -EIO;
4538 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4539 status = decode_first_pnfs_layout_type(xdr, layouttype);
4540 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4541 } else
4542 *layouttype = 0;
4543 return status;
4544}
4545
Fred Isamandae100c2011-07-30 20:52:37 -04004546/*
4547 * The prefered block size for layout directed io
4548 */
4549static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4550 uint32_t *res)
4551{
4552 __be32 *p;
4553
4554 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4555 *res = 0;
4556 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4557 p = xdr_inline_decode(xdr, 4);
4558 if (unlikely(!p)) {
4559 print_overflow_msg(__func__, xdr);
4560 return -EIO;
4561 }
4562 *res = be32_to_cpup(p);
4563 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4564 }
4565 return 0;
4566}
4567
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4569{
Al Viro8687b632006-10-19 23:28:48 -07004570 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004571 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 int status;
4573
4574 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4575 goto xdr_error;
4576 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4577 goto xdr_error;
4578 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4579 goto xdr_error;
4580
4581 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4582
4583 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4584 goto xdr_error;
4585 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4586 goto xdr_error;
4587 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4588 goto xdr_error;
4589 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4590 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4591 goto xdr_error;
4592 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004593 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4594 if (status != 0)
4595 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004596 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4597 if (status != 0)
4598 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004599 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4600 if (status)
4601 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602
4603 status = verify_attr_len(xdr, savep, attrlen);
4604xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004605 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 return status;
4607}
4608
4609static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4610{
Al Viro8687b632006-10-19 23:28:48 -07004611 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 uint32_t len;
4613 int status;
4614
Trond Myklebust99367812007-07-17 21:52:41 -04004615 /* Zero handle first to allow comparisons */
4616 memset(fh, 0, sizeof(*fh));
4617
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 status = decode_op_hdr(xdr, OP_GETFH);
4619 if (status)
4620 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621
Benny Halevyc0eae662009-08-14 17:20:14 +03004622 p = xdr_inline_decode(xdr, 4);
4623 if (unlikely(!p))
4624 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004625 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 if (len > NFS4_FHSIZE)
4627 return -EIO;
4628 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004629 p = xdr_inline_decode(xdr, len);
4630 if (unlikely(!p))
4631 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004632 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004634out_overflow:
4635 print_overflow_msg(__func__, xdr);
4636 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637}
4638
4639static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4640{
4641 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004642
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 status = decode_op_hdr(xdr, OP_LINK);
4644 if (status)
4645 return status;
4646 return decode_change_info(xdr, cinfo);
4647}
4648
4649/*
4650 * We create the owner, so we know a proper owner.id length is 4.
4651 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004652static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004654 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004655 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004656 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004658 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004659 if (unlikely(!p))
4660 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004661 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004662 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004663 type = be32_to_cpup(p++); /* 4 byte read */
4664 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004665 fl->fl_start = (loff_t)offset;
4666 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4667 if (length == ~(uint64_t)0)
4668 fl->fl_end = OFFSET_MAX;
4669 fl->fl_type = F_WRLCK;
4670 if (type & 1)
4671 fl->fl_type = F_RDLCK;
4672 fl->fl_pid = 0;
4673 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004674 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4675 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4676 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004677 if (likely(p))
4678 return -NFS4ERR_DENIED;
4679out_overflow:
4680 print_overflow_msg(__func__, xdr);
4681 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682}
4683
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004684static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 int status;
4687
4688 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004689 if (status == -EIO)
4690 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004692 status = decode_stateid(xdr, &res->stateid);
4693 if (unlikely(status))
4694 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004696 status = decode_lock_denied(xdr, NULL);
4697 if (res->open_seqid != NULL)
4698 nfs_increment_open_seqid(status, res->open_seqid);
4699 nfs_increment_lock_seqid(status, res->lock_seqid);
4700out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 return status;
4702}
4703
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004704static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705{
4706 int status;
4707 status = decode_op_hdr(xdr, OP_LOCKT);
4708 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004709 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710 return status;
4711}
4712
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004713static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 int status;
4716
4717 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004718 if (status != -EIO)
4719 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004720 if (status == 0)
4721 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 return status;
4723}
4724
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004725static int decode_release_lockowner(struct xdr_stream *xdr)
4726{
4727 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4728}
4729
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730static int decode_lookup(struct xdr_stream *xdr)
4731{
4732 return decode_op_hdr(xdr, OP_LOOKUP);
4733}
4734
4735/* This is too sick! */
4736static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4737{
Andy Adamson05d564f2008-12-23 16:06:15 -05004738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 uint32_t limit_type, nblocks, blocksize;
4740
Benny Halevyc0eae662009-08-14 17:20:14 +03004741 p = xdr_inline_decode(xdr, 12);
4742 if (unlikely(!p))
4743 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004744 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004746 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004747 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004748 break;
4749 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004750 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004751 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004752 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 }
4754 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004755out_overflow:
4756 print_overflow_msg(__func__, xdr);
4757 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758}
4759
4760static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4761{
Andy Adamson05d564f2008-12-23 16:06:15 -05004762 __be32 *p;
4763 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004764 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765
Benny Halevyc0eae662009-08-14 17:20:14 +03004766 p = xdr_inline_decode(xdr, 4);
4767 if (unlikely(!p))
4768 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004769 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4771 res->delegation_type = 0;
4772 return 0;
4773 }
Benny Halevy07d30432009-08-14 17:19:52 +03004774 status = decode_stateid(xdr, &res->delegation);
4775 if (unlikely(status))
4776 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004777 p = xdr_inline_decode(xdr, 4);
4778 if (unlikely(!p))
4779 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004780 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004781
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004783 case NFS4_OPEN_DELEGATE_READ:
4784 res->delegation_type = FMODE_READ;
4785 break;
4786 case NFS4_OPEN_DELEGATE_WRITE:
4787 res->delegation_type = FMODE_WRITE|FMODE_READ;
4788 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 return -EIO;
4790 }
David Howells7539bba2006-08-22 20:06:09 -04004791 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004792out_overflow:
4793 print_overflow_msg(__func__, xdr);
4794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795}
4796
4797static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4798{
Andy Adamson05d564f2008-12-23 16:06:15 -05004799 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004800 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004801 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802
Andy Adamson05d564f2008-12-23 16:06:15 -05004803 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004804 if (status != -EIO)
4805 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004806 if (!status)
4807 status = decode_stateid(xdr, &res->stateid);
4808 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004809 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810
Andy Adamson05d564f2008-12-23 16:06:15 -05004811 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812
Benny Halevyc0eae662009-08-14 17:20:14 +03004813 p = xdr_inline_decode(xdr, 8);
4814 if (unlikely(!p))
4815 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004816 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004817 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004818 if (bmlen > 10)
4819 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820
Benny Halevyc0eae662009-08-14 17:20:14 +03004821 p = xdr_inline_decode(xdr, bmlen << 2);
4822 if (unlikely(!p))
4823 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004824 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4825 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004826 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004827 for (; i < NFS4_BITMAP_SIZE; i++)
4828 res->attrset[i] = 0;
4829
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 return decode_delegation(xdr, res);
4831xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004832 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004834out_overflow:
4835 print_overflow_msg(__func__, xdr);
4836 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837}
4838
4839static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4840{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 int status;
4842
Andy Adamson05d564f2008-12-23 16:06:15 -05004843 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004844 if (status != -EIO)
4845 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004846 if (!status)
4847 status = decode_stateid(xdr, &res->stateid);
4848 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849}
4850
4851static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4852{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 int status;
4854
4855 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004856 if (status != -EIO)
4857 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004858 if (!status)
4859 status = decode_stateid(xdr, &res->stateid);
4860 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861}
4862
4863static int decode_putfh(struct xdr_stream *xdr)
4864{
4865 return decode_op_hdr(xdr, OP_PUTFH);
4866}
4867
4868static int decode_putrootfh(struct xdr_stream *xdr)
4869{
4870 return decode_op_hdr(xdr, OP_PUTROOTFH);
4871}
4872
4873static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4874{
4875 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004876 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 uint32_t count, eof, recvd, hdrlen;
4878 int status;
4879
4880 status = decode_op_hdr(xdr, OP_READ);
4881 if (status)
4882 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004883 p = xdr_inline_decode(xdr, 8);
4884 if (unlikely(!p))
4885 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004886 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004887 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004888 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 recvd = req->rq_rcv_buf.len - hdrlen;
4890 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004891 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 "count %u > recvd %u\n", count, recvd);
4893 count = recvd;
4894 eof = 0;
4895 }
4896 xdr_read_pages(xdr, count);
4897 res->eof = eof;
4898 res->count = count;
4899 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004900out_overflow:
4901 print_overflow_msg(__func__, xdr);
4902 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903}
4904
4905static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4906{
4907 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004909 size_t hdrlen;
4910 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004911 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912
4913 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004914 if (!status)
4915 status = decode_verifier(xdr, readdir->verifier.data);
4916 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004918 dprintk("%s: verifier = %08x:%08x\n",
4919 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004920 ((u32 *)readdir->verifier.data)[0],
4921 ((u32 *)readdir->verifier.data)[1]);
4922
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923
Benny Halevydb942bb2009-08-14 17:19:56 +03004924 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 recvd = rcvbuf->len - hdrlen;
4926 if (pglen > recvd)
4927 pglen = recvd;
4928 xdr_read_pages(xdr, pglen);
4929
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004930
Trond Myklebustac396122010-11-15 20:26:22 -05004931 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932}
4933
4934static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4935{
4936 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4937 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004938 size_t hdrlen;
4939 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004940 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 int status;
4942
4943 status = decode_op_hdr(xdr, OP_READLINK);
4944 if (status)
4945 return status;
4946
4947 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004948 p = xdr_inline_decode(xdr, 4);
4949 if (unlikely(!p))
4950 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004951 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004953 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 return -ENAMETOOLONG;
4955 }
4956 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4957 recvd = req->rq_rcv_buf.len - hdrlen;
4958 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004959 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 "count %u > recvd %u\n", len, recvd);
4961 return -EIO;
4962 }
4963 xdr_read_pages(xdr, len);
4964 /*
4965 * The XDR encode routine has set things up so that
4966 * the link text will be copied directly into the
4967 * buffer. We just have to do overflow-checking,
4968 * and and null-terminate the text (the VFS expects
4969 * null-termination).
4970 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004971 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004973out_overflow:
4974 print_overflow_msg(__func__, xdr);
4975 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976}
4977
4978static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4979{
4980 int status;
4981
4982 status = decode_op_hdr(xdr, OP_REMOVE);
4983 if (status)
4984 goto out;
4985 status = decode_change_info(xdr, cinfo);
4986out:
4987 return status;
4988}
4989
4990static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4991 struct nfs4_change_info *new_cinfo)
4992{
4993 int status;
4994
4995 status = decode_op_hdr(xdr, OP_RENAME);
4996 if (status)
4997 goto out;
4998 if ((status = decode_change_info(xdr, old_cinfo)))
4999 goto out;
5000 status = decode_change_info(xdr, new_cinfo);
5001out:
5002 return status;
5003}
5004
5005static int decode_renew(struct xdr_stream *xdr)
5006{
5007 return decode_op_hdr(xdr, OP_RENEW);
5008}
5009
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005010static int
5011decode_restorefh(struct xdr_stream *xdr)
5012{
5013 return decode_op_hdr(xdr, OP_RESTOREFH);
5014}
5015
J. Bruce Fields029d1052005-06-22 17:16:22 +00005016static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005017 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005018{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005019 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005020 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005021 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005022 struct kvec *iov = req->rq_rcv_buf.head;
5023 int status;
5024
Andy Adamsonbf118a32011-12-07 11:55:27 -05005025 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005026 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5027 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005028 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005029 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5030 goto out;
5031 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5032 goto out;
5033
5034 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5035 return -EIO;
5036 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005037 size_t hdrlen;
5038 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005039
Andy Adamsonbf118a32011-12-07 11:55:27 -05005040 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5041 * are stored with the acl data to handle the problem of
5042 * variable length bitmaps.*/
5043 xdr->p = bm_p;
5044 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5045 res->acl_data_offset <<= 2;
5046
J. Bruce Fields029d1052005-06-22 17:16:22 +00005047 /* We ignore &savep and don't do consistency checks on
5048 * the attr length. Let userspace figure it out.... */
5049 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005050 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005051 recvd = req->rq_rcv_buf.len - hdrlen;
5052 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005053 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5054 /* getxattr interface called with a NULL buf */
5055 res->acl_len = attrlen;
5056 goto out;
5057 }
5058 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005059 attrlen, recvd);
5060 return -EINVAL;
5061 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005062 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005063 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005064 } else
5065 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005066
5067out:
5068 return status;
5069}
5070
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071static int
5072decode_savefh(struct xdr_stream *xdr)
5073{
5074 return decode_op_hdr(xdr, OP_SAVEFH);
5075}
5076
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005077static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078{
Al Viro8687b632006-10-19 23:28:48 -07005079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 uint32_t bmlen;
5081 int status;
5082
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 status = decode_op_hdr(xdr, OP_SETATTR);
5084 if (status)
5085 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005086 p = xdr_inline_decode(xdr, 4);
5087 if (unlikely(!p))
5088 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005089 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005090 p = xdr_inline_decode(xdr, bmlen << 2);
5091 if (likely(p))
5092 return 0;
5093out_overflow:
5094 print_overflow_msg(__func__, xdr);
5095 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096}
5097
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005098static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099{
Al Viro8687b632006-10-19 23:28:48 -07005100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 uint32_t opnum;
5102 int32_t nfserr;
5103
Benny Halevyc0eae662009-08-14 17:20:14 +03005104 p = xdr_inline_decode(xdr, 8);
5105 if (unlikely(!p))
5106 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005107 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005109 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005110 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 return -EIO;
5112 }
Benny Halevycccddf42009-08-14 17:20:19 +03005113 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005115 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5116 if (unlikely(!p))
5117 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005118 p = xdr_decode_hyper(p, &res->clientid);
5119 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 } else if (nfserr == NFSERR_CLID_INUSE) {
5121 uint32_t len;
5122
5123 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005124 p = xdr_inline_decode(xdr, 4);
5125 if (unlikely(!p))
5126 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005127 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005128 p = xdr_inline_decode(xdr, len);
5129 if (unlikely(!p))
5130 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131
5132 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, 4);
5134 if (unlikely(!p))
5135 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005136 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005137 p = xdr_inline_decode(xdr, len);
5138 if (unlikely(!p))
5139 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 return -NFSERR_CLID_INUSE;
5141 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005142 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143
5144 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005145out_overflow:
5146 print_overflow_msg(__func__, xdr);
5147 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148}
5149
5150static int decode_setclientid_confirm(struct xdr_stream *xdr)
5151{
5152 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5153}
5154
5155static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5156{
Al Viro8687b632006-10-19 23:28:48 -07005157 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158 int status;
5159
5160 status = decode_op_hdr(xdr, OP_WRITE);
5161 if (status)
5162 return status;
5163
Benny Halevyc0eae662009-08-14 17:20:14 +03005164 p = xdr_inline_decode(xdr, 16);
5165 if (unlikely(!p))
5166 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005167 res->count = be32_to_cpup(p++);
5168 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005169 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005171out_overflow:
5172 print_overflow_msg(__func__, xdr);
5173 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174}
5175
5176static int decode_delegreturn(struct xdr_stream *xdr)
5177{
5178 return decode_op_hdr(xdr, OP_DELEGRETURN);
5179}
5180
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005181static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5182{
5183 __be32 *p;
5184
5185 p = xdr_inline_decode(xdr, 4);
5186 if (unlikely(!p))
5187 goto out_overflow;
5188 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5189 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5190 goto out_err;
5191
5192 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5193 if (unlikely(!p))
5194 goto out_overflow;
5195 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5196
5197 p = xdr_inline_decode(xdr, 8);
5198 if (unlikely(!p))
5199 goto out_overflow;
5200 flavor->gss.qop4 = be32_to_cpup(p++);
5201 flavor->gss.service = be32_to_cpup(p);
5202
5203 return 0;
5204
5205out_overflow:
5206 print_overflow_msg(__func__, xdr);
5207 return -EIO;
5208out_err:
5209 return -EINVAL;
5210}
5211
5212static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5213{
5214 struct nfs4_secinfo_flavor *sec_flavor;
5215 int status;
5216 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005217 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005218
5219 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005220 if (status)
5221 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005222 p = xdr_inline_decode(xdr, 4);
5223 if (unlikely(!p))
5224 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005225
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005226 res->flavors->num_flavors = 0;
5227 num_flavors = be32_to_cpup(p);
5228
5229 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005230 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005231 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005232 break;
5233
5234 p = xdr_inline_decode(xdr, 4);
5235 if (unlikely(!p))
5236 goto out_overflow;
5237 sec_flavor->flavor = be32_to_cpup(p);
5238
5239 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005240 status = decode_secinfo_gss(xdr, sec_flavor);
5241 if (status)
5242 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005243 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005244 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005245 }
5246
Bryan Schumaker613e9012011-04-27 15:28:44 -04005247out:
5248 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249out_overflow:
5250 print_overflow_msg(__func__, xdr);
5251 return -EIO;
5252}
5253
Benny Halevy99fe60d2009-04-01 09:22:29 -04005254#if defined(CONFIG_NFS_V4_1)
5255static int decode_exchange_id(struct xdr_stream *xdr,
5256 struct nfs41_exchange_id_res *res)
5257{
5258 __be32 *p;
5259 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005260 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005261 int status;
5262 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005263 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005264
5265 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5266 if (status)
5267 return status;
5268
Benny Halevyc0eae662009-08-14 17:20:14 +03005269 p = xdr_inline_decode(xdr, 8);
5270 if (unlikely(!p))
5271 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005272 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005273 p = xdr_inline_decode(xdr, 12);
5274 if (unlikely(!p))
5275 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005276 clp->cl_seqid = be32_to_cpup(p++);
5277 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005278
5279 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005280 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005281 if (dummy != SP4_NONE)
5282 return -EIO;
5283
5284 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005285 p = xdr_inline_decode(xdr, 8);
5286 if (unlikely(!p))
5287 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005288
5289 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005290 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5291 if (unlikely(status))
5292 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005293
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005294 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005295 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5296 if (unlikely(status))
5297 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005298
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005299 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5300 return -EIO;
5301
5302 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5303 res->server_scope->server_scope_sz = dummy;
5304
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005305 /* Implementation Id */
5306 p = xdr_inline_decode(xdr, 4);
5307 if (unlikely(!p))
5308 goto out_overflow;
5309 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005310
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005311 if (impl_id_count) {
5312 /* nii_domain */
5313 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5314 if (unlikely(status))
5315 return status;
5316 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5317 return -EIO;
5318 memcpy(res->impl_id->domain, dummy_str, dummy);
5319
5320 /* nii_name */
5321 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5322 if (unlikely(status))
5323 return status;
5324 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5325 return -EIO;
5326 memcpy(res->impl_id->name, dummy_str, dummy);
5327
5328 /* nii_date */
5329 p = xdr_inline_decode(xdr, 12);
5330 if (unlikely(!p))
5331 goto out_overflow;
5332 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5333 res->impl_id->date.nseconds = be32_to_cpup(p);
5334
5335 /* if there's more than one entry, ignore the rest */
5336 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005337 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005338out_overflow:
5339 print_overflow_msg(__func__, xdr);
5340 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005341}
Andy Adamsonfc931582009-04-01 09:22:31 -04005342
5343static int decode_chan_attrs(struct xdr_stream *xdr,
5344 struct nfs4_channel_attrs *attrs)
5345{
5346 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005347 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005348
Benny Halevyc0eae662009-08-14 17:20:14 +03005349 p = xdr_inline_decode(xdr, 28);
5350 if (unlikely(!p))
5351 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005352 val = be32_to_cpup(p++); /* headerpadsz */
5353 if (val)
5354 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005355 attrs->max_rqst_sz = be32_to_cpup(p++);
5356 attrs->max_resp_sz = be32_to_cpup(p++);
5357 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5358 attrs->max_ops = be32_to_cpup(p++);
5359 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005360 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005361 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005362 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5363 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005364 return -EINVAL;
5365 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005366 if (nr_attrs == 1) {
5367 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5368 if (unlikely(!p))
5369 goto out_overflow;
5370 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005371 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005372out_overflow:
5373 print_overflow_msg(__func__, xdr);
5374 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005375}
5376
Benny Halevye78291e2009-08-14 17:20:00 +03005377static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5378{
5379 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005380}
5381
5382static int decode_create_session(struct xdr_stream *xdr,
5383 struct nfs41_create_session_res *res)
5384{
5385 __be32 *p;
5386 int status;
5387 struct nfs_client *clp = res->client;
5388 struct nfs4_session *session = clp->cl_session;
5389
5390 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005391 if (!status)
5392 status = decode_sessionid(xdr, &session->sess_id);
5393 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005394 return status;
5395
Andy Adamsonfc931582009-04-01 09:22:31 -04005396 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005397 p = xdr_inline_decode(xdr, 8);
5398 if (unlikely(!p))
5399 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005400 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005401 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005402
5403 /* Channel attributes */
5404 status = decode_chan_attrs(xdr, &session->fc_attrs);
5405 if (!status)
5406 status = decode_chan_attrs(xdr, &session->bc_attrs);
5407 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005408out_overflow:
5409 print_overflow_msg(__func__, xdr);
5410 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005411}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005412
5413static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5414{
5415 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5416}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005417
5418static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5419{
5420 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5421}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005422#endif /* CONFIG_NFS_V4_1 */
5423
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005424static int decode_sequence(struct xdr_stream *xdr,
5425 struct nfs4_sequence_res *res,
5426 struct rpc_rqst *rqstp)
5427{
5428#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005429 struct nfs4_sessionid id;
5430 u32 dummy;
5431 int status;
5432 __be32 *p;
5433
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005434 if (!res->sr_session)
5435 return 0;
5436
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005437 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005438 if (!status)
5439 status = decode_sessionid(xdr, &id);
5440 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005441 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005442
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005443 /*
5444 * If the server returns different values for sessionID, slotID or
5445 * sequence number, the server is looney tunes.
5446 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005447 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005448
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005449 if (memcmp(id.data, res->sr_session->sess_id.data,
5450 NFS4_MAX_SESSIONID_LEN)) {
5451 dprintk("%s Invalid session id\n", __func__);
5452 goto out_err;
5453 }
Benny Halevye78291e2009-08-14 17:20:00 +03005454
Benny Halevyc0eae662009-08-14 17:20:14 +03005455 p = xdr_inline_decode(xdr, 20);
5456 if (unlikely(!p))
5457 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005458
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005459 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005460 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005461 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005462 dprintk("%s Invalid sequence number\n", __func__);
5463 goto out_err;
5464 }
5465 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005466 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005467 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005468 dprintk("%s Invalid slot id\n", __func__);
5469 goto out_err;
5470 }
5471 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005472 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005473 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005474 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005475 /* result flags */
5476 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005477 status = 0;
5478out_err:
5479 res->sr_status = status;
5480 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005481out_overflow:
5482 print_overflow_msg(__func__, xdr);
5483 status = -EIO;
5484 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005485#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005486 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005487#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005488}
5489
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005490#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005491/*
5492 * TODO: Need to handle case when EOF != true;
5493 */
5494static int decode_getdevicelist(struct xdr_stream *xdr,
5495 struct pnfs_devicelist *res)
5496{
5497 __be32 *p;
5498 int status, i;
5499 struct nfs_writeverf verftemp;
5500
5501 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5502 if (status)
5503 return status;
5504
5505 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5506 if (unlikely(!p))
5507 goto out_overflow;
5508
5509 /* TODO: Skip cookie for now */
5510 p += 2;
5511
5512 /* Read verifier */
5513 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5514
5515 res->num_devs = be32_to_cpup(p);
5516
5517 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5518
5519 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005520 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005521 __func__, res->num_devs);
5522 return -EIO;
5523 }
5524
5525 p = xdr_inline_decode(xdr,
5526 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5527 if (unlikely(!p))
5528 goto out_overflow;
5529 for (i = 0; i < res->num_devs; i++)
5530 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5531 NFS4_DEVICEID4_SIZE);
5532 res->eof = be32_to_cpup(p);
5533 return 0;
5534out_overflow:
5535 print_overflow_msg(__func__, xdr);
5536 return -EIO;
5537}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005538
5539static int decode_getdeviceinfo(struct xdr_stream *xdr,
5540 struct pnfs_device *pdev)
5541{
5542 __be32 *p;
5543 uint32_t len, type;
5544 int status;
5545
5546 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5547 if (status) {
5548 if (status == -ETOOSMALL) {
5549 p = xdr_inline_decode(xdr, 4);
5550 if (unlikely(!p))
5551 goto out_overflow;
5552 pdev->mincount = be32_to_cpup(p);
5553 dprintk("%s: Min count too small. mincnt = %u\n",
5554 __func__, pdev->mincount);
5555 }
5556 return status;
5557 }
5558
5559 p = xdr_inline_decode(xdr, 8);
5560 if (unlikely(!p))
5561 goto out_overflow;
5562 type = be32_to_cpup(p++);
5563 if (type != pdev->layout_type) {
5564 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5565 __func__, pdev->layout_type, type);
5566 return -EINVAL;
5567 }
5568 /*
5569 * Get the length of the opaque device_addr4. xdr_read_pages places
5570 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5571 * and places the remaining xdr data in xdr_buf->tail
5572 */
5573 pdev->mincount = be32_to_cpup(p);
5574 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5575
5576 /* Parse notification bitmap, verifying that it is zero. */
5577 p = xdr_inline_decode(xdr, 4);
5578 if (unlikely(!p))
5579 goto out_overflow;
5580 len = be32_to_cpup(p);
5581 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005582 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005583
5584 p = xdr_inline_decode(xdr, 4 * len);
5585 if (unlikely(!p))
5586 goto out_overflow;
5587 for (i = 0; i < len; i++, p++) {
5588 if (be32_to_cpup(p)) {
5589 dprintk("%s: notifications not supported\n",
5590 __func__);
5591 return -EIO;
5592 }
5593 }
5594 }
5595 return 0;
5596out_overflow:
5597 print_overflow_msg(__func__, xdr);
5598 return -EIO;
5599}
5600
5601static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5602 struct nfs4_layoutget_res *res)
5603{
5604 __be32 *p;
5605 int status;
5606 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005607 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5608 struct kvec *iov = rcvbuf->head;
5609 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005610
5611 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5612 if (status)
5613 return status;
5614 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5615 if (unlikely(!p))
5616 goto out_overflow;
5617 res->return_on_close = be32_to_cpup(p++);
5618 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5619 layout_count = be32_to_cpup(p);
5620 if (!layout_count) {
5621 dprintk("%s: server responded with empty layout array\n",
5622 __func__);
5623 return -EINVAL;
5624 }
5625
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005626 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005627 if (unlikely(!p))
5628 goto out_overflow;
5629 p = xdr_decode_hyper(p, &res->range.offset);
5630 p = xdr_decode_hyper(p, &res->range.length);
5631 res->range.iomode = be32_to_cpup(p++);
5632 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005633 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005634
5635 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5636 __func__,
5637 (unsigned long)res->range.offset,
5638 (unsigned long)res->range.length,
5639 res->range.iomode,
5640 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005641 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005642
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005643 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5644 recvd = req->rq_rcv_buf.len - hdrlen;
5645 if (res->layoutp->len > recvd) {
5646 dprintk("NFS: server cheating in layoutget reply: "
5647 "layout len %u > recvd %u\n",
5648 res->layoutp->len, recvd);
5649 return -EINVAL;
5650 }
5651
5652 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005653
5654 if (layout_count > 1) {
5655 /* We only handle a length one array at the moment. Any
5656 * further entries are just ignored. Note that this means
5657 * the client may see a response that is less than the
5658 * minimum it requested.
5659 */
5660 dprintk("%s: server responded with %d layouts, dropping tail\n",
5661 __func__, layout_count);
5662 }
5663
5664 return 0;
5665out_overflow:
5666 print_overflow_msg(__func__, xdr);
5667 return -EIO;
5668}
Andy Adamson863a3c62011-03-23 13:27:54 +00005669
Benny Halevycbe82602011-05-22 19:52:37 +03005670static int decode_layoutreturn(struct xdr_stream *xdr,
5671 struct nfs4_layoutreturn_res *res)
5672{
5673 __be32 *p;
5674 int status;
5675
5676 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5677 if (status)
5678 return status;
5679 p = xdr_inline_decode(xdr, 4);
5680 if (unlikely(!p))
5681 goto out_overflow;
5682 res->lrs_present = be32_to_cpup(p);
5683 if (res->lrs_present)
5684 status = decode_stateid(xdr, &res->stateid);
5685 return status;
5686out_overflow:
5687 print_overflow_msg(__func__, xdr);
5688 return -EIO;
5689}
5690
Andy Adamson863a3c62011-03-23 13:27:54 +00005691static int decode_layoutcommit(struct xdr_stream *xdr,
5692 struct rpc_rqst *req,
5693 struct nfs4_layoutcommit_res *res)
5694{
5695 __be32 *p;
5696 __u32 sizechanged;
5697 int status;
5698
5699 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005700 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005701 if (status)
5702 return status;
5703
5704 p = xdr_inline_decode(xdr, 4);
5705 if (unlikely(!p))
5706 goto out_overflow;
5707 sizechanged = be32_to_cpup(p);
5708
5709 if (sizechanged) {
5710 /* throw away new size */
5711 p = xdr_inline_decode(xdr, 8);
5712 if (unlikely(!p))
5713 goto out_overflow;
5714 }
5715 return 0;
5716out_overflow:
5717 print_overflow_msg(__func__, xdr);
5718 return -EIO;
5719}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005720
5721static int decode_test_stateid(struct xdr_stream *xdr,
5722 struct nfs41_test_stateid_res *res)
5723{
5724 __be32 *p;
5725 int status;
5726 int num_res;
5727
5728 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5729 if (status)
5730 return status;
5731
5732 p = xdr_inline_decode(xdr, 4);
5733 if (unlikely(!p))
5734 goto out_overflow;
5735 num_res = be32_to_cpup(p++);
5736 if (num_res != 1)
5737 goto out;
5738
5739 p = xdr_inline_decode(xdr, 4);
5740 if (unlikely(!p))
5741 goto out_overflow;
5742 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005743
5744 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005745out_overflow:
5746 print_overflow_msg(__func__, xdr);
5747out:
5748 return -EIO;
5749}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005750
5751static int decode_free_stateid(struct xdr_stream *xdr,
5752 struct nfs41_free_stateid_res *res)
5753{
5754 __be32 *p;
5755 int status;
5756
5757 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5758 if (status)
5759 return status;
5760
5761 p = xdr_inline_decode(xdr, 4);
5762 if (unlikely(!p))
5763 goto out_overflow;
5764 res->status = be32_to_cpup(p++);
5765 return res->status;
5766out_overflow:
5767 print_overflow_msg(__func__, xdr);
5768 return -EIO;
5769}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005770#endif /* CONFIG_NFS_V4_1 */
5771
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772/*
Benny Halevy49c25592008-12-23 16:06:16 -05005773 * END OF "GENERIC" DECODE ROUTINES.
5774 */
5775
5776/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777 * Decode OPEN_DOWNGRADE response
5778 */
Chuck Leverbf269552010-12-14 14:59:29 +00005779static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5780 struct xdr_stream *xdr,
5781 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782{
Andy Adamson05d564f2008-12-23 16:06:15 -05005783 struct compound_hdr hdr;
5784 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005785
Chuck Leverbf269552010-12-14 14:59:29 +00005786 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005787 if (status)
5788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005789 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005790 if (status)
5791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005792 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005793 if (status)
5794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005796 if (status != 0)
5797 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005798 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005800 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801}
5802
5803/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804 * Decode ACCESS response
5805 */
Chuck Leverbf269552010-12-14 14:59:29 +00005806static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5807 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 struct compound_hdr hdr;
5810 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005811
Chuck Leverbf269552010-12-14 14:59:29 +00005812 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005813 if (status)
5814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005815 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005816 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005819 if (status != 0)
5820 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005821 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005822 if (status != 0)
5823 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005824 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825out:
5826 return status;
5827}
5828
5829/*
5830 * Decode LOOKUP response
5831 */
Chuck Leverbf269552010-12-14 14:59:29 +00005832static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5833 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 struct compound_hdr hdr;
5836 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005837
Chuck Leverbf269552010-12-14 14:59:29 +00005838 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005839 if (status)
5840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005841 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005842 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005844 status = decode_putfh(xdr);
5845 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_lookup(xdr);
5848 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_getfh(xdr, res->fh);
5851 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005853 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854out:
5855 return status;
5856}
5857
5858/*
5859 * Decode LOOKUP_ROOT response
5860 */
Chuck Leverbf269552010-12-14 14:59:29 +00005861static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5862 struct xdr_stream *xdr,
5863 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 struct compound_hdr hdr;
5866 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005867
Chuck Leverbf269552010-12-14 14:59:29 +00005868 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005869 if (status)
5870 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005871 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005872 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005874 status = decode_putrootfh(xdr);
5875 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005877 status = decode_getfh(xdr, res->fh);
5878 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005879 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880out:
5881 return status;
5882}
5883
5884/*
5885 * Decode REMOVE response
5886 */
Chuck Leverbf269552010-12-14 14:59:29 +00005887static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5888 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 struct compound_hdr hdr;
5891 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005892
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005894 if (status)
5895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005897 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_putfh(xdr);
5900 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005902 status = decode_remove(xdr, &res->cinfo);
5903 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005904 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005905 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906out:
5907 return status;
5908}
5909
5910/*
5911 * Decode RENAME response
5912 */
Chuck Leverbf269552010-12-14 14:59:29 +00005913static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5914 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916 struct compound_hdr hdr;
5917 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005918
Chuck Leverbf269552010-12-14 14:59:29 +00005919 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005920 if (status)
5921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005923 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_putfh(xdr);
5926 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_savefh(xdr);
5929 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005931 status = decode_putfh(xdr);
5932 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005934 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5935 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005936 goto out;
5937 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005938 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005939 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005940 status = decode_restorefh(xdr);
5941 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005942 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005943 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005944out:
5945 return status;
5946}
5947
5948/*
5949 * Decode LINK response
5950 */
Chuck Leverbf269552010-12-14 14:59:29 +00005951static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5952 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 struct compound_hdr hdr;
5955 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005956
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005958 if (status)
5959 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005961 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_putfh(xdr);
5964 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_savefh(xdr);
5967 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_putfh(xdr);
5970 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_link(xdr, &res->cinfo);
5973 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005974 goto out;
5975 /*
5976 * Note order: OP_LINK leaves the directory as the current
5977 * filehandle.
5978 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005979 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005981 status = decode_restorefh(xdr);
5982 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005983 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005984 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985out:
5986 return status;
5987}
5988
5989/*
5990 * Decode CREATE response
5991 */
Chuck Leverbf269552010-12-14 14:59:29 +00005992static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5993 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995 struct compound_hdr hdr;
5996 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005997
Chuck Leverbf269552010-12-14 14:59:29 +00005998 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005999 if (status)
6000 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006002 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_putfh(xdr);
6005 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_savefh(xdr);
6008 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006009 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_create(xdr, &res->dir_cinfo);
6011 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_getfh(xdr, res->fh);
6014 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006016 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_restorefh(xdr);
6019 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006020 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006021 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022out:
6023 return status;
6024}
6025
6026/*
6027 * Decode SYMLINK response
6028 */
Chuck Leverbf269552010-12-14 14:59:29 +00006029static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6030 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031{
Chuck Leverbf269552010-12-14 14:59:29 +00006032 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033}
6034
6035/*
6036 * Decode GETATTR response
6037 */
Chuck Leverbf269552010-12-14 14:59:29 +00006038static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6039 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 struct compound_hdr hdr;
6042 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006043
Chuck Leverbf269552010-12-14 14:59:29 +00006044 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045 if (status)
6046 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006048 if (status)
6049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 if (status)
6052 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006053 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054out:
6055 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056}
6057
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006058/*
6059 * Encode an SETACL request
6060 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006061static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6062 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006063{
Andy Adamson05d564f2008-12-23 16:06:15 -05006064 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006065 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006066 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006067
Chuck Lever9f06c712010-12-14 14:59:18 +00006068 encode_compound_hdr(xdr, req, &hdr);
6069 encode_sequence(xdr, &args->seq_args, &hdr);
6070 encode_putfh(xdr, args->fh, &hdr);
6071 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006072 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006073}
Andy Adamson05d564f2008-12-23 16:06:15 -05006074
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006075/*
6076 * Decode SETACL response
6077 */
6078static int
Chuck Leverbf269552010-12-14 14:59:29 +00006079nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006080 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006081{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006082 struct compound_hdr hdr;
6083 int status;
6084
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006086 if (status)
6087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006089 if (status)
6090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006092 if (status)
6093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006095out:
6096 return status;
6097}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098
6099/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006100 * Decode GETACL response
6101 */
6102static int
Chuck Leverbf269552010-12-14 14:59:29 +00006103nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006104 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006105{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006106 struct compound_hdr hdr;
6107 int status;
6108
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006110 if (status)
6111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006113 if (status)
6114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006116 if (status)
6117 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006118 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006119
6120out:
6121 return status;
6122}
6123
6124/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 * Decode CLOSE response
6126 */
Chuck Leverbf269552010-12-14 14:59:29 +00006127static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6128 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129{
Andy Adamson05d564f2008-12-23 16:06:15 -05006130 struct compound_hdr hdr;
6131 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006140 if (status)
6141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006143 if (status != 0)
6144 goto out;
6145 /*
6146 * Note: Server may do delete on close for this file
6147 * in which case the getattr call will fail with
6148 * an ESTALE error. Shouldn't be a problem,
6149 * though, since fattr->valid will remain unset.
6150 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006151 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006153 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154}
6155
6156/*
6157 * Decode OPEN response
6158 */
Chuck Leverbf269552010-12-14 14:59:29 +00006159static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6160 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161{
Andy Adamson05d564f2008-12-23 16:06:15 -05006162 struct compound_hdr hdr;
6163 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006166 if (status)
6167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006169 if (status)
6170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006172 if (status)
6173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006175 if (status)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006178 if (status)
6179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006182 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006183 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006184 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006185 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006186 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006188 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189}
6190
6191/*
6192 * Decode OPEN_CONFIRM response
6193 */
Chuck Leverbf269552010-12-14 14:59:29 +00006194static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6195 struct xdr_stream *xdr,
6196 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197{
Andy Adamson05d564f2008-12-23 16:06:15 -05006198 struct compound_hdr hdr;
6199 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006205 if (status)
6206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006209 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210}
6211
6212/*
6213 * Decode OPEN response
6214 */
Chuck Leverbf269552010-12-14 14:59:29 +00006215static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6216 struct xdr_stream *xdr,
6217 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218{
Andy Adamson05d564f2008-12-23 16:06:15 -05006219 struct compound_hdr hdr;
6220 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006223 if (status)
6224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006226 if (status)
6227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006229 if (status)
6230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006232 if (status)
6233 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006234 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006236 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237}
6238
6239/*
6240 * Decode SETATTR response
6241 */
Chuck Leverbf269552010-12-14 14:59:29 +00006242static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6243 struct xdr_stream *xdr,
6244 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245{
Andy Adamson05d564f2008-12-23 16:06:15 -05006246 struct compound_hdr hdr;
6247 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006250 if (status)
6251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006253 if (status)
6254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006259 if (status)
6260 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006261 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006263 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264}
6265
6266/*
6267 * Decode LOCK response
6268 */
Chuck Leverbf269552010-12-14 14:59:29 +00006269static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6270 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 struct compound_hdr hdr;
6273 int status;
6274
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 if (status)
6277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 if (status)
6283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285out:
6286 return status;
6287}
6288
6289/*
6290 * Decode LOCKT response
6291 */
Chuck Leverbf269552010-12-14 14:59:29 +00006292static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6293 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 struct compound_hdr hdr;
6296 int status;
6297
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 if (status)
6300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006302 if (status)
6303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308out:
6309 return status;
6310}
6311
6312/*
6313 * Decode LOCKU response
6314 */
Chuck Leverbf269552010-12-14 14:59:29 +00006315static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6316 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318 struct compound_hdr hdr;
6319 int status;
6320
Chuck Leverbf269552010-12-14 14:59:29 +00006321 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 if (status)
6323 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006325 if (status)
6326 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 if (status)
6329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331out:
6332 return status;
6333}
6334
Chuck Leverbf269552010-12-14 14:59:29 +00006335static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6336 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006337{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006338 struct compound_hdr hdr;
6339 int status;
6340
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006342 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006344 return status;
6345}
6346
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347/*
6348 * Decode READLINK response
6349 */
Chuck Leverbf269552010-12-14 14:59:29 +00006350static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6351 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006352 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354 struct compound_hdr hdr;
6355 int status;
6356
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 if (status)
6359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006361 if (status)
6362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 if (status)
6365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367out:
6368 return status;
6369}
6370
6371/*
6372 * Decode READDIR response
6373 */
Chuck Leverbf269552010-12-14 14:59:29 +00006374static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6375 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 struct compound_hdr hdr;
6378 int status;
6379
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 if (status)
6382 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006384 if (status)
6385 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387 if (status)
6388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390out:
6391 return status;
6392}
6393
6394/*
6395 * Decode Read response
6396 */
Chuck Leverbf269552010-12-14 14:59:29 +00006397static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6398 struct nfs_readres *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)
6405 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006407 if (status)
6408 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 if (status)
6411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413 if (!status)
6414 status = res->count;
6415out:
6416 return status;
6417}
6418
6419/*
6420 * Decode WRITE response
6421 */
Chuck Leverbf269552010-12-14 14:59:29 +00006422static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6423 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 struct compound_hdr hdr;
6426 int status;
6427
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 if (status)
6430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006432 if (status)
6433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 if (status)
6436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006438 if (status)
6439 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006440 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006441 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (!status)
6443 status = res->count;
6444out:
6445 return status;
6446}
6447
6448/*
6449 * Decode COMMIT response
6450 */
Chuck Leverbf269552010-12-14 14:59:29 +00006451static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6452 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 struct compound_hdr hdr;
6455 int status;
6456
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 if (status)
6459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006461 if (status)
6462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006467 if (status)
6468 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006469 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006470 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471out:
6472 return status;
6473}
6474
6475/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006476 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 */
Chuck Leverbf269552010-12-14 14:59:29 +00006478static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006479 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481 struct compound_hdr hdr;
6482 int status;
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006487 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 return status;
6492}
6493
6494/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006495 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496 */
Chuck Leverbf269552010-12-14 14:59:29 +00006497static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006498 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006499{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500 struct compound_hdr hdr;
6501 int status;
6502
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006506 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 return status;
6511}
6512
6513/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006514 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 */
Chuck Leverbf269552010-12-14 14:59:29 +00006516static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006517 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 struct compound_hdr hdr;
6520 int status;
6521
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006525 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 return status;
6530}
6531
6532/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006533 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 */
Chuck Leverbf269552010-12-14 14:59:29 +00006535static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6536 struct xdr_stream *xdr,
6537 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 struct compound_hdr hdr;
6540 int status;
6541
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006543 if (status)
6544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006546 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_putfh(xdr);
6549 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552out:
6553 return status;
6554}
6555
6556/*
6557 * Decode RENEW response
6558 */
Chuck Leverbf269552010-12-14 14:59:29 +00006559static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6560 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 struct compound_hdr hdr;
6563 int status;
6564
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 return status;
6569}
6570
6571/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006572 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 */
Chuck Leverbf269552010-12-14 14:59:29 +00006574static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6575 struct xdr_stream *xdr,
6576 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 struct compound_hdr hdr;
6579 int status;
6580
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 return status;
6585}
6586
6587/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006588 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 */
Chuck Leverbf269552010-12-14 14:59:29 +00006590static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6591 struct xdr_stream *xdr,
6592 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 struct compound_hdr hdr;
6595 int status;
6596
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 return status;
6605}
6606
6607/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006608 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 */
Chuck Leverbf269552010-12-14 14:59:29 +00006610static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6611 struct xdr_stream *xdr,
6612 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614 struct compound_hdr hdr;
6615 int status;
6616
Chuck Leverbf269552010-12-14 14:59:29 +00006617 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006618 if (status)
6619 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006621 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006624 if (status != 0)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006627 if (status != 0)
6628 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006629 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006630out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 return status;
6632}
6633
Trond Myklebust683b57b2006-06-09 09:34:22 -04006634/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006635 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006636 */
Chuck Leverbf269552010-12-14 14:59:29 +00006637static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6638 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006639 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006640{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006641 struct compound_hdr hdr;
6642 int status;
6643
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006645 if (status)
6646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006648 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_putfh(xdr);
6651 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_lookup(xdr);
6654 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006657 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6658 NULL, res->fs_locations,
6659 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006660out:
6661 return status;
6662}
6663
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006664/*
6665 * Decode SECINFO response
6666 */
6667static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6668 struct xdr_stream *xdr,
6669 struct nfs4_secinfo_res *res)
6670{
6671 struct compound_hdr hdr;
6672 int status;
6673
6674 status = decode_compound_hdr(xdr, &hdr);
6675 if (status)
6676 goto out;
6677 status = decode_sequence(xdr, &res->seq_res, rqstp);
6678 if (status)
6679 goto out;
6680 status = decode_putfh(xdr);
6681 if (status)
6682 goto out;
6683 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006684out:
6685 return status;
6686}
6687
Benny Halevy99fe60d2009-04-01 09:22:29 -04006688#if defined(CONFIG_NFS_V4_1)
6689/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006690 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006691 */
Chuck Leverbf269552010-12-14 14:59:29 +00006692static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6693 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006694 void *res)
6695{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006696 struct compound_hdr hdr;
6697 int status;
6698
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006700 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006702 return status;
6703}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006704
6705/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006706 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006707 */
Chuck Leverbf269552010-12-14 14:59:29 +00006708static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6709 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006710 struct nfs41_create_session_res *res)
6711{
Andy Adamsonfc931582009-04-01 09:22:31 -04006712 struct compound_hdr hdr;
6713 int status;
6714
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006716 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006718 return status;
6719}
6720
6721/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006722 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006723 */
Chuck Leverbf269552010-12-14 14:59:29 +00006724static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6725 struct xdr_stream *xdr,
6726 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006727{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006728 struct compound_hdr hdr;
6729 int status;
6730
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006732 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006733 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006734 return status;
6735}
6736
6737/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006738 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006739 */
Chuck Leverbf269552010-12-14 14:59:29 +00006740static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6741 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006742 struct nfs4_sequence_res *res)
6743{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006744 struct compound_hdr hdr;
6745 int status;
6746
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006748 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006749 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006750 return status;
6751}
6752
6753/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006754 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006755 */
Chuck Leverbf269552010-12-14 14:59:29 +00006756static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6757 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006758 struct nfs4_get_lease_time_res *res)
6759{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006760 struct compound_hdr hdr;
6761 int status;
6762
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006764 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006765 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006766 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006767 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006768 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006769 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006770 return status;
6771}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006772
6773/*
6774 * Decode RECLAIM_COMPLETE response
6775 */
Chuck Leverbf269552010-12-14 14:59:29 +00006776static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6777 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006778 struct nfs41_reclaim_complete_res *res)
6779{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006780 struct compound_hdr hdr;
6781 int status;
6782
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006784 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006786 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006788 return status;
6789}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006790
6791/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006792 * Decode GETDEVICELIST response
6793 */
6794static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6795 struct xdr_stream *xdr,
6796 struct nfs4_getdevicelist_res *res)
6797{
6798 struct compound_hdr hdr;
6799 int status;
6800
6801 dprintk("encoding getdevicelist!\n");
6802
6803 status = decode_compound_hdr(xdr, &hdr);
6804 if (status != 0)
6805 goto out;
6806 status = decode_sequence(xdr, &res->seq_res, rqstp);
6807 if (status != 0)
6808 goto out;
6809 status = decode_putfh(xdr);
6810 if (status != 0)
6811 goto out;
6812 status = decode_getdevicelist(xdr, res->devlist);
6813out:
6814 return status;
6815}
6816
6817/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006818 * Decode GETDEVINFO response
6819 */
Chuck Leverbf269552010-12-14 14:59:29 +00006820static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6821 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006822 struct nfs4_getdeviceinfo_res *res)
6823{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006824 struct compound_hdr hdr;
6825 int status;
6826
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006828 if (status != 0)
6829 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006830 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006831 if (status != 0)
6832 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006834out:
6835 return status;
6836}
6837
6838/*
6839 * Decode LAYOUTGET response
6840 */
Chuck Leverbf269552010-12-14 14:59:29 +00006841static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6842 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006843 struct nfs4_layoutget_res *res)
6844{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006845 struct compound_hdr hdr;
6846 int status;
6847
Chuck Leverbf269552010-12-14 14:59:29 +00006848 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006849 if (status)
6850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006851 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006852 if (status)
6853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006855 if (status)
6856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006858out:
6859 return status;
6860}
Andy Adamson863a3c62011-03-23 13:27:54 +00006861
6862/*
Benny Halevycbe82602011-05-22 19:52:37 +03006863 * Decode LAYOUTRETURN response
6864 */
6865static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6866 struct xdr_stream *xdr,
6867 struct nfs4_layoutreturn_res *res)
6868{
6869 struct compound_hdr hdr;
6870 int status;
6871
6872 status = decode_compound_hdr(xdr, &hdr);
6873 if (status)
6874 goto out;
6875 status = decode_sequence(xdr, &res->seq_res, rqstp);
6876 if (status)
6877 goto out;
6878 status = decode_putfh(xdr);
6879 if (status)
6880 goto out;
6881 status = decode_layoutreturn(xdr, res);
6882out:
6883 return status;
6884}
6885
6886/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006887 * Decode LAYOUTCOMMIT response
6888 */
6889static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6890 struct xdr_stream *xdr,
6891 struct nfs4_layoutcommit_res *res)
6892{
6893 struct compound_hdr hdr;
6894 int status;
6895
6896 status = decode_compound_hdr(xdr, &hdr);
6897 if (status)
6898 goto out;
6899 status = decode_sequence(xdr, &res->seq_res, rqstp);
6900 if (status)
6901 goto out;
6902 status = decode_putfh(xdr);
6903 if (status)
6904 goto out;
6905 status = decode_layoutcommit(xdr, rqstp, res);
6906 if (status)
6907 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006908 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006909out:
6910 return status;
6911}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006912
6913/*
6914 * Decode SECINFO_NO_NAME response
6915 */
6916static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6917 struct xdr_stream *xdr,
6918 struct nfs4_secinfo_res *res)
6919{
6920 struct compound_hdr hdr;
6921 int status;
6922
6923 status = decode_compound_hdr(xdr, &hdr);
6924 if (status)
6925 goto out;
6926 status = decode_sequence(xdr, &res->seq_res, rqstp);
6927 if (status)
6928 goto out;
6929 status = decode_putrootfh(xdr);
6930 if (status)
6931 goto out;
6932 status = decode_secinfo(xdr, res);
6933out:
6934 return status;
6935}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006936
6937/*
6938 * Decode TEST_STATEID response
6939 */
6940static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6941 struct xdr_stream *xdr,
6942 struct nfs41_test_stateid_res *res)
6943{
6944 struct compound_hdr hdr;
6945 int status;
6946
6947 status = decode_compound_hdr(xdr, &hdr);
6948 if (status)
6949 goto out;
6950 status = decode_sequence(xdr, &res->seq_res, rqstp);
6951 if (status)
6952 goto out;
6953 status = decode_test_stateid(xdr, res);
6954out:
6955 return status;
6956}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006957
6958/*
6959 * Decode FREE_STATEID response
6960 */
6961static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6962 struct xdr_stream *xdr,
6963 struct nfs41_free_stateid_res *res)
6964{
6965 struct compound_hdr hdr;
6966 int status;
6967
6968 status = decode_compound_hdr(xdr, &hdr);
6969 if (status)
6970 goto out;
6971 status = decode_sequence(xdr, &res->seq_res, rqstp);
6972 if (status)
6973 goto out;
6974 status = decode_free_stateid(xdr, res);
6975out:
6976 return status;
6977}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006978#endif /* CONFIG_NFS_V4_1 */
6979
Chuck Lever573c4e12010-12-14 14:58:11 +00006980/**
6981 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6982 * the local page cache.
6983 * @xdr: XDR stream where entry resides
6984 * @entry: buffer to fill in with entry data
6985 * @plus: boolean indicating whether this should be a readdirplus entry
6986 *
6987 * Returns zero if successful, otherwise a negative errno value is
6988 * returned.
6989 *
6990 * This function is not invoked during READDIR reply decoding, but
6991 * rather whenever an application invokes the getdents(2) system call
6992 * on a directory already in our cache.
6993 */
6994int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6995 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006996{
Fred Isamandae100c2011-07-30 20:52:37 -04006997 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006998 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006999 __be32 *p = xdr_inline_decode(xdr, 4);
7000 if (unlikely(!p))
7001 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007002 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007003 p = xdr_inline_decode(xdr, 4);
7004 if (unlikely(!p))
7005 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007006 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007007 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007009 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010 }
7011
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007012 p = xdr_inline_decode(xdr, 12);
7013 if (unlikely(!p))
7014 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007015 entry->prev_cookie = entry->cookie;
7016 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007017 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007018
Trond Myklebust9af8c222010-10-24 11:52:55 -04007019 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007020 if (unlikely(!p))
7021 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023
7024 /*
7025 * In case the server doesn't return an inode number,
7026 * we fake one here. (We don't use inode number 0,
7027 * since glibc seems to choke on it...)
7028 */
7029 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007030 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031
Trond Myklebust9af8c222010-10-24 11:52:55 -04007032 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007033 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007034
7035 if (decode_attr_length(xdr, &len, &p) < 0)
7036 goto out_overflow;
7037
Chuck Lever573c4e12010-12-14 14:58:11 +00007038 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007039 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007040 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007041 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7042 entry->ino = entry->fattr->mounted_on_fileid;
7043 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007044 entry->ino = entry->fattr->fileid;
7045
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007046 entry->d_type = DT_UNKNOWN;
7047 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7048 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7049
Chuck Lever573c4e12010-12-14 14:58:11 +00007050 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007051
7052out_overflow:
7053 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007054 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007055}
7056
7057/*
7058 * We need to translate between nfs status return values and
7059 * the local errno values which may not be the same.
7060 */
7061static struct {
7062 int stat;
7063 int errno;
7064} nfs_errtbl[] = {
7065 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007066 { NFS4ERR_PERM, -EPERM },
7067 { NFS4ERR_NOENT, -ENOENT },
7068 { NFS4ERR_IO, -errno_NFSERR_IO},
7069 { NFS4ERR_NXIO, -ENXIO },
7070 { NFS4ERR_ACCESS, -EACCES },
7071 { NFS4ERR_EXIST, -EEXIST },
7072 { NFS4ERR_XDEV, -EXDEV },
7073 { NFS4ERR_NOTDIR, -ENOTDIR },
7074 { NFS4ERR_ISDIR, -EISDIR },
7075 { NFS4ERR_INVAL, -EINVAL },
7076 { NFS4ERR_FBIG, -EFBIG },
7077 { NFS4ERR_NOSPC, -ENOSPC },
7078 { NFS4ERR_ROFS, -EROFS },
7079 { NFS4ERR_MLINK, -EMLINK },
7080 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7081 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7082 { NFS4ERR_DQUOT, -EDQUOT },
7083 { NFS4ERR_STALE, -ESTALE },
7084 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007085 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7086 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7087 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007088 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007089 { NFS4ERR_BADTYPE, -EBADTYPE },
7090 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007091 { NFS4ERR_SYMLINK, -ELOOP },
7092 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7093 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007094 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095};
7096
7097/*
7098 * Convert an NFS error code to a local one.
7099 * This one is used jointly by NFSv2 and NFSv3.
7100 */
7101static int
David Howells0a8ea432006-08-22 20:06:08 -04007102nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007103{
7104 int i;
7105 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7106 if (nfs_errtbl[i].stat == stat)
7107 return nfs_errtbl[i].errno;
7108 }
7109 if (stat <= 10000 || stat > 10100) {
7110 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007111 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007112 }
7113 /* If we cannot translate the error, the recovery routines should
7114 * handle it.
7115 * Note: remaining NFSv4 error codes have values > 10000, so should
7116 * not conflict with native Linux error codes.
7117 */
Benny Halevy856dff32008-03-31 17:39:06 +03007118 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007119}
7120
Linus Torvalds1da177e2005-04-16 15:20:36 -07007121#define PROC(proc, argtype, restype) \
7122[NFSPROC4_CLNT_##proc] = { \
7123 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007124 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007125 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007126 .p_arglen = NFS4_##argtype##_sz, \
7127 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007128 .p_statidx = NFSPROC4_CLNT_##proc, \
7129 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007130}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007131
7132struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007133 PROC(READ, enc_read, dec_read),
7134 PROC(WRITE, enc_write, dec_write),
7135 PROC(COMMIT, enc_commit, dec_commit),
7136 PROC(OPEN, enc_open, dec_open),
7137 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7138 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7139 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7140 PROC(CLOSE, enc_close, dec_close),
7141 PROC(SETATTR, enc_setattr, dec_setattr),
7142 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7143 PROC(RENEW, enc_renew, dec_renew),
7144 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7145 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7146 PROC(LOCK, enc_lock, dec_lock),
7147 PROC(LOCKT, enc_lockt, dec_lockt),
7148 PROC(LOCKU, enc_locku, dec_locku),
7149 PROC(ACCESS, enc_access, dec_access),
7150 PROC(GETATTR, enc_getattr, dec_getattr),
7151 PROC(LOOKUP, enc_lookup, dec_lookup),
7152 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7153 PROC(REMOVE, enc_remove, dec_remove),
7154 PROC(RENAME, enc_rename, dec_rename),
7155 PROC(LINK, enc_link, dec_link),
7156 PROC(SYMLINK, enc_symlink, dec_symlink),
7157 PROC(CREATE, enc_create, dec_create),
7158 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7159 PROC(STATFS, enc_statfs, dec_statfs),
7160 PROC(READLINK, enc_readlink, dec_readlink),
7161 PROC(READDIR, enc_readdir, dec_readdir),
7162 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7163 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7164 PROC(GETACL, enc_getacl, dec_getacl),
7165 PROC(SETACL, enc_setacl, dec_setacl),
7166 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7167 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007168 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007169#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007170 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7171 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7172 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7173 PROC(SEQUENCE, enc_sequence, dec_sequence),
7174 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7175 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7176 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7177 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007178 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007179 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007180 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007181 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007182 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007183 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007184#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007185};
7186
Trond Myklebusta613fa12012-01-20 13:53:56 -05007187const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007189 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007190 .procs = nfs4_procedures
7191};
7192
7193/*
7194 * Local variables:
7195 * c-basic-offset: 8
7196 * End:
7197 */