blob: de4cb5cfc3184b83370afd5b6f94b768f205fd32 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Trond Myklebustcb17e552012-03-04 18:13:56 -0500888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 p = xdr_reserve_space(xdr, 4 + len);
901 BUG_ON(p == NULL);
902 xdr_encode_opaque(p, str, len);
903}
904
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400905static void encode_compound_hdr(struct xdr_stream *xdr,
906 struct rpc_rqst *req,
907 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Al Viro8687b632006-10-19 23:28:48 -0700909 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400910 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400911
912 /* initialize running count of expected bytes in reply.
913 * NOTE: the replied tag SHOULD be the same is the one sent,
914 * but this is not required as a MUST for the server to do so. */
915 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300918 p = reserve_space(xdr, 4 + hdr->taglen + 8);
919 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300920 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300922 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500923}
924
925static void encode_nops(struct compound_hdr *hdr)
926{
Andy Adamsonfc931582009-04-01 09:22:31 -0400927 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500928 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
931static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
932{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500933 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500936static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
938 char owner_name[IDMAP_NAMESZ];
939 char owner_group[IDMAP_NAMESZ];
940 int owner_namelen = 0;
941 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700942 __be32 *p;
943 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 int len;
945 uint32_t bmval0 = 0;
946 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948 /*
949 * We reserve enough space to write the entire attribute buffer at once.
950 * In the worst-case, this would be
951 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
952 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000953 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 */
955 len = 16;
956
957 /* Sigh */
958 if (iap->ia_valid & ATTR_SIZE)
959 len += 8;
960 if (iap->ia_valid & ATTR_MODE)
961 len += 4;
962 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800963 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400965 dprintk("nfs: couldn't resolve uid %d to string\n",
966 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 /* XXX */
968 strcpy(owner_name, "nobody");
969 owner_namelen = sizeof("nobody") - 1;
970 /* goto out; */
971 }
972 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
973 }
974 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800975 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400977 dprintk("nfs: couldn't resolve gid %d to string\n",
978 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 strcpy(owner_group, "nobody");
980 owner_grouplen = sizeof("nobody") - 1;
981 /* goto out; */
982 }
983 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
984 }
985 if (iap->ia_valid & ATTR_ATIME_SET)
986 len += 16;
987 else if (iap->ia_valid & ATTR_ATIME)
988 len += 4;
989 if (iap->ia_valid & ATTR_MTIME_SET)
990 len += 16;
991 else if (iap->ia_valid & ATTR_MTIME)
992 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300993 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 /*
996 * We write the bitmap length now, but leave the bitmap and the attribute
997 * buffer length to be backfilled at the end of this routine.
998 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300999 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 q = p;
1001 p += 3;
1002
1003 if (iap->ia_valid & ATTR_SIZE) {
1004 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001005 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007 if (iap->ia_valid & ATTR_MODE) {
1008 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001009 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
1011 if (iap->ia_valid & ATTR_UID) {
1012 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001013 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015 if (iap->ia_valid & ATTR_GID) {
1016 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001017 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019 if (iap->ia_valid & ATTR_ATIME_SET) {
1020 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001021 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1022 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001023 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1024 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026 else if (iap->ia_valid & ATTR_ATIME) {
1027 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001028 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 if (iap->ia_valid & ATTR_MTIME_SET) {
1031 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001032 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1033 *p++ = cpu_to_be32(0);
1034 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1035 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037 else if (iap->ia_valid & ATTR_MTIME) {
1038 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 /*
1043 * Now we backfill the bitmap and the attribute buffer length.
1044 */
1045 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001046 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 len, ((char *)p - (char *)q) + 4);
1048 BUG();
1049 }
1050 len = (char *)p - (char *)q - 12;
1051 *q++ = htonl(bmval0);
1052 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001053 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056}
1057
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001058static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Al Viro8687b632006-10-19 23:28:48 -07001060 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Benny Halevy13c65ce2009-08-14 17:19:25 +03001062 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001064 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001065 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001066 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001069static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Al Viro8687b632006-10-19 23:28:48 -07001071 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Benny Halevy13c65ce2009-08-14 17:19:25 +03001073 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001074 *p++ = cpu_to_be32(OP_CLOSE);
1075 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001076 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001077 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001078 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079}
1080
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001081static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Al Viro8687b632006-10-19 23:28:48 -07001083 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001084
Benny Halevy13c65ce2009-08-14 17:19:25 +03001085 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001086 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001087 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001088 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001089 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001090 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Al Viro8687b632006-10-19 23:28:48 -07001095 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001096
Benny Halevy13c65ce2009-08-14 17:19:25 +03001097 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001098 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001099 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 switch (create->ftype) {
1102 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001103 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001104 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001105 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 break;
1107
1108 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001109 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001110 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001111 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 break;
1113
1114 default:
1115 break;
1116 }
1117
Benny Halevy811652b2009-08-14 17:19:34 +03001118 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001119 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001120 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001125static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Andy Adamson05d564f2008-12-23 16:06:15 -05001127 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Benny Halevy13c65ce2009-08-14 17:19:25 +03001129 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001130 *p++ = cpu_to_be32(OP_GETATTR);
1131 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001132 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001133 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001134 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001137static 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 -07001138{
Andy Adamson05d564f2008-12-23 16:06:15 -05001139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Benny Halevy13c65ce2009-08-14 17:19:25 +03001141 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001142 *p++ = cpu_to_be32(OP_GETATTR);
1143 *p++ = cpu_to_be32(2);
1144 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001145 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001146 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001147 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Fred Isamandae100c2011-07-30 20:52:37 -04001150static void
1151encode_getattr_three(struct xdr_stream *xdr,
1152 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1153 struct compound_hdr *hdr)
1154{
1155 __be32 *p;
1156
1157 p = reserve_space(xdr, 4);
1158 *p = cpu_to_be32(OP_GETATTR);
1159 if (bm2) {
1160 p = reserve_space(xdr, 16);
1161 *p++ = cpu_to_be32(3);
1162 *p++ = cpu_to_be32(bm0);
1163 *p++ = cpu_to_be32(bm1);
1164 *p = cpu_to_be32(bm2);
1165 } else if (bm1) {
1166 p = reserve_space(xdr, 12);
1167 *p++ = cpu_to_be32(2);
1168 *p++ = cpu_to_be32(bm0);
1169 *p = cpu_to_be32(bm1);
1170 } else {
1171 p = reserve_space(xdr, 8);
1172 *p++ = cpu_to_be32(1);
1173 *p = cpu_to_be32(bm0);
1174 }
1175 hdr->nops++;
1176 hdr->replen += decode_getattr_maxsz;
1177}
1178
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001179static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001181 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1182 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Fred Isamandae100c2011-07-30 20:52:37 -04001187 encode_getattr_three(xdr,
1188 bitmask[0] & nfs4_fsinfo_bitmap[0],
1189 bitmask[1] & nfs4_fsinfo_bitmap[1],
1190 bitmask[2] & nfs4_fsinfo_bitmap[2],
1191 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001194static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001195{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001196 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1197 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001198}
1199
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001200static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Al Viro8687b632006-10-19 23:28:48 -07001202 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Benny Halevy13c65ce2009-08-14 17:19:25 +03001204 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001205 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001206 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001207 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208}
1209
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001210static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
Al Viro8687b632006-10-19 23:28:48 -07001212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Benny Halevy13c65ce2009-08-14 17:19:25 +03001214 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001215 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001216 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001217 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001218 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001221static inline int nfs4_lock_type(struct file_lock *fl, int block)
1222{
1223 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1224 return block ? NFS4_READW_LT : NFS4_READ_LT;
1225 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1226}
1227
1228static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1229{
1230 if (fl->fl_end == OFFSET_MAX)
1231 return ~(uint64_t)0;
1232 return fl->fl_end - fl->fl_start + 1;
1233}
1234
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001235static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1236{
1237 __be32 *p;
1238
Trond Myklebustd035c362010-12-21 10:45:27 -05001239 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001240 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001241 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001242 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001243 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244 xdr_encode_hyper(p, lowner->id);
1245}
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247/*
1248 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1249 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1250 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001251static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252{
Al Viro8687b632006-10-19 23:28:48 -07001253 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Benny Halevy13c65ce2009-08-14 17:19:25 +03001255 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001256 *p++ = cpu_to_be32(OP_LOCK);
1257 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1258 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001259 p = xdr_encode_hyper(p, args->fl->fl_start);
1260 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001261 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001262 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001263 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001264 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001265 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001266 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001267 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 }
1269 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001270 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001271 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001272 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
Andy Adamsond0179312008-12-23 16:06:17 -05001274 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001275 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Al Viro8687b632006-10-19 23:28:48 -07001280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001283 *p++ = cpu_to_be32(OP_LOCKT);
1284 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001285 p = xdr_encode_hyper(p, args->fl->fl_start);
1286 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001287 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001288 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001289 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001292static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293{
Al Viro8687b632006-10-19 23:28:48 -07001294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Benny Halevy13c65ce2009-08-14 17:19:25 +03001296 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(OP_LOCKU);
1298 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1299 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001300 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001301 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001302 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001303 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001304 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001307static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1308{
1309 __be32 *p;
1310
1311 p = reserve_space(xdr, 4);
1312 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1313 encode_lockowner(xdr, lowner);
1314 hdr->nops++;
1315 hdr->replen += decode_release_lockowner_maxsz;
1316}
1317
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001318static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Benny Halevy13c65ce2009-08-14 17:19:25 +03001323 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001324 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001325 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001326 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001327 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328}
1329
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001330static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
Al Viro8687b632006-10-19 23:28:48 -07001332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Benny Halevy13c65ce2009-08-14 17:19:25 +03001334 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001335 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001336 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001337 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001338 break;
1339 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001340 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001341 break;
1342 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001344 break;
1345 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001346 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 }
Benny Halevy34558512009-08-14 17:19:30 +03001348 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
1351static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 /*
1355 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1356 * owner 4 = 32
1357 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001358 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001359 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001360 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001361 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001362 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001363 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001364 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001365 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001366 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001367 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
1370static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001373 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Benny Halevy13c65ce2009-08-14 17:19:25 +03001375 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001377 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001378 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001379 encode_attrs(xdr, arg->u.attrs, arg->server);
1380 break;
1381 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001382 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001383 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001384 if (nfs4_has_persistent_session(clp)) {
1385 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1386 encode_attrs(xdr, arg->u.attrs, arg->server);
1387 } else {
1388 struct iattr dummy;
1389
1390 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1391 encode_nfs4_verifier(xdr, &arg->u.verifier);
1392 dummy.ia_valid = 0;
1393 encode_attrs(xdr, &dummy, arg->server);
1394 }
1395 } else {
1396 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1397 encode_nfs4_verifier(xdr, &arg->u.verifier);
1398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 }
1400}
1401
1402static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1403{
Al Viro8687b632006-10-19 23:28:48 -07001404 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Benny Halevy13c65ce2009-08-14 17:19:25 +03001406 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001408 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 break;
1411 default:
1412 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001413 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001414 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 }
1416}
1417
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001418static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
Al Viro8687b632006-10-19 23:28:48 -07001420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Benny Halevy13c65ce2009-08-14 17:19:25 +03001422 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001424 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 break;
1427 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001428 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 break;
1430 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001431 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 break;
1433 default:
1434 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 }
1436}
1437
1438static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1439{
Al Viro8687b632006-10-19 23:28:48 -07001440 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Benny Halevy13c65ce2009-08-14 17:19:25 +03001442 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001443 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 encode_string(xdr, name->len, name->name);
1445}
1446
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001447static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 encode_delegation_type(xdr, type);
1454}
1455
1456static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1457{
Al Viro8687b632006-10-19 23:28:48 -07001458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001461 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001462 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 encode_string(xdr, name->len, name->name);
1464}
1465
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001466static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
1468 encode_openhdr(xdr, arg);
1469 encode_opentype(xdr, arg);
1470 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001471 case NFS4_OPEN_CLAIM_NULL:
1472 encode_claim_null(xdr, arg->name);
1473 break;
1474 case NFS4_OPEN_CLAIM_PREVIOUS:
1475 encode_claim_previous(xdr, arg->u.delegation_type);
1476 break;
1477 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1478 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1479 break;
1480 default:
1481 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
Andy Adamsond0179312008-12-23 16:06:17 -05001483 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001484 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485}
1486
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001487static 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 -07001488{
Al Viro8687b632006-10-19 23:28:48 -07001489 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Benny Halevy13c65ce2009-08-14 17:19:25 +03001491 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001492 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001493 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001494 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001495 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001496 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001499static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Al Viro8687b632006-10-19 23:28:48 -07001501 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Benny Halevy13c65ce2009-08-14 17:19:25 +03001503 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001504 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001505 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001506 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001507 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001508 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001509 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static void
Andy Adamsond0179312008-12-23 16:06:17 -05001513encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
1515 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001516 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Benny Halevy13c65ce2009-08-14 17:19:25 +03001518 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001519 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001520 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001521 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001522 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001525static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Andy Adamson05d564f2008-12-23 16:06:15 -05001527 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001528
Benny Halevy13c65ce2009-08-14 17:19:25 +03001529 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001530 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001531 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001532 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001535static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001538 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Benny Halevy13c65ce2009-08-14 17:19:25 +03001540 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001542 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001543 if (zero_seqid)
1544 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001545 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 } else
Benny Halevy34558512009-08-14 17:19:30 +03001547 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Al Viro8687b632006-10-19 23:28:48 -07001552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Benny Halevy13c65ce2009-08-14 17:19:25 +03001554 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001555 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001557 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001558 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Benny Halevy13c65ce2009-08-14 17:19:25 +03001560 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001561 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001562 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001563 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001564 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001567static 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 -07001568{
Trond Myklebust28331a42011-04-27 13:47:52 -04001569 uint32_t attrs[2] = {
1570 FATTR4_WORD0_RDATTR_ERROR,
1571 FATTR4_WORD1_MOUNTED_ON_FILEID,
1572 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001573 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001574 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001576 if (readdir->plus) {
1577 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001578 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001579 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1580 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1581 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1582 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001583 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001584 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001585 /* Use mounted_on_fileid only if the server supports it */
1586 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1587 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001588
Benny Halevy13c65ce2009-08-14 17:19:25 +03001589 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001590 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001591 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001592 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001593 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(readdir->count);
1595 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001596
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001598 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001599 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001600 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001601 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1602 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001603 (unsigned long long)readdir->cookie,
1604 ((u32 *)readdir->verifier.data)[0],
1605 ((u32 *)readdir->verifier.data)[1],
1606 attrs[0] & readdir->bitmask[0],
1607 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608}
1609
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001610static 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 -07001611{
Al Viro8687b632006-10-19 23:28:48 -07001612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Benny Halevy13c65ce2009-08-14 17:19:25 +03001614 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001615 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001616 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001617 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
Al Viro8687b632006-10-19 23:28:48 -07001622 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
Benny Halevy13c65ce2009-08-14 17:19:25 +03001624 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001625 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001626 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001627 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001628 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001631static 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 -07001632{
Al Viro8687b632006-10-19 23:28:48 -07001633 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Benny Halevy811652b2009-08-14 17:19:34 +03001635 p = reserve_space(xdr, 4);
1636 *p = cpu_to_be32(OP_RENAME);
1637 encode_string(xdr, oldname->len, oldname->name);
1638 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001639 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001640 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Chuck Leverbb4dae52012-03-01 17:01:48 -05001643static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1644 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Al Viro8687b632006-10-19 23:28:48 -07001646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Benny Halevy13c65ce2009-08-14 17:19:25 +03001648 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001649 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001650 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001651 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001652 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void
Andy Adamsond0179312008-12-23 16:06:17 -05001656encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001657{
Al Viro8687b632006-10-19 23:28:48 -07001658 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001659
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001661 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001662 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001663 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001664}
1665
Chuck Lever9f06c712010-12-14 14:59:18 +00001666static void
Andy Adamsond0179312008-12-23 16:06:17 -05001667encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001668{
Al Viro8687b632006-10-19 23:28:48 -07001669 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001670
Benny Halevy13c65ce2009-08-14 17:19:25 +03001671 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001672 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001673 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001675 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001676 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001677 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001678 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001679 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001680 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001681 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001682 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001683}
1684
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001685static void
Andy Adamsond0179312008-12-23 16:06:17 -05001686encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
Al Viro8687b632006-10-19 23:28:48 -07001688 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Benny Halevy13c65ce2009-08-14 17:19:25 +03001690 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001691 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001692 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001693 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001696static 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 -07001697{
Al Viro8687b632006-10-19 23:28:48 -07001698 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001699
Benny Halevy13c65ce2009-08-14 17:19:25 +03001700 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001701 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001702 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001703 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001704 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001708static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Al Viro8687b632006-10-19 23:28:48 -07001710 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Benny Halevy13c65ce2009-08-14 17:19:25 +03001712 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001713 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001714 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
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_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1720 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001721 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001722 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001723 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001724 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001727static 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 -07001728{
Andy Adamson05d564f2008-12-23 16:06:15 -05001729 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Benny Halevy13c65ce2009-08-14 17:19:25 +03001731 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001733 p = xdr_encode_hyper(p, arg->clientid);
1734 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001735 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001736 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737}
1738
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001739static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Al Viro8687b632006-10-19 23:28:48 -07001741 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Benny Halevy13c65ce2009-08-14 17:19:25 +03001743 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001744 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001746 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001747 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Benny Halevy13c65ce2009-08-14 17:19:25 +03001749 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001750 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001751 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001752 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
1754 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001755 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001756 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757}
1758
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001759static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760{
Al Viro8687b632006-10-19 23:28:48 -07001761 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
Benny Halevy13c65ce2009-08-14 17:19:25 +03001763 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
Benny Halevye75bc1c2009-08-14 17:18:54 +03001765 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001766 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001767 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001768 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001770
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001771static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1772{
1773 int len = name->len;
1774 __be32 *p;
1775
1776 p = reserve_space(xdr, 8 + len);
1777 *p++ = cpu_to_be32(OP_SECINFO);
1778 xdr_encode_opaque(p, name->name, len);
1779 hdr->nops++;
1780 hdr->replen += decode_secinfo_maxsz;
1781}
1782
Benny Halevy99fe60d2009-04-01 09:22:29 -04001783#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001784/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001785static void encode_exchange_id(struct xdr_stream *xdr,
1786 struct nfs41_exchange_id_args *args,
1787 struct compound_hdr *hdr)
1788{
1789 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001790 char impl_name[NFS4_OPAQUE_LIMIT];
1791 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792
Benny Halevy13c65ce2009-08-14 17:19:25 +03001793 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001794 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001795 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001796
1797 encode_string(xdr, args->id_len, args->id);
1798
Benny Halevy13c65ce2009-08-14 17:19:25 +03001799 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001800 *p++ = cpu_to_be32(args->flags);
1801 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001802
1803 if (send_implementation_id &&
1804 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1805 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1806 <= NFS4_OPAQUE_LIMIT + 1)
1807 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1808 utsname()->sysname, utsname()->release,
1809 utsname()->version, utsname()->machine);
1810
1811 if (len > 0) {
1812 *p = cpu_to_be32(1); /* implementation id array length=1 */
1813
1814 encode_string(xdr,
1815 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1816 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1817 encode_string(xdr, len, impl_name);
1818 /* just send zeros for nii_date - the date is in nii_name */
1819 p = reserve_space(xdr, 12);
1820 p = xdr_encode_hyper(p, 0);
1821 *p = cpu_to_be32(0);
1822 } else
1823 *p = cpu_to_be32(0); /* implementation id array length=0 */
1824
Benny Halevy99fe60d2009-04-01 09:22:29 -04001825 hdr->nops++;
1826 hdr->replen += decode_exchange_id_maxsz;
1827}
Andy Adamsonfc931582009-04-01 09:22:31 -04001828
1829static void encode_create_session(struct xdr_stream *xdr,
1830 struct nfs41_create_session_args *args,
1831 struct compound_hdr *hdr)
1832{
1833 __be32 *p;
1834 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1835 uint32_t len;
1836 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001837 u32 max_resp_sz_cached;
1838
1839 /*
1840 * Assumes OPEN is the biggest non-idempotent compound.
1841 * 2 is the verifier.
1842 */
1843 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1844 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001845
Andy Adamsonfc931582009-04-01 09:22:31 -04001846 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1847 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001848
Benny Halevy13c65ce2009-08-14 17:19:25 +03001849 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001850 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001851 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1853 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001854
Andy Adamsonfc931582009-04-01 09:22:31 -04001855 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001856 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001857 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1858 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001859 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001860 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1861 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1862 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001863
1864 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001865 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001866 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1869 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1870 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1871 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001872
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001874 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001875 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001876
1877 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001878 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001879 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001880 *p++ = cpu_to_be32(0); /* UID */
1881 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001882 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001883 hdr->nops++;
1884 hdr->replen += decode_create_session_maxsz;
1885}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001886
1887static void encode_destroy_session(struct xdr_stream *xdr,
1888 struct nfs4_session *session,
1889 struct compound_hdr *hdr)
1890{
1891 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001892 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001893 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001894 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001895 hdr->nops++;
1896 hdr->replen += decode_destroy_session_maxsz;
1897}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001898
1899static void encode_reclaim_complete(struct xdr_stream *xdr,
1900 struct nfs41_reclaim_complete_args *args,
1901 struct compound_hdr *hdr)
1902{
1903 __be32 *p;
1904
1905 p = reserve_space(xdr, 8);
1906 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1907 *p++ = cpu_to_be32(args->one_fs);
1908 hdr->nops++;
1909 hdr->replen += decode_reclaim_complete_maxsz;
1910}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001911#endif /* CONFIG_NFS_V4_1 */
1912
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001913static void encode_sequence(struct xdr_stream *xdr,
1914 const struct nfs4_sequence_args *args,
1915 struct compound_hdr *hdr)
1916{
1917#if defined(CONFIG_NFS_V4_1)
1918 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001919 struct nfs4_slot_table *tp;
1920 struct nfs4_slot *slot;
1921 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001922
1923 if (!session)
1924 return;
1925
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001926 tp = &session->fc_slot_table;
1927
1928 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1929 slot = tp->slots + args->sa_slotid;
1930
Benny Halevy13c65ce2009-08-14 17:19:25 +03001931 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001932 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001933
1934 /*
1935 * Sessionid + seqid + slotid + max slotid + cache_this
1936 */
1937 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1938 "max_slotid=%d cache_this=%d\n",
1939 __func__,
1940 ((u32 *)session->sess_id.data)[0],
1941 ((u32 *)session->sess_id.data)[1],
1942 ((u32 *)session->sess_id.data)[2],
1943 ((u32 *)session->sess_id.data)[3],
1944 slot->seq_nr, args->sa_slotid,
1945 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001946 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001947 *p++ = cpu_to_be32(slot->seq_nr);
1948 *p++ = cpu_to_be32(args->sa_slotid);
1949 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001950 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001951 hdr->nops++;
1952 hdr->replen += decode_sequence_maxsz;
1953#endif /* CONFIG_NFS_V4_1 */
1954}
1955
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956#ifdef CONFIG_NFS_V4_1
1957static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001958encode_getdevicelist(struct xdr_stream *xdr,
1959 const struct nfs4_getdevicelist_args *args,
1960 struct compound_hdr *hdr)
1961{
1962 __be32 *p;
1963 nfs4_verifier dummy = {
1964 .data = "dummmmmy",
1965 };
1966
1967 p = reserve_space(xdr, 20);
1968 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1969 *p++ = cpu_to_be32(args->layoutclass);
1970 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1971 xdr_encode_hyper(p, 0ULL); /* cookie */
1972 encode_nfs4_verifier(xdr, &dummy);
1973 hdr->nops++;
1974 hdr->replen += decode_getdevicelist_maxsz;
1975}
1976
1977static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001978encode_getdeviceinfo(struct xdr_stream *xdr,
1979 const struct nfs4_getdeviceinfo_args *args,
1980 struct compound_hdr *hdr)
1981{
1982 __be32 *p;
1983
1984 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1985 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1986 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1987 NFS4_DEVICEID4_SIZE);
1988 *p++ = cpu_to_be32(args->pdev->layout_type);
1989 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1990 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1991 hdr->nops++;
1992 hdr->replen += decode_getdeviceinfo_maxsz;
1993}
1994
1995static void
1996encode_layoutget(struct xdr_stream *xdr,
1997 const struct nfs4_layoutget_args *args,
1998 struct compound_hdr *hdr)
1999{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002000 __be32 *p;
2001
2002 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
2003 *p++ = cpu_to_be32(OP_LAYOUTGET);
2004 *p++ = cpu_to_be32(0); /* Signal layout available */
2005 *p++ = cpu_to_be32(args->type);
2006 *p++ = cpu_to_be32(args->range.iomode);
2007 p = xdr_encode_hyper(p, args->range.offset);
2008 p = xdr_encode_hyper(p, args->range.length);
2009 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00002010 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002011 *p = cpu_to_be32(args->maxcount);
2012
2013 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2014 __func__,
2015 args->type,
2016 args->range.iomode,
2017 (unsigned long)args->range.offset,
2018 (unsigned long)args->range.length,
2019 args->maxcount);
2020 hdr->nops++;
2021 hdr->replen += decode_layoutget_maxsz;
2022}
Andy Adamson863a3c62011-03-23 13:27:54 +00002023
2024static int
2025encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002026 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002027 const struct nfs4_layoutcommit_args *args,
2028 struct compound_hdr *hdr)
2029{
2030 __be32 *p;
2031
2032 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2033 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2034
Benny Halevyac7db722011-05-22 19:53:48 +03002035 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00002036 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2037 /* Only whole file layouts */
2038 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002039 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00002040 *p++ = cpu_to_be32(0); /* reclaim */
2041 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2042 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2043 p = xdr_encode_hyper(p, args->lastbytewritten);
2044 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2045 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002046
2047 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2048 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2049 NFS_I(inode)->layout, xdr, args);
2050 else {
2051 p = reserve_space(xdr, 4);
2052 *p = cpu_to_be32(0); /* no layout-type payload */
2053 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002054
2055 hdr->nops++;
2056 hdr->replen += decode_layoutcommit_maxsz;
2057 return 0;
2058}
Benny Halevycbe82602011-05-22 19:52:37 +03002059
2060static void
2061encode_layoutreturn(struct xdr_stream *xdr,
2062 const struct nfs4_layoutreturn_args *args,
2063 struct compound_hdr *hdr)
2064{
2065 __be32 *p;
2066
2067 p = reserve_space(xdr, 20);
2068 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2069 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2070 *p++ = cpu_to_be32(args->layout_type);
2071 *p++ = cpu_to_be32(IOMODE_ANY);
2072 *p = cpu_to_be32(RETURN_FILE);
2073 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2074 p = xdr_encode_hyper(p, 0);
2075 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2076 spin_lock(&args->inode->i_lock);
2077 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2078 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002079 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2080 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2081 NFS_I(args->inode)->layout, xdr, args);
2082 } else {
2083 p = reserve_space(xdr, 4);
2084 *p = cpu_to_be32(0);
2085 }
Benny Halevycbe82602011-05-22 19:52:37 +03002086 hdr->nops++;
2087 hdr->replen += decode_layoutreturn_maxsz;
2088}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002089
2090static int
2091encode_secinfo_no_name(struct xdr_stream *xdr,
2092 const struct nfs41_secinfo_no_name_args *args,
2093 struct compound_hdr *hdr)
2094{
2095 __be32 *p;
2096 p = reserve_space(xdr, 8);
2097 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2098 *p++ = cpu_to_be32(args->style);
2099 hdr->nops++;
2100 hdr->replen += decode_secinfo_no_name_maxsz;
2101 return 0;
2102}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002103
2104static void encode_test_stateid(struct xdr_stream *xdr,
2105 struct nfs41_test_stateid_args *args,
2106 struct compound_hdr *hdr)
2107{
2108 __be32 *p;
2109
2110 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2111 *p++ = cpu_to_be32(OP_TEST_STATEID);
2112 *p++ = cpu_to_be32(1);
2113 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2114 hdr->nops++;
2115 hdr->replen += decode_test_stateid_maxsz;
2116}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002117
2118static void encode_free_stateid(struct xdr_stream *xdr,
2119 struct nfs41_free_stateid_args *args,
2120 struct compound_hdr *hdr)
2121{
2122 __be32 *p;
2123 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2124 *p++ = cpu_to_be32(OP_FREE_STATEID);
2125 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2126 hdr->nops++;
2127 hdr->replen += decode_free_stateid_maxsz;
2128}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002129#endif /* CONFIG_NFS_V4_1 */
2130
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131/*
2132 * END OF "GENERIC" ENCODE ROUTINES.
2133 */
2134
Benny Halevy66cc0422009-04-01 09:22:10 -04002135static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2136{
2137#if defined(CONFIG_NFS_V4_1)
2138 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002139 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002140#endif /* CONFIG_NFS_V4_1 */
2141 return 0;
2142}
2143
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144/*
2145 * Encode an ACCESS request
2146 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002147static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2148 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002151 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Chuck Lever9f06c712010-12-14 14:59:18 +00002154 encode_compound_hdr(xdr, req, &hdr);
2155 encode_sequence(xdr, &args->seq_args, &hdr);
2156 encode_putfh(xdr, args->fh, &hdr);
2157 encode_access(xdr, args->access, &hdr);
2158 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002159 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160}
2161
2162/*
2163 * Encode LOOKUP request
2164 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002165static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2166 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002169 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Chuck Lever9f06c712010-12-14 14:59:18 +00002172 encode_compound_hdr(xdr, req, &hdr);
2173 encode_sequence(xdr, &args->seq_args, &hdr);
2174 encode_putfh(xdr, args->dir_fh, &hdr);
2175 encode_lookup(xdr, args->name, &hdr);
2176 encode_getfh(xdr, &hdr);
2177 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002178 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179}
2180
2181/*
2182 * Encode LOOKUP_ROOT request
2183 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002184static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2185 struct xdr_stream *xdr,
2186 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002189 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Chuck Lever9f06c712010-12-14 14:59:18 +00002192 encode_compound_hdr(xdr, req, &hdr);
2193 encode_sequence(xdr, &args->seq_args, &hdr);
2194 encode_putrootfh(xdr, &hdr);
2195 encode_getfh(xdr, &hdr);
2196 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002197 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198}
2199
2200/*
2201 * Encode REMOVE request
2202 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002203static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2204 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002207 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Chuck Lever9f06c712010-12-14 14:59:18 +00002210 encode_compound_hdr(xdr, req, &hdr);
2211 encode_sequence(xdr, &args->seq_args, &hdr);
2212 encode_putfh(xdr, args->fh, &hdr);
2213 encode_remove(xdr, &args->name, &hdr);
2214 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002215 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216}
2217
2218/*
2219 * Encode RENAME request
2220 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002221static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2222 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002225 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Chuck Lever9f06c712010-12-14 14:59:18 +00002228 encode_compound_hdr(xdr, req, &hdr);
2229 encode_sequence(xdr, &args->seq_args, &hdr);
2230 encode_putfh(xdr, args->old_dir, &hdr);
2231 encode_savefh(xdr, &hdr);
2232 encode_putfh(xdr, args->new_dir, &hdr);
2233 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2234 encode_getfattr(xdr, args->bitmask, &hdr);
2235 encode_restorefh(xdr, &hdr);
2236 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002237 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
2240/*
2241 * Encode LINK request
2242 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002243static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2244 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_compound_hdr(xdr, req, &hdr);
2251 encode_sequence(xdr, &args->seq_args, &hdr);
2252 encode_putfh(xdr, args->fh, &hdr);
2253 encode_savefh(xdr, &hdr);
2254 encode_putfh(xdr, args->dir_fh, &hdr);
2255 encode_link(xdr, args->name, &hdr);
2256 encode_getfattr(xdr, args->bitmask, &hdr);
2257 encode_restorefh(xdr, &hdr);
2258 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002259 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260}
2261
2262/*
2263 * Encode CREATE request
2264 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002265static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2266 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002269 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Chuck Lever9f06c712010-12-14 14:59:18 +00002272 encode_compound_hdr(xdr, req, &hdr);
2273 encode_sequence(xdr, &args->seq_args, &hdr);
2274 encode_putfh(xdr, args->dir_fh, &hdr);
2275 encode_savefh(xdr, &hdr);
2276 encode_create(xdr, args, &hdr);
2277 encode_getfh(xdr, &hdr);
2278 encode_getfattr(xdr, args->bitmask, &hdr);
2279 encode_restorefh(xdr, &hdr);
2280 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002281 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282}
2283
2284/*
2285 * Encode SYMLINK request
2286 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002287static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2288 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289{
Chuck Lever9f06c712010-12-14 14:59:18 +00002290 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293/*
2294 * Encode GETATTR request
2295 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002296static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2297 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002300 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
Chuck Lever9f06c712010-12-14 14:59:18 +00002303 encode_compound_hdr(xdr, req, &hdr);
2304 encode_sequence(xdr, &args->seq_args, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
2306 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308}
2309
2310/*
2311 * Encode a CLOSE request
2312 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002313static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2314 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315{
Andy Adamson05d564f2008-12-23 16:06:15 -05002316 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002317 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002318 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
Chuck Lever9f06c712010-12-14 14:59:18 +00002320 encode_compound_hdr(xdr, req, &hdr);
2321 encode_sequence(xdr, &args->seq_args, &hdr);
2322 encode_putfh(xdr, args->fh, &hdr);
2323 encode_close(xdr, args, &hdr);
2324 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002325 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326}
2327
2328/*
2329 * Encode an OPEN request
2330 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002331static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2332 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002335 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Chuck Lever9f06c712010-12-14 14:59:18 +00002338 encode_compound_hdr(xdr, req, &hdr);
2339 encode_sequence(xdr, &args->seq_args, &hdr);
2340 encode_putfh(xdr, args->fh, &hdr);
2341 encode_savefh(xdr, &hdr);
2342 encode_open(xdr, args, &hdr);
2343 encode_getfh(xdr, &hdr);
2344 encode_getfattr(xdr, args->bitmask, &hdr);
2345 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002346 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002347 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348}
2349
2350/*
2351 * Encode an OPEN_CONFIRM request
2352 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002353static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2354 struct xdr_stream *xdr,
2355 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002358 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Chuck Lever9f06c712010-12-14 14:59:18 +00002361 encode_compound_hdr(xdr, req, &hdr);
2362 encode_putfh(xdr, args->fh, &hdr);
2363 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002364 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365}
2366
2367/*
2368 * Encode an OPEN request with no attributes.
2369 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002370static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2371 struct xdr_stream *xdr,
2372 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002375 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_sequence(xdr, &args->seq_args, &hdr);
2380 encode_putfh(xdr, args->fh, &hdr);
2381 encode_open(xdr, args, &hdr);
2382 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002383 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384}
2385
2386/*
2387 * Encode an OPEN_DOWNGRADE request
2388 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002389static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2390 struct xdr_stream *xdr,
2391 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002394 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Chuck Lever9f06c712010-12-14 14:59:18 +00002397 encode_compound_hdr(xdr, req, &hdr);
2398 encode_sequence(xdr, &args->seq_args, &hdr);
2399 encode_putfh(xdr, args->fh, &hdr);
2400 encode_open_downgrade(xdr, args, &hdr);
2401 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002402 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
2405/*
2406 * Encode a LOCK request
2407 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002408static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2409 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002412 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
Chuck Lever9f06c712010-12-14 14:59:18 +00002415 encode_compound_hdr(xdr, req, &hdr);
2416 encode_sequence(xdr, &args->seq_args, &hdr);
2417 encode_putfh(xdr, args->fh, &hdr);
2418 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002419 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420}
2421
2422/*
2423 * Encode a LOCKT request
2424 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002425static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2426 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002429 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Chuck Lever9f06c712010-12-14 14:59:18 +00002432 encode_compound_hdr(xdr, req, &hdr);
2433 encode_sequence(xdr, &args->seq_args, &hdr);
2434 encode_putfh(xdr, args->fh, &hdr);
2435 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002436 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437}
2438
2439/*
2440 * Encode a LOCKU request
2441 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002442static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2443 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002446 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Chuck Lever9f06c712010-12-14 14:59:18 +00002449 encode_compound_hdr(xdr, req, &hdr);
2450 encode_sequence(xdr, &args->seq_args, &hdr);
2451 encode_putfh(xdr, args->fh, &hdr);
2452 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002453 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454}
2455
Chuck Lever9f06c712010-12-14 14:59:18 +00002456static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2457 struct xdr_stream *xdr,
2458 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002459{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002460 struct compound_hdr hdr = {
2461 .minorversion = 0,
2462 };
2463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464 encode_compound_hdr(xdr, req, &hdr);
2465 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002466 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002467}
2468
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469/*
2470 * Encode a READLINK request
2471 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002472static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2473 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002476 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478
Chuck Lever9f06c712010-12-14 14:59:18 +00002479 encode_compound_hdr(xdr, req, &hdr);
2480 encode_sequence(xdr, &args->seq_args, &hdr);
2481 encode_putfh(xdr, args->fh, &hdr);
2482 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002483
Benny Halevy28f56692009-04-01 09:22:09 -04002484 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002485 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002486 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487}
2488
2489/*
2490 * Encode a READDIR request
2491 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002492static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2493 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002496 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
Chuck Lever9f06c712010-12-14 14:59:18 +00002499 encode_compound_hdr(xdr, req, &hdr);
2500 encode_sequence(xdr, &args->seq_args, &hdr);
2501 encode_putfh(xdr, args->fh, &hdr);
2502 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002503
Benny Halevy28f56692009-04-01 09:22:09 -04002504 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002505 args->pgbase, args->count);
2506 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002507 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002508 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002509 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * Encode a READ request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
Benny Halevy28f56692009-04-01 09:22:09 -04002527 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002529 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002530 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531}
2532
2533/*
2534 * Encode an SETATTR request
2535 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002536static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2537 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538{
Andy Adamson05d564f2008-12-23 16:06:15 -05002539 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002540 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002541 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Chuck Lever9f06c712010-12-14 14:59:18 +00002543 encode_compound_hdr(xdr, req, &hdr);
2544 encode_sequence(xdr, &args->seq_args, &hdr);
2545 encode_putfh(xdr, args->fh, &hdr);
2546 encode_setattr(xdr, args, args->server, &hdr);
2547 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002548 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549}
2550
2551/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002552 * Encode a GETACL request
2553 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002554static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2555 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002556{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002557 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002558 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002559 };
Benny Halevy28f56692009-04-01 09:22:09 -04002560 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002561
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002565 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002566 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002567
Benny Halevy28f56692009-04-01 09:22:09 -04002568 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002569 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002570
Andy Adamsond0179312008-12-23 16:06:17 -05002571 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002572}
2573
2574/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 * Encode a WRITE request
2576 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002577static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2578 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002581 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_compound_hdr(xdr, req, &hdr);
2585 encode_sequence(xdr, &args->seq_args, &hdr);
2586 encode_putfh(xdr, args->fh, &hdr);
2587 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002588 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002589 if (args->bitmask)
2590 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002591 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592}
2593
2594/*
2595 * a COMMIT request
2596 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002597static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2598 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002601 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Chuck Lever9f06c712010-12-14 14:59:18 +00002604 encode_compound_hdr(xdr, req, &hdr);
2605 encode_sequence(xdr, &args->seq_args, &hdr);
2606 encode_putfh(xdr, args->fh, &hdr);
2607 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002608 if (args->bitmask)
2609 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002610 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611}
2612
2613/*
2614 * FSINFO request
2615 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002616static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2617 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002620 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
Chuck Lever9f06c712010-12-14 14:59:18 +00002623 encode_compound_hdr(xdr, req, &hdr);
2624 encode_sequence(xdr, &args->seq_args, &hdr);
2625 encode_putfh(xdr, args->fh, &hdr);
2626 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002627 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628}
2629
2630/*
2631 * a PATHCONF request
2632 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002633static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2634 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002637 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Chuck Lever9f06c712010-12-14 14:59:18 +00002640 encode_compound_hdr(xdr, req, &hdr);
2641 encode_sequence(xdr, &args->seq_args, &hdr);
2642 encode_putfh(xdr, args->fh, &hdr);
2643 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002644 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002645 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646}
2647
2648/*
2649 * a STATFS request
2650 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002651static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2652 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002655 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Chuck Lever9f06c712010-12-14 14:59:18 +00002658 encode_compound_hdr(xdr, req, &hdr);
2659 encode_sequence(xdr, &args->seq_args, &hdr);
2660 encode_putfh(xdr, args->fh, &hdr);
2661 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002662 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002663 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664}
2665
2666/*
2667 * GETATTR_BITMAP request
2668 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002669static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002674 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, &args->seq_args, &hdr);
2679 encode_putfh(xdr, args->fhandle, &hdr);
2680 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002681 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002682 FATTR4_WORD0_LINK_SUPPORT|
2683 FATTR4_WORD0_SYMLINK_SUPPORT|
2684 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002685 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686}
2687
2688/*
2689 * a RENEW request
2690 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002691static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2692 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002695 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 };
2697
Chuck Lever9f06c712010-12-14 14:59:18 +00002698 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002699 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002700 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701}
2702
2703/*
2704 * a SETCLIENTID request
2705 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002706static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2707 struct xdr_stream *xdr,
2708 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002711 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 };
2713
Chuck Lever9f06c712010-12-14 14:59:18 +00002714 encode_compound_hdr(xdr, req, &hdr);
2715 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002716 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717}
2718
2719/*
2720 * a SETCLIENTID_CONFIRM request
2721 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002722static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2723 struct xdr_stream *xdr,
2724 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002727 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 };
Fred Isamandae100c2011-07-30 20:52:37 -04002729 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
Chuck Lever9f06c712010-12-14 14:59:18 +00002731 encode_compound_hdr(xdr, req, &hdr);
2732 encode_setclientid_confirm(xdr, arg, &hdr);
2733 encode_putrootfh(xdr, &hdr);
2734 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002735 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736}
2737
2738/*
2739 * DELEGRETURN request
2740 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002741static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2742 struct xdr_stream *xdr,
2743 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002746 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
Chuck Lever9f06c712010-12-14 14:59:18 +00002749 encode_compound_hdr(xdr, req, &hdr);
2750 encode_sequence(xdr, &args->seq_args, &hdr);
2751 encode_putfh(xdr, args->fhandle, &hdr);
2752 encode_delegreturn(xdr, args->stateid, &hdr);
2753 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002754 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755}
2756
2757/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002758 * Encode FS_LOCATIONS request
2759 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002760static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2761 struct xdr_stream *xdr,
2762 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002763{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002764 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002766 };
Benny Halevy28f56692009-04-01 09:22:09 -04002767 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002768
Chuck Lever9f06c712010-12-14 14:59:18 +00002769 encode_compound_hdr(xdr, req, &hdr);
2770 encode_sequence(xdr, &args->seq_args, &hdr);
2771 encode_putfh(xdr, args->dir_fh, &hdr);
2772 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002773 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002774 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002775
Benny Halevy28f56692009-04-01 09:22:09 -04002776 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002777 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002778 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002779}
2780
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002781/*
2782 * Encode SECINFO request
2783 */
2784static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2785 struct xdr_stream *xdr,
2786 struct nfs4_secinfo_arg *args)
2787{
2788 struct compound_hdr hdr = {
2789 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2790 };
2791
2792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_sequence(xdr, &args->seq_args, &hdr);
2794 encode_putfh(xdr, args->dir_fh, &hdr);
2795 encode_secinfo(xdr, args->name, &hdr);
2796 encode_nops(&hdr);
2797}
2798
Benny Halevy99fe60d2009-04-01 09:22:29 -04002799#if defined(CONFIG_NFS_V4_1)
2800/*
2801 * EXCHANGE_ID request
2802 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002803static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2804 struct xdr_stream *xdr,
2805 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002806{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002807 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002808 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002809 };
2810
Chuck Lever9f06c712010-12-14 14:59:18 +00002811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002813 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002814}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002815
2816/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002817 * a CREATE_SESSION request
2818 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002819static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002822{
Andy Adamsonfc931582009-04-01 09:22:31 -04002823 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002824 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002825 };
2826
Chuck Lever9f06c712010-12-14 14:59:18 +00002827 encode_compound_hdr(xdr, req, &hdr);
2828 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002829 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002830}
2831
2832/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002833 * a DESTROY_SESSION request
2834 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002835static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2836 struct xdr_stream *xdr,
2837 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002838{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002839 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002840 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002841 };
2842
Chuck Lever9f06c712010-12-14 14:59:18 +00002843 encode_compound_hdr(xdr, req, &hdr);
2844 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002845 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002846}
2847
2848/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002849 * a SEQUENCE request
2850 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002851static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2852 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002853{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002854 struct compound_hdr hdr = {
2855 .minorversion = nfs4_xdr_minorversion(args),
2856 };
2857
Chuck Lever9f06c712010-12-14 14:59:18 +00002858 encode_compound_hdr(xdr, req, &hdr);
2859 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002860 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002861}
2862
2863/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002864 * a GET_LEASE_TIME request
2865 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002866static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2867 struct xdr_stream *xdr,
2868 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002869{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002870 struct compound_hdr hdr = {
2871 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2872 };
Fred Isamandae100c2011-07-30 20:52:37 -04002873 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002874
Chuck Lever9f06c712010-12-14 14:59:18 +00002875 encode_compound_hdr(xdr, req, &hdr);
2876 encode_sequence(xdr, &args->la_seq_args, &hdr);
2877 encode_putrootfh(xdr, &hdr);
2878 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002879 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002880}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002881
2882/*
2883 * a RECLAIM_COMPLETE request
2884 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002885static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2886 struct xdr_stream *xdr,
2887 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002888{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002889 struct compound_hdr hdr = {
2890 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2891 };
2892
Chuck Lever9f06c712010-12-14 14:59:18 +00002893 encode_compound_hdr(xdr, req, &hdr);
2894 encode_sequence(xdr, &args->seq_args, &hdr);
2895 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002896 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002897}
2898
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002899/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002900 * Encode GETDEVICELIST request
2901 */
2902static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2903 struct xdr_stream *xdr,
2904 struct nfs4_getdevicelist_args *args)
2905{
2906 struct compound_hdr hdr = {
2907 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2908 };
2909
2910 encode_compound_hdr(xdr, req, &hdr);
2911 encode_sequence(xdr, &args->seq_args, &hdr);
2912 encode_putfh(xdr, args->fh, &hdr);
2913 encode_getdevicelist(xdr, args, &hdr);
2914 encode_nops(&hdr);
2915}
2916
2917/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002918 * Encode GETDEVICEINFO request
2919 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002920static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2921 struct xdr_stream *xdr,
2922 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002923{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002924 struct compound_hdr hdr = {
2925 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2926 };
2927
Chuck Lever9f06c712010-12-14 14:59:18 +00002928 encode_compound_hdr(xdr, req, &hdr);
2929 encode_sequence(xdr, &args->seq_args, &hdr);
2930 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002931
2932 /* set up reply kvec. Subtract notification bitmap max size (2)
2933 * so that notification bitmap is put in xdr_buf tail */
2934 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2935 args->pdev->pages, args->pdev->pgbase,
2936 args->pdev->pglen);
2937
2938 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002939}
2940
2941/*
2942 * Encode LAYOUTGET request
2943 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002944static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2945 struct xdr_stream *xdr,
2946 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002947{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002948 struct compound_hdr hdr = {
2949 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2950 };
2951
Chuck Lever9f06c712010-12-14 14:59:18 +00002952 encode_compound_hdr(xdr, req, &hdr);
2953 encode_sequence(xdr, &args->seq_args, &hdr);
2954 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2955 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002956
2957 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2958 args->layout.pages, 0, args->layout.pglen);
2959
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002960 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002961}
Andy Adamson863a3c62011-03-23 13:27:54 +00002962
2963/*
2964 * Encode LAYOUTCOMMIT request
2965 */
Benny Halevycbe82602011-05-22 19:52:37 +03002966static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2967 struct xdr_stream *xdr,
2968 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002969{
Benny Halevyac7db722011-05-22 19:53:48 +03002970 struct nfs4_layoutcommit_data *data =
2971 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002972 struct compound_hdr hdr = {
2973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2974 };
2975
2976 encode_compound_hdr(xdr, req, &hdr);
2977 encode_sequence(xdr, &args->seq_args, &hdr);
2978 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002979 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002980 encode_getfattr(xdr, args->bitmask, &hdr);
2981 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002982}
2983
2984/*
2985 * Encode LAYOUTRETURN request
2986 */
2987static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2988 struct xdr_stream *xdr,
2989 struct nfs4_layoutreturn_args *args)
2990{
2991 struct compound_hdr hdr = {
2992 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2993 };
2994
2995 encode_compound_hdr(xdr, req, &hdr);
2996 encode_sequence(xdr, &args->seq_args, &hdr);
2997 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2998 encode_layoutreturn(xdr, args, &hdr);
2999 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003000}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003001
3002/*
3003 * Encode SECINFO_NO_NAME request
3004 */
3005static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3006 struct xdr_stream *xdr,
3007 struct nfs41_secinfo_no_name_args *args)
3008{
3009 struct compound_hdr hdr = {
3010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3011 };
3012
3013 encode_compound_hdr(xdr, req, &hdr);
3014 encode_sequence(xdr, &args->seq_args, &hdr);
3015 encode_putrootfh(xdr, &hdr);
3016 encode_secinfo_no_name(xdr, args, &hdr);
3017 encode_nops(&hdr);
3018 return 0;
3019}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003020
3021/*
3022 * Encode TEST_STATEID request
3023 */
3024static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3025 struct xdr_stream *xdr,
3026 struct nfs41_test_stateid_args *args)
3027{
3028 struct compound_hdr hdr = {
3029 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3030 };
3031
3032 encode_compound_hdr(xdr, req, &hdr);
3033 encode_sequence(xdr, &args->seq_args, &hdr);
3034 encode_test_stateid(xdr, args, &hdr);
3035 encode_nops(&hdr);
3036}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003037
3038/*
3039 * Encode FREE_STATEID request
3040 */
3041static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3042 struct xdr_stream *xdr,
3043 struct nfs41_free_stateid_args *args)
3044{
3045 struct compound_hdr hdr = {
3046 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3047 };
3048
3049 encode_compound_hdr(xdr, req, &hdr);
3050 encode_sequence(xdr, &args->seq_args, &hdr);
3051 encode_free_stateid(xdr, args, &hdr);
3052 encode_nops(&hdr);
3053}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003054#endif /* CONFIG_NFS_V4_1 */
3055
Benny Halevy686841b2009-08-14 17:19:48 +03003056static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3057{
3058 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3059 "Remaining buffer length is %tu words.\n",
3060 func, xdr->end - xdr->p);
3061}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Trond Myklebust683b57b2006-06-09 09:34:22 -04003063static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064{
Al Viro8687b632006-10-19 23:28:48 -07003065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
Benny Halevyc0eae662009-08-14 17:20:14 +03003067 p = xdr_inline_decode(xdr, 4);
3068 if (unlikely(!p))
3069 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003070 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003071 p = xdr_inline_decode(xdr, *len);
3072 if (unlikely(!p))
3073 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 *string = (char *)p;
3075 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003076out_overflow:
3077 print_overflow_msg(__func__, xdr);
3078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
3081static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3082{
Al Viro8687b632006-10-19 23:28:48 -07003083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
Benny Halevyc0eae662009-08-14 17:20:14 +03003085 p = xdr_inline_decode(xdr, 8);
3086 if (unlikely(!p))
3087 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003088 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003089 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003090
Benny Halevyc0eae662009-08-14 17:20:14 +03003091 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3092 if (unlikely(!p))
3093 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 hdr->tag = (char *)p;
3095 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003096 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003097 if (unlikely(hdr->nops < 1))
3098 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003100out_overflow:
3101 print_overflow_msg(__func__, xdr);
3102 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103}
3104
3105static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3106{
Al Viro8687b632006-10-19 23:28:48 -07003107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 uint32_t opnum;
3109 int32_t nfserr;
3110
Benny Halevyc0eae662009-08-14 17:20:14 +03003111 p = xdr_inline_decode(xdr, 8);
3112 if (unlikely(!p))
3113 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003114 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003116 dprintk("nfs: Server returned operation"
3117 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 opnum, expected);
3119 return -EIO;
3120 }
Benny Halevycccddf42009-08-14 17:20:19 +03003121 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003123 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003125out_overflow:
3126 print_overflow_msg(__func__, xdr);
3127 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128}
3129
3130/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003131static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132{
Al Viro8687b632006-10-19 23:28:48 -07003133 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003134 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 char *str;
3136
Benny Halevyc0eae662009-08-14 17:20:14 +03003137 p = xdr_inline_decode(xdr, 12);
3138 if (likely(p))
3139 return decode_opaque_inline(xdr, &strlen, &str);
3140 print_overflow_msg(__func__, xdr);
3141 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
3144static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3145{
Al Viro8687b632006-10-19 23:28:48 -07003146 uint32_t bmlen;
3147 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Benny Halevyc0eae662009-08-14 17:20:14 +03003149 p = xdr_inline_decode(xdr, 4);
3150 if (unlikely(!p))
3151 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003152 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
Fred Isamandae100c2011-07-30 20:52:37 -04003154 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003155 p = xdr_inline_decode(xdr, (bmlen << 2));
3156 if (unlikely(!p))
3157 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003159 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003160 if (bmlen > 1) {
3161 bitmap[1] = be32_to_cpup(p++);
3162 if (bmlen > 2)
3163 bitmap[2] = be32_to_cpup(p);
3164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 }
3166 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003167out_overflow:
3168 print_overflow_msg(__func__, xdr);
3169 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170}
3171
Al Viro8687b632006-10-19 23:28:48 -07003172static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
Al Viro8687b632006-10-19 23:28:48 -07003174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175
Benny Halevyc0eae662009-08-14 17:20:14 +03003176 p = xdr_inline_decode(xdr, 4);
3177 if (unlikely(!p))
3178 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003179 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 *savep = xdr->p;
3181 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003182out_overflow:
3183 print_overflow_msg(__func__, xdr);
3184 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185}
3186
3187static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3188{
3189 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003190 int ret;
3191 ret = decode_attr_bitmap(xdr, bitmask);
3192 if (unlikely(ret < 0))
3193 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3195 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003196 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3197 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3198 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 return 0;
3200}
3201
3202static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3203{
Al Viro8687b632006-10-19 23:28:48 -07003204 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003205 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
3207 *type = 0;
3208 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3209 return -EIO;
3210 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003211 p = xdr_inline_decode(xdr, 4);
3212 if (unlikely(!p))
3213 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003214 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003216 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 return -EIO;
3218 }
3219 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003222 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003223 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003224out_overflow:
3225 print_overflow_msg(__func__, xdr);
3226 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227}
3228
Chuck Lever264e6352012-03-01 17:02:05 -05003229static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3230 uint32_t *bitmap, uint32_t *type)
3231{
3232 __be32 *p;
3233
3234 *type = 0;
3235 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3236 return -EIO;
3237 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3238 p = xdr_inline_decode(xdr, 4);
3239 if (unlikely(!p))
3240 goto out_overflow;
3241 *type = be32_to_cpup(p);
3242 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3243 }
3244 dprintk("%s: expire type=0x%x\n", __func__, *type);
3245 return 0;
3246out_overflow:
3247 print_overflow_msg(__func__, xdr);
3248 return -EIO;
3249}
3250
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3252{
Al Viro8687b632006-10-19 23:28:48 -07003253 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003254 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
3256 *change = 0;
3257 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3258 return -EIO;
3259 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003260 p = xdr_inline_decode(xdr, 8);
3261 if (unlikely(!p))
3262 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003263 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003267 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003269 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003270out_overflow:
3271 print_overflow_msg(__func__, xdr);
3272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273}
3274
3275static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3276{
Al Viro8687b632006-10-19 23:28:48 -07003277 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003278 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 *size = 0;
3281 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3282 return -EIO;
3283 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003284 p = xdr_inline_decode(xdr, 8);
3285 if (unlikely(!p))
3286 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003287 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003289 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003291 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003292 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003293out_overflow:
3294 print_overflow_msg(__func__, xdr);
3295 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296}
3297
3298static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3299{
Al Viro8687b632006-10-19 23:28:48 -07003300 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
3302 *res = 0;
3303 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3304 return -EIO;
3305 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003306 p = xdr_inline_decode(xdr, 4);
3307 if (unlikely(!p))
3308 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003309 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3311 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003312 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003314out_overflow:
3315 print_overflow_msg(__func__, xdr);
3316 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317}
3318
3319static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3320{
Al Viro8687b632006-10-19 23:28:48 -07003321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
3323 *res = 0;
3324 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3325 return -EIO;
3326 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003327 p = xdr_inline_decode(xdr, 4);
3328 if (unlikely(!p))
3329 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003330 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3332 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003333 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003335out_overflow:
3336 print_overflow_msg(__func__, xdr);
3337 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338}
3339
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003340static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341{
Al Viro8687b632006-10-19 23:28:48 -07003342 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003343 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
3345 fsid->major = 0;
3346 fsid->minor = 0;
3347 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3348 return -EIO;
3349 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003350 p = xdr_inline_decode(xdr, 16);
3351 if (unlikely(!p))
3352 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003353 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003354 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003356 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003358 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 (unsigned long long)fsid->major,
3360 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003361 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003362out_overflow:
3363 print_overflow_msg(__func__, xdr);
3364 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365}
3366
3367static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3368{
Al Viro8687b632006-10-19 23:28:48 -07003369 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 *res = 60;
3372 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3373 return -EIO;
3374 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003375 p = xdr_inline_decode(xdr, 4);
3376 if (unlikely(!p))
3377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003378 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3380 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003381 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003383out_overflow:
3384 print_overflow_msg(__func__, xdr);
3385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386}
3387
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003388static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003389{
3390 __be32 *p;
3391
3392 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3393 return -EIO;
3394 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3395 p = xdr_inline_decode(xdr, 4);
3396 if (unlikely(!p))
3397 goto out_overflow;
3398 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003399 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003400 }
3401 return 0;
3402out_overflow:
3403 print_overflow_msg(__func__, xdr);
3404 return -EIO;
3405}
3406
3407static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3408{
3409 __be32 *p;
3410 int len;
3411
Trond Myklebust7ad07352010-10-23 15:34:20 -04003412 if (fh != NULL)
3413 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003414
3415 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3416 return -EIO;
3417 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3418 p = xdr_inline_decode(xdr, 4);
3419 if (unlikely(!p))
3420 goto out_overflow;
3421 len = be32_to_cpup(p);
3422 if (len > NFS4_FHSIZE)
3423 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003424 p = xdr_inline_decode(xdr, len);
3425 if (unlikely(!p))
3426 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003427 if (fh != NULL) {
3428 memcpy(fh->data, p, len);
3429 fh->size = len;
3430 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003431 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3432 }
3433 return 0;
3434out_overflow:
3435 print_overflow_msg(__func__, xdr);
3436 return -EIO;
3437}
3438
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3440{
Al Viro8687b632006-10-19 23:28:48 -07003441 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
3443 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3444 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3445 return -EIO;
3446 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003447 p = xdr_inline_decode(xdr, 4);
3448 if (unlikely(!p))
3449 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003450 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3452 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003453 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003455out_overflow:
3456 print_overflow_msg(__func__, xdr);
3457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458}
3459
3460static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3461{
Al Viro8687b632006-10-19 23:28:48 -07003462 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003463 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
3465 *fileid = 0;
3466 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3467 return -EIO;
3468 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 8);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003474 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003476 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003477 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003478out_overflow:
3479 print_overflow_msg(__func__, xdr);
3480 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481}
3482
Manoj Naik99baf622006-06-09 09:34:24 -04003483static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3484{
Al Viro8687b632006-10-19 23:28:48 -07003485 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003486 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003487
3488 *fileid = 0;
3489 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3490 return -EIO;
3491 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003492 p = xdr_inline_decode(xdr, 8);
3493 if (unlikely(!p))
3494 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003495 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003496 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003497 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003498 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003499 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003500 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003501out_overflow:
3502 print_overflow_msg(__func__, xdr);
3503 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003504}
3505
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3507{
Al Viro8687b632006-10-19 23:28:48 -07003508 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 int status = 0;
3510
3511 *res = 0;
3512 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3513 return -EIO;
3514 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003515 p = xdr_inline_decode(xdr, 8);
3516 if (unlikely(!p))
3517 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003518 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3520 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003521 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003523out_overflow:
3524 print_overflow_msg(__func__, xdr);
3525 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526}
3527
3528static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3529{
Al Viro8687b632006-10-19 23:28:48 -07003530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 int status = 0;
3532
3533 *res = 0;
3534 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3535 return -EIO;
3536 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003537 p = xdr_inline_decode(xdr, 8);
3538 if (unlikely(!p))
3539 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003540 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3542 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003543 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003545out_overflow:
3546 print_overflow_msg(__func__, xdr);
3547 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548}
3549
3550static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3551{
Al Viro8687b632006-10-19 23:28:48 -07003552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 int status = 0;
3554
3555 *res = 0;
3556 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3557 return -EIO;
3558 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003559 p = xdr_inline_decode(xdr, 8);
3560 if (unlikely(!p))
3561 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003562 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3564 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003565 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003567out_overflow:
3568 print_overflow_msg(__func__, xdr);
3569 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570}
3571
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003572static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3573{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003574 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003575 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003576 int status = 0;
3577
Benny Halevyc0eae662009-08-14 17:20:14 +03003578 p = xdr_inline_decode(xdr, 4);
3579 if (unlikely(!p))
3580 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003581 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003582 if (n == 0)
3583 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003584 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003585 path->ncomponents = 0;
3586 while (path->ncomponents < n) {
3587 struct nfs4_string *component = &path->components[path->ncomponents];
3588 status = decode_opaque_inline(xdr, &component->len, &component->data);
3589 if (unlikely(status != 0))
3590 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003591 if (unlikely(nfs_debug & NFSDBG_XDR))
3592 pr_cont("%s%.*s ",
3593 (path->ncomponents != n ? "/ " : ""),
3594 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003595 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3596 path->ncomponents++;
3597 else {
3598 dprintk("cannot parse %d components in path\n", n);
3599 goto out_eio;
3600 }
3601 }
3602out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003603 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003604root_path:
3605/* a root pathname is sent as a zero component4 */
3606 path->ncomponents = 1;
3607 path->components[0].len=0;
3608 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003609 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003610 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003611out_eio:
3612 dprintk(" status %d", status);
3613 status = -EIO;
3614 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003615out_overflow:
3616 print_overflow_msg(__func__, xdr);
3617 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003618}
3619
3620static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003621{
3622 int n;
Al Viro8687b632006-10-19 23:28:48 -07003623 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003624 int status = -EIO;
3625
3626 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3627 goto out;
3628 status = 0;
3629 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3630 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003631 status = -EIO;
3632 /* Ignore borken servers that return unrequested attrs */
3633 if (unlikely(res == NULL))
3634 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003635 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003636 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003637 if (unlikely(status != 0))
3638 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003639 p = xdr_inline_decode(xdr, 4);
3640 if (unlikely(!p))
3641 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003642 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003643 if (n <= 0)
3644 goto out_eio;
3645 res->nlocations = 0;
3646 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003647 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003648 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003649
Benny Halevyc0eae662009-08-14 17:20:14 +03003650 p = xdr_inline_decode(xdr, 4);
3651 if (unlikely(!p))
3652 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003653 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003654
3655 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003656 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003657 while (loc->nservers < m) {
3658 struct nfs4_string *server = &loc->servers[loc->nservers];
3659 status = decode_opaque_inline(xdr, &server->len, &server->data);
3660 if (unlikely(status != 0))
3661 goto out_eio;
3662 dprintk("%s ", server->data);
3663 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3664 loc->nservers++;
3665 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003666 unsigned int i;
3667 dprintk("%s: using first %u of %u servers "
3668 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003669 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003670 NFS4_FS_LOCATION_MAXSERVERS,
3671 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003672 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003673 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003674 char *data;
3675 status = decode_opaque_inline(xdr, &len, &data);
3676 if (unlikely(status != 0))
3677 goto out_eio;
3678 }
3679 }
3680 }
3681 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003682 if (unlikely(status != 0))
3683 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003684 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003685 res->nlocations++;
3686 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003687 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003688 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003689out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003690 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003691 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003692out_overflow:
3693 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003694out_eio:
3695 status = -EIO;
3696 goto out;
3697}
3698
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3700{
Al Viro8687b632006-10-19 23:28:48 -07003701 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 int status = 0;
3703
3704 *res = 0;
3705 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3706 return -EIO;
3707 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003708 p = xdr_inline_decode(xdr, 8);
3709 if (unlikely(!p))
3710 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003711 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3713 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003714 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003716out_overflow:
3717 print_overflow_msg(__func__, xdr);
3718 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719}
3720
3721static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3722{
Al Viro8687b632006-10-19 23:28:48 -07003723 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 int status = 0;
3725
3726 *maxlink = 1;
3727 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3728 return -EIO;
3729 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003730 p = xdr_inline_decode(xdr, 4);
3731 if (unlikely(!p))
3732 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003733 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003736 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003738out_overflow:
3739 print_overflow_msg(__func__, xdr);
3740 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741}
3742
3743static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3744{
Al Viro8687b632006-10-19 23:28:48 -07003745 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 int status = 0;
3747
3748 *maxname = 1024;
3749 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3750 return -EIO;
3751 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003752 p = xdr_inline_decode(xdr, 4);
3753 if (unlikely(!p))
3754 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003755 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3757 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003758 dprintk("%s: maxname=%u\n", __func__, *maxname);
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_maxread(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_MAXREAD - 1U)))
3772 return -EIO;
3773 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3774 uint64_t maxread;
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, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 if (maxread > 0x7FFFFFFF)
3780 maxread = 0x7FFFFFFF;
3781 *res = (uint32_t)maxread;
3782 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3783 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003784 dprintk("%s: maxread=%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
3791static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3792{
Al Viro8687b632006-10-19 23:28:48 -07003793 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 int status = 0;
3795
3796 *res = 1024;
3797 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3798 return -EIO;
3799 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3800 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003801 p = xdr_inline_decode(xdr, 8);
3802 if (unlikely(!p))
3803 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003804 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 if (maxwrite > 0x7FFFFFFF)
3806 maxwrite = 0x7FFFFFFF;
3807 *res = (uint32_t)maxwrite;
3808 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3809 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003810 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003812out_overflow:
3813 print_overflow_msg(__func__, xdr);
3814 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815}
3816
Trond Myklebustbca79472009-03-11 14:10:26 -04003817static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818{
Trond Myklebustbca79472009-03-11 14:10:26 -04003819 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003820 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003821 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822
3823 *mode = 0;
3824 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3825 return -EIO;
3826 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003827 p = xdr_inline_decode(xdr, 4);
3828 if (unlikely(!p))
3829 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003830 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003831 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003833 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003835 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003836 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003837out_overflow:
3838 print_overflow_msg(__func__, xdr);
3839 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840}
3841
3842static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3843{
Al Viro8687b632006-10-19 23:28:48 -07003844 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003845 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
3847 *nlink = 1;
3848 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3849 return -EIO;
3850 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
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 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003856 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003858 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003859 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003860out_overflow:
3861 print_overflow_msg(__func__, xdr);
3862 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863}
3864
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003865static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003866 const struct nfs_server *server, uint32_t *uid,
3867 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868{
Al Viro8687b632006-10-19 23:28:48 -07003869 uint32_t len;
3870 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003871 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872
3873 *uid = -2;
3874 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3875 return -EIO;
3876 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003877 p = xdr_inline_decode(xdr, 4);
3878 if (unlikely(!p))
3879 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003880 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003881 p = xdr_inline_decode(xdr, len);
3882 if (unlikely(!p))
3883 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003884 if (owner_name != NULL) {
3885 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3886 if (owner_name->data != NULL) {
3887 owner_name->len = len;
3888 ret = NFS_ATTR_FATTR_OWNER_NAME;
3889 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003890 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003891 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003892 ret = NFS_ATTR_FATTR_OWNER;
3893 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003895 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003897 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003898 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3900 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003901 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003902 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003903out_overflow:
3904 print_overflow_msg(__func__, xdr);
3905 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906}
3907
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003908static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003909 const struct nfs_server *server, uint32_t *gid,
3910 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911{
Al Viro8687b632006-10-19 23:28:48 -07003912 uint32_t len;
3913 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003914 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915
3916 *gid = -2;
3917 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3918 return -EIO;
3919 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003920 p = xdr_inline_decode(xdr, 4);
3921 if (unlikely(!p))
3922 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003923 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003924 p = xdr_inline_decode(xdr, len);
3925 if (unlikely(!p))
3926 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003927 if (group_name != NULL) {
3928 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3929 if (group_name->data != NULL) {
3930 group_name->len = len;
3931 ret = NFS_ATTR_FATTR_GROUP_NAME;
3932 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003933 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003934 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 ret = NFS_ATTR_FATTR_GROUP;
3936 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003938 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003940 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003941 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3943 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003944 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003945 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003946out_overflow:
3947 print_overflow_msg(__func__, xdr);
3948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3952{
Al Viro8687b632006-10-19 23:28:48 -07003953 uint32_t major = 0, minor = 0;
3954 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003955 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956
3957 *rdev = MKDEV(0,0);
3958 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3959 return -EIO;
3960 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3961 dev_t tmp;
3962
Benny Halevyc0eae662009-08-14 17:20:14 +03003963 p = xdr_inline_decode(xdr, 8);
3964 if (unlikely(!p))
3965 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003966 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003967 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 tmp = MKDEV(major, minor);
3969 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3970 *rdev = tmp;
3971 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003972 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003974 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003975 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003976out_overflow:
3977 print_overflow_msg(__func__, xdr);
3978 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979}
3980
3981static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3982{
Al Viro8687b632006-10-19 23:28:48 -07003983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 int status = 0;
3985
3986 *res = 0;
3987 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3988 return -EIO;
3989 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003990 p = xdr_inline_decode(xdr, 8);
3991 if (unlikely(!p))
3992 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003993 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3995 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003996 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003998out_overflow:
3999 print_overflow_msg(__func__, xdr);
4000 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001}
4002
4003static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4004{
Al Viro8687b632006-10-19 23:28:48 -07004005 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 int status = 0;
4007
4008 *res = 0;
4009 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4010 return -EIO;
4011 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004012 p = xdr_inline_decode(xdr, 8);
4013 if (unlikely(!p))
4014 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004015 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4017 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004018 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004020out_overflow:
4021 print_overflow_msg(__func__, xdr);
4022 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023}
4024
4025static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4026{
Al Viro8687b632006-10-19 23:28:48 -07004027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 int status = 0;
4029
4030 *res = 0;
4031 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4032 return -EIO;
4033 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004034 p = xdr_inline_decode(xdr, 8);
4035 if (unlikely(!p))
4036 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004037 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4039 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004040 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004042out_overflow:
4043 print_overflow_msg(__func__, xdr);
4044 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045}
4046
4047static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4048{
Al Viro8687b632006-10-19 23:28:48 -07004049 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004050 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051
4052 *used = 0;
4053 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4054 return -EIO;
4055 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004056 p = xdr_inline_decode(xdr, 8);
4057 if (unlikely(!p))
4058 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004059 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004061 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004063 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004065 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004066out_overflow:
4067 print_overflow_msg(__func__, xdr);
4068 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069}
4070
4071static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4072{
Al Viro8687b632006-10-19 23:28:48 -07004073 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 uint64_t sec;
4075 uint32_t nsec;
4076
Benny Halevyc0eae662009-08-14 17:20:14 +03004077 p = xdr_inline_decode(xdr, 12);
4078 if (unlikely(!p))
4079 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004080 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004081 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 time->tv_sec = (time_t)sec;
4083 time->tv_nsec = (long)nsec;
4084 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004085out_overflow:
4086 print_overflow_msg(__func__, xdr);
4087 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088}
4089
4090static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4091{
4092 int status = 0;
4093
4094 time->tv_sec = 0;
4095 time->tv_nsec = 0;
4096 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4097 return -EIO;
4098 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4099 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004100 if (status == 0)
4101 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4103 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004104 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 return status;
4106}
4107
4108static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4109{
4110 int status = 0;
4111
4112 time->tv_sec = 0;
4113 time->tv_nsec = 0;
4114 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4115 return -EIO;
4116 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4117 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004118 if (status == 0)
4119 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4121 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004122 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 return status;
4124}
4125
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004126static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4127 struct timespec *time)
4128{
4129 int status = 0;
4130
4131 time->tv_sec = 0;
4132 time->tv_nsec = 0;
4133 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4134 return -EIO;
4135 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4136 status = decode_attr_time(xdr, time);
4137 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4138 }
4139 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4140 (long)time->tv_nsec);
4141 return status;
4142}
4143
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4145{
4146 int status = 0;
4147
4148 time->tv_sec = 0;
4149 time->tv_nsec = 0;
4150 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4151 return -EIO;
4152 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4153 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004154 if (status == 0)
4155 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4157 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004158 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 return status;
4160}
4161
Al Viro8687b632006-10-19 23:28:48 -07004162static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163{
4164 unsigned int attrwords = XDR_QUADLEN(attrlen);
4165 unsigned int nwords = xdr->p - savep;
4166
4167 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004168 dprintk("%s: server returned incorrect attribute length: "
4169 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004170 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 attrwords << 2,
4172 (attrwords < nwords) ? '<' : '>',
4173 nwords << 2);
4174 return -EIO;
4175 }
4176 return 0;
4177}
4178
4179static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4180{
Al Viro8687b632006-10-19 23:28:48 -07004181 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182
Benny Halevyc0eae662009-08-14 17:20:14 +03004183 p = xdr_inline_decode(xdr, 20);
4184 if (unlikely(!p))
4185 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004186 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004187 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004188 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004190out_overflow:
4191 print_overflow_msg(__func__, xdr);
4192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193}
4194
4195static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4196{
Al Viro8687b632006-10-19 23:28:48 -07004197 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 uint32_t supp, acc;
4199 int status;
4200
4201 status = decode_op_hdr(xdr, OP_ACCESS);
4202 if (status)
4203 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004204 p = xdr_inline_decode(xdr, 8);
4205 if (unlikely(!p))
4206 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004207 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004208 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 access->supported = supp;
4210 access->access = acc;
4211 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004212out_overflow:
4213 print_overflow_msg(__func__, xdr);
4214 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215}
4216
Benny Halevy07d30432009-08-14 17:19:52 +03004217static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218{
Al Viro8687b632006-10-19 23:28:48 -07004219 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004220
4221 p = xdr_inline_decode(xdr, len);
4222 if (likely(p)) {
4223 memcpy(buf, p, len);
4224 return 0;
4225 }
4226 print_overflow_msg(__func__, xdr);
4227 return -EIO;
4228}
4229
4230static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4231{
4232 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233}
4234
4235static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 int status;
4238
4239 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004240 if (status != -EIO)
4241 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004242 if (!status)
4243 status = decode_stateid(xdr, &res->stateid);
4244 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245}
4246
Benny Halevydb942bb2009-08-14 17:19:56 +03004247static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4248{
4249 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250}
4251
4252static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 int status;
4255
4256 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004257 if (!status)
4258 status = decode_verifier(xdr, res->verf->verifier);
4259 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260}
4261
4262static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4263{
Al Viro8687b632006-10-19 23:28:48 -07004264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 uint32_t bmlen;
4266 int status;
4267
4268 status = decode_op_hdr(xdr, OP_CREATE);
4269 if (status)
4270 return status;
4271 if ((status = decode_change_info(xdr, cinfo)))
4272 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004273 p = xdr_inline_decode(xdr, 4);
4274 if (unlikely(!p))
4275 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004276 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004277 p = xdr_inline_decode(xdr, bmlen << 2);
4278 if (likely(p))
4279 return 0;
4280out_overflow:
4281 print_overflow_msg(__func__, xdr);
4282 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283}
4284
4285static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
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;
4290
4291 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 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4298 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004299 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4300 &res->fh_expire_type)) != 0)
4301 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4303 goto xdr_error;
4304 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4305 goto xdr_error;
4306 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4307 goto xdr_error;
4308 status = verify_attr_len(xdr, savep, attrlen);
4309xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004310 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 return status;
4312}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004313
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4315{
Al Viro8687b632006-10-19 23:28:48 -07004316 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004317 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004319
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4325 goto xdr_error;
4326
4327 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4328 goto xdr_error;
4329 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4330 goto xdr_error;
4331 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4334 goto xdr_error;
4335 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4338 goto xdr_error;
4339
4340 status = verify_attr_len(xdr, savep, attrlen);
4341xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004342 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 return status;
4344}
4345
4346static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4347{
Al Viro8687b632006-10-19 23:28:48 -07004348 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004349 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004351
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4357 goto xdr_error;
4358
4359 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4360 goto xdr_error;
4361 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4362 goto xdr_error;
4363
4364 status = verify_attr_len(xdr, savep, attrlen);
4365xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004366 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 return status;
4368}
4369
Bryan Schumakerae42c702010-10-21 16:33:17 -04004370static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4371 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004372 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004373 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374{
Trond Myklebustbca79472009-03-11 14:10:26 -04004375 int status;
4376 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004377 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004378 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004380 status = decode_attr_type(xdr, bitmap, &type);
4381 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004383 fattr->mode = 0;
4384 if (status != 0) {
4385 fattr->mode |= nfs_type2fmt[type];
4386 fattr->valid |= status;
4387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004389 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4390 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004392 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004393
4394 status = decode_attr_size(xdr, bitmap, &fattr->size);
4395 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004397 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004398
4399 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4400 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004402 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004403
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004404 err = 0;
4405 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004406 if (status < 0)
4407 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004408 if (err == -NFS4ERR_WRONGSEC)
4409 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004410
4411 status = decode_attr_filehandle(xdr, bitmap, fh);
4412 if (status < 0)
4413 goto xdr_error;
4414
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004415 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4416 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004418 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004419
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004420 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004421 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004422 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004423 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004424
4425 status = decode_attr_mode(xdr, bitmap, &fmode);
4426 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004428 if (status != 0) {
4429 fattr->mode |= fmode;
4430 fattr->valid |= status;
4431 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004432
4433 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4434 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004436 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004437
Trond Myklebust6926afd2012-01-07 13:22:46 -05004438 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004439 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004441 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004442
Trond Myklebust6926afd2012-01-07 13:22:46 -05004443 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004444 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004446 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447
4448 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4449 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004451 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004452
4453 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4454 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004456 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004457
4458 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4459 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004461 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004462
4463 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4464 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004466 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004467
4468 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4469 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004471 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004472
Trond Myklebust28331a42011-04-27 13:47:52 -04004473 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004474 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004475 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004476 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004477
Bryan Schumakerae42c702010-10-21 16:33:17 -04004478xdr_error:
4479 dprintk("%s: xdr returned %d\n", __func__, -status);
4480 return status;
4481}
4482
4483static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004484 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4485 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004486{
4487 __be32 *savep;
4488 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004489 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004490 int status;
4491
4492 status = decode_op_hdr(xdr, OP_GETATTR);
4493 if (status < 0)
4494 goto xdr_error;
4495
4496 status = decode_attr_bitmap(xdr, bitmap);
4497 if (status < 0)
4498 goto xdr_error;
4499
4500 status = decode_attr_length(xdr, &attrlen, &savep);
4501 if (status < 0)
4502 goto xdr_error;
4503
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004504 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004505 if (status < 0)
4506 goto xdr_error;
4507
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004508 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004510 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 return status;
4512}
4513
Bryan Schumakerae42c702010-10-21 16:33:17 -04004514static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004515 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004516{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004517 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004518}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519
Andy Adamson504913f2010-10-20 00:17:57 -04004520/*
4521 * Decode potentially multiple layout types. Currently we only support
4522 * one layout driver per file system.
4523 */
4524static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4525 uint32_t *layouttype)
4526{
4527 uint32_t *p;
4528 int num;
4529
4530 p = xdr_inline_decode(xdr, 4);
4531 if (unlikely(!p))
4532 goto out_overflow;
4533 num = be32_to_cpup(p);
4534
4535 /* pNFS is not supported by the underlying file system */
4536 if (num == 0) {
4537 *layouttype = 0;
4538 return 0;
4539 }
4540 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004541 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4542 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004543
4544 /* Decode and set first layout type, move xdr->p past unused types */
4545 p = xdr_inline_decode(xdr, num * 4);
4546 if (unlikely(!p))
4547 goto out_overflow;
4548 *layouttype = be32_to_cpup(p);
4549 return 0;
4550out_overflow:
4551 print_overflow_msg(__func__, xdr);
4552 return -EIO;
4553}
4554
4555/*
4556 * The type of file system exported.
4557 * Note we must ensure that layouttype is set in any non-error case.
4558 */
4559static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4560 uint32_t *layouttype)
4561{
4562 int status = 0;
4563
4564 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4565 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4566 return -EIO;
4567 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4568 status = decode_first_pnfs_layout_type(xdr, layouttype);
4569 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4570 } else
4571 *layouttype = 0;
4572 return status;
4573}
4574
Fred Isamandae100c2011-07-30 20:52:37 -04004575/*
4576 * The prefered block size for layout directed io
4577 */
4578static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4579 uint32_t *res)
4580{
4581 __be32 *p;
4582
4583 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4584 *res = 0;
4585 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4586 p = xdr_inline_decode(xdr, 4);
4587 if (unlikely(!p)) {
4588 print_overflow_msg(__func__, xdr);
4589 return -EIO;
4590 }
4591 *res = be32_to_cpup(p);
4592 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4593 }
4594 return 0;
4595}
4596
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4598{
Al Viro8687b632006-10-19 23:28:48 -07004599 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004600 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 int status;
4602
4603 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4604 goto xdr_error;
4605 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4606 goto xdr_error;
4607 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4608 goto xdr_error;
4609
4610 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4611
4612 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4613 goto xdr_error;
4614 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4615 goto xdr_error;
4616 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4617 goto xdr_error;
4618 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4619 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4620 goto xdr_error;
4621 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004622 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4623 if (status != 0)
4624 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004625 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4626 if (status != 0)
4627 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004628 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4629 if (status)
4630 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631
4632 status = verify_attr_len(xdr, savep, attrlen);
4633xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004634 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 return status;
4636}
4637
4638static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4639{
Al Viro8687b632006-10-19 23:28:48 -07004640 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 uint32_t len;
4642 int status;
4643
Trond Myklebust99367812007-07-17 21:52:41 -04004644 /* Zero handle first to allow comparisons */
4645 memset(fh, 0, sizeof(*fh));
4646
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 status = decode_op_hdr(xdr, OP_GETFH);
4648 if (status)
4649 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650
Benny Halevyc0eae662009-08-14 17:20:14 +03004651 p = xdr_inline_decode(xdr, 4);
4652 if (unlikely(!p))
4653 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004654 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 if (len > NFS4_FHSIZE)
4656 return -EIO;
4657 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004658 p = xdr_inline_decode(xdr, len);
4659 if (unlikely(!p))
4660 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004661 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004663out_overflow:
4664 print_overflow_msg(__func__, xdr);
4665 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666}
4667
4668static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4669{
4670 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004671
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 status = decode_op_hdr(xdr, OP_LINK);
4673 if (status)
4674 return status;
4675 return decode_change_info(xdr, cinfo);
4676}
4677
4678/*
4679 * We create the owner, so we know a proper owner.id length is 4.
4680 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004681static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004683 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004684 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004685 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004687 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004688 if (unlikely(!p))
4689 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004690 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004691 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004692 type = be32_to_cpup(p++); /* 4 byte read */
4693 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004694 fl->fl_start = (loff_t)offset;
4695 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4696 if (length == ~(uint64_t)0)
4697 fl->fl_end = OFFSET_MAX;
4698 fl->fl_type = F_WRLCK;
4699 if (type & 1)
4700 fl->fl_type = F_RDLCK;
4701 fl->fl_pid = 0;
4702 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004703 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4704 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4705 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004706 if (likely(p))
4707 return -NFS4ERR_DENIED;
4708out_overflow:
4709 print_overflow_msg(__func__, xdr);
4710 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711}
4712
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004713static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_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_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004718 if (status == -EIO)
4719 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004721 status = decode_stateid(xdr, &res->stateid);
4722 if (unlikely(status))
4723 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004725 status = decode_lock_denied(xdr, NULL);
4726 if (res->open_seqid != NULL)
4727 nfs_increment_open_seqid(status, res->open_seqid);
4728 nfs_increment_lock_seqid(status, res->lock_seqid);
4729out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 return status;
4731}
4732
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004733static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734{
4735 int status;
4736 status = decode_op_hdr(xdr, OP_LOCKT);
4737 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004738 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 return status;
4740}
4741
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004742static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 int status;
4745
4746 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004747 if (status != -EIO)
4748 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004749 if (status == 0)
4750 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 return status;
4752}
4753
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004754static int decode_release_lockowner(struct xdr_stream *xdr)
4755{
4756 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4757}
4758
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759static int decode_lookup(struct xdr_stream *xdr)
4760{
4761 return decode_op_hdr(xdr, OP_LOOKUP);
4762}
4763
4764/* This is too sick! */
4765static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4766{
Andy Adamson05d564f2008-12-23 16:06:15 -05004767 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 uint32_t limit_type, nblocks, blocksize;
4769
Benny Halevyc0eae662009-08-14 17:20:14 +03004770 p = xdr_inline_decode(xdr, 12);
4771 if (unlikely(!p))
4772 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004773 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004775 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004776 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004777 break;
4778 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004779 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004780 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004781 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 }
4783 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004784out_overflow:
4785 print_overflow_msg(__func__, xdr);
4786 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787}
4788
4789static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4790{
Andy Adamson05d564f2008-12-23 16:06:15 -05004791 __be32 *p;
4792 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004793 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794
Benny Halevyc0eae662009-08-14 17:20:14 +03004795 p = xdr_inline_decode(xdr, 4);
4796 if (unlikely(!p))
4797 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004798 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4800 res->delegation_type = 0;
4801 return 0;
4802 }
Benny Halevy07d30432009-08-14 17:19:52 +03004803 status = decode_stateid(xdr, &res->delegation);
4804 if (unlikely(status))
4805 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004806 p = xdr_inline_decode(xdr, 4);
4807 if (unlikely(!p))
4808 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004809 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004810
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004812 case NFS4_OPEN_DELEGATE_READ:
4813 res->delegation_type = FMODE_READ;
4814 break;
4815 case NFS4_OPEN_DELEGATE_WRITE:
4816 res->delegation_type = FMODE_WRITE|FMODE_READ;
4817 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 return -EIO;
4819 }
David Howells7539bba2006-08-22 20:06:09 -04004820 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004821out_overflow:
4822 print_overflow_msg(__func__, xdr);
4823 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824}
4825
4826static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4827{
Andy Adamson05d564f2008-12-23 16:06:15 -05004828 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004829 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004830 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831
Andy Adamson05d564f2008-12-23 16:06:15 -05004832 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004833 if (status != -EIO)
4834 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004835 if (!status)
4836 status = decode_stateid(xdr, &res->stateid);
4837 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004838 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839
Andy Adamson05d564f2008-12-23 16:06:15 -05004840 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Benny Halevyc0eae662009-08-14 17:20:14 +03004842 p = xdr_inline_decode(xdr, 8);
4843 if (unlikely(!p))
4844 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004845 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004846 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004847 if (bmlen > 10)
4848 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849
Benny Halevyc0eae662009-08-14 17:20:14 +03004850 p = xdr_inline_decode(xdr, bmlen << 2);
4851 if (unlikely(!p))
4852 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004853 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4854 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004855 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004856 for (; i < NFS4_BITMAP_SIZE; i++)
4857 res->attrset[i] = 0;
4858
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 return decode_delegation(xdr, res);
4860xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004861 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004863out_overflow:
4864 print_overflow_msg(__func__, xdr);
4865 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866}
4867
4868static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4869{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 int status;
4871
Andy Adamson05d564f2008-12-23 16:06:15 -05004872 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004873 if (status != -EIO)
4874 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004875 if (!status)
4876 status = decode_stateid(xdr, &res->stateid);
4877 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878}
4879
4880static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4881{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 int status;
4883
4884 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004885 if (status != -EIO)
4886 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004887 if (!status)
4888 status = decode_stateid(xdr, &res->stateid);
4889 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890}
4891
4892static int decode_putfh(struct xdr_stream *xdr)
4893{
4894 return decode_op_hdr(xdr, OP_PUTFH);
4895}
4896
4897static int decode_putrootfh(struct xdr_stream *xdr)
4898{
4899 return decode_op_hdr(xdr, OP_PUTROOTFH);
4900}
4901
4902static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4903{
4904 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 uint32_t count, eof, recvd, hdrlen;
4907 int status;
4908
4909 status = decode_op_hdr(xdr, OP_READ);
4910 if (status)
4911 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004912 p = xdr_inline_decode(xdr, 8);
4913 if (unlikely(!p))
4914 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004915 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004916 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004917 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 recvd = req->rq_rcv_buf.len - hdrlen;
4919 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004920 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 "count %u > recvd %u\n", count, recvd);
4922 count = recvd;
4923 eof = 0;
4924 }
4925 xdr_read_pages(xdr, count);
4926 res->eof = eof;
4927 res->count = count;
4928 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004929out_overflow:
4930 print_overflow_msg(__func__, xdr);
4931 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932}
4933
4934static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4935{
4936 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004938 size_t hdrlen;
4939 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004940 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941
4942 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004943 if (!status)
4944 status = decode_verifier(xdr, readdir->verifier.data);
4945 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004947 dprintk("%s: verifier = %08x:%08x\n",
4948 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004949 ((u32 *)readdir->verifier.data)[0],
4950 ((u32 *)readdir->verifier.data)[1]);
4951
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952
Benny Halevydb942bb2009-08-14 17:19:56 +03004953 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 recvd = rcvbuf->len - hdrlen;
4955 if (pglen > recvd)
4956 pglen = recvd;
4957 xdr_read_pages(xdr, pglen);
4958
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004959
Trond Myklebustac396122010-11-15 20:26:22 -05004960 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961}
4962
4963static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4964{
4965 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4966 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004967 size_t hdrlen;
4968 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 int status;
4971
4972 status = decode_op_hdr(xdr, OP_READLINK);
4973 if (status)
4974 return status;
4975
4976 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004977 p = xdr_inline_decode(xdr, 4);
4978 if (unlikely(!p))
4979 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004980 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004982 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 return -ENAMETOOLONG;
4984 }
4985 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4986 recvd = req->rq_rcv_buf.len - hdrlen;
4987 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004988 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 "count %u > recvd %u\n", len, recvd);
4990 return -EIO;
4991 }
4992 xdr_read_pages(xdr, len);
4993 /*
4994 * The XDR encode routine has set things up so that
4995 * the link text will be copied directly into the
4996 * buffer. We just have to do overflow-checking,
4997 * and and null-terminate the text (the VFS expects
4998 * null-termination).
4999 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005000 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005002out_overflow:
5003 print_overflow_msg(__func__, xdr);
5004 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005}
5006
5007static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5008{
5009 int status;
5010
5011 status = decode_op_hdr(xdr, OP_REMOVE);
5012 if (status)
5013 goto out;
5014 status = decode_change_info(xdr, cinfo);
5015out:
5016 return status;
5017}
5018
5019static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5020 struct nfs4_change_info *new_cinfo)
5021{
5022 int status;
5023
5024 status = decode_op_hdr(xdr, OP_RENAME);
5025 if (status)
5026 goto out;
5027 if ((status = decode_change_info(xdr, old_cinfo)))
5028 goto out;
5029 status = decode_change_info(xdr, new_cinfo);
5030out:
5031 return status;
5032}
5033
5034static int decode_renew(struct xdr_stream *xdr)
5035{
5036 return decode_op_hdr(xdr, OP_RENEW);
5037}
5038
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005039static int
5040decode_restorefh(struct xdr_stream *xdr)
5041{
5042 return decode_op_hdr(xdr, OP_RESTOREFH);
5043}
5044
J. Bruce Fields029d1052005-06-22 17:16:22 +00005045static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005046 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005047{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005048 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005049 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005050 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005051 struct kvec *iov = req->rq_rcv_buf.head;
5052 int status;
5053
Andy Adamsonbf118a32011-12-07 11:55:27 -05005054 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005055 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5056 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005057 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005058 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5059 goto out;
5060 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5061 goto out;
5062
5063 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5064 return -EIO;
5065 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005066 size_t hdrlen;
5067 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005068
Andy Adamsonbf118a32011-12-07 11:55:27 -05005069 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5070 * are stored with the acl data to handle the problem of
5071 * variable length bitmaps.*/
5072 xdr->p = bm_p;
5073 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5074 res->acl_data_offset <<= 2;
5075
J. Bruce Fields029d1052005-06-22 17:16:22 +00005076 /* We ignore &savep and don't do consistency checks on
5077 * the attr length. Let userspace figure it out.... */
5078 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005079 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005080 recvd = req->rq_rcv_buf.len - hdrlen;
5081 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005082 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5083 /* getxattr interface called with a NULL buf */
5084 res->acl_len = attrlen;
5085 goto out;
5086 }
5087 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005088 attrlen, recvd);
5089 return -EINVAL;
5090 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005091 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005092 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005093 } else
5094 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005095
5096out:
5097 return status;
5098}
5099
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100static int
5101decode_savefh(struct xdr_stream *xdr)
5102{
5103 return decode_op_hdr(xdr, OP_SAVEFH);
5104}
5105
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005106static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107{
Al Viro8687b632006-10-19 23:28:48 -07005108 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 uint32_t bmlen;
5110 int status;
5111
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 status = decode_op_hdr(xdr, OP_SETATTR);
5113 if (status)
5114 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005115 p = xdr_inline_decode(xdr, 4);
5116 if (unlikely(!p))
5117 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005118 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005119 p = xdr_inline_decode(xdr, bmlen << 2);
5120 if (likely(p))
5121 return 0;
5122out_overflow:
5123 print_overflow_msg(__func__, xdr);
5124 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125}
5126
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005127static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128{
Al Viro8687b632006-10-19 23:28:48 -07005129 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 uint32_t opnum;
5131 int32_t nfserr;
5132
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, 8);
5134 if (unlikely(!p))
5135 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005136 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005138 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005139 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 return -EIO;
5141 }
Benny Halevycccddf42009-08-14 17:20:19 +03005142 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005144 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5145 if (unlikely(!p))
5146 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005147 p = xdr_decode_hyper(p, &res->clientid);
5148 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 } else if (nfserr == NFSERR_CLID_INUSE) {
5150 uint32_t len;
5151
5152 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005153 p = xdr_inline_decode(xdr, 4);
5154 if (unlikely(!p))
5155 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005156 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005157 p = xdr_inline_decode(xdr, len);
5158 if (unlikely(!p))
5159 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160
5161 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005162 p = xdr_inline_decode(xdr, 4);
5163 if (unlikely(!p))
5164 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005165 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005166 p = xdr_inline_decode(xdr, len);
5167 if (unlikely(!p))
5168 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169 return -NFSERR_CLID_INUSE;
5170 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005171 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172
5173 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005174out_overflow:
5175 print_overflow_msg(__func__, xdr);
5176 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177}
5178
5179static int decode_setclientid_confirm(struct xdr_stream *xdr)
5180{
5181 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5182}
5183
5184static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5185{
Al Viro8687b632006-10-19 23:28:48 -07005186 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 int status;
5188
5189 status = decode_op_hdr(xdr, OP_WRITE);
5190 if (status)
5191 return status;
5192
Benny Halevyc0eae662009-08-14 17:20:14 +03005193 p = xdr_inline_decode(xdr, 16);
5194 if (unlikely(!p))
5195 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005196 res->count = be32_to_cpup(p++);
5197 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005198 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005200out_overflow:
5201 print_overflow_msg(__func__, xdr);
5202 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203}
5204
5205static int decode_delegreturn(struct xdr_stream *xdr)
5206{
5207 return decode_op_hdr(xdr, OP_DELEGRETURN);
5208}
5209
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005210static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5211{
5212 __be32 *p;
5213
5214 p = xdr_inline_decode(xdr, 4);
5215 if (unlikely(!p))
5216 goto out_overflow;
5217 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5218 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5219 goto out_err;
5220
5221 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5222 if (unlikely(!p))
5223 goto out_overflow;
5224 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5225
5226 p = xdr_inline_decode(xdr, 8);
5227 if (unlikely(!p))
5228 goto out_overflow;
5229 flavor->gss.qop4 = be32_to_cpup(p++);
5230 flavor->gss.service = be32_to_cpup(p);
5231
5232 return 0;
5233
5234out_overflow:
5235 print_overflow_msg(__func__, xdr);
5236 return -EIO;
5237out_err:
5238 return -EINVAL;
5239}
5240
5241static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5242{
5243 struct nfs4_secinfo_flavor *sec_flavor;
5244 int status;
5245 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005246 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005247
5248 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005249 if (status)
5250 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005251 p = xdr_inline_decode(xdr, 4);
5252 if (unlikely(!p))
5253 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005254
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005255 res->flavors->num_flavors = 0;
5256 num_flavors = be32_to_cpup(p);
5257
5258 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005259 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005260 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005261 break;
5262
5263 p = xdr_inline_decode(xdr, 4);
5264 if (unlikely(!p))
5265 goto out_overflow;
5266 sec_flavor->flavor = be32_to_cpup(p);
5267
5268 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005269 status = decode_secinfo_gss(xdr, sec_flavor);
5270 if (status)
5271 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005272 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005273 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005274 }
5275
Bryan Schumaker613e9012011-04-27 15:28:44 -04005276out:
5277 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005278out_overflow:
5279 print_overflow_msg(__func__, xdr);
5280 return -EIO;
5281}
5282
Benny Halevy99fe60d2009-04-01 09:22:29 -04005283#if defined(CONFIG_NFS_V4_1)
5284static int decode_exchange_id(struct xdr_stream *xdr,
5285 struct nfs41_exchange_id_res *res)
5286{
5287 __be32 *p;
5288 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005289 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005290 int status;
5291 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005292 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005293
5294 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5295 if (status)
5296 return status;
5297
Benny Halevyc0eae662009-08-14 17:20:14 +03005298 p = xdr_inline_decode(xdr, 8);
5299 if (unlikely(!p))
5300 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005301 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005302 p = xdr_inline_decode(xdr, 12);
5303 if (unlikely(!p))
5304 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005305 clp->cl_seqid = be32_to_cpup(p++);
5306 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005307
5308 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005309 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005310 if (dummy != SP4_NONE)
5311 return -EIO;
5312
5313 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005314 p = xdr_inline_decode(xdr, 8);
5315 if (unlikely(!p))
5316 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005317
5318 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005319 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5320 if (unlikely(status))
5321 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005322
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005323 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005324 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5325 if (unlikely(status))
5326 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005327
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005328 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5329 return -EIO;
5330
5331 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5332 res->server_scope->server_scope_sz = dummy;
5333
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005334 /* Implementation Id */
5335 p = xdr_inline_decode(xdr, 4);
5336 if (unlikely(!p))
5337 goto out_overflow;
5338 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005339
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005340 if (impl_id_count) {
5341 /* nii_domain */
5342 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5343 if (unlikely(status))
5344 return status;
5345 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5346 return -EIO;
5347 memcpy(res->impl_id->domain, dummy_str, dummy);
5348
5349 /* nii_name */
5350 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5351 if (unlikely(status))
5352 return status;
5353 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5354 return -EIO;
5355 memcpy(res->impl_id->name, dummy_str, dummy);
5356
5357 /* nii_date */
5358 p = xdr_inline_decode(xdr, 12);
5359 if (unlikely(!p))
5360 goto out_overflow;
5361 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5362 res->impl_id->date.nseconds = be32_to_cpup(p);
5363
5364 /* if there's more than one entry, ignore the rest */
5365 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005366 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005367out_overflow:
5368 print_overflow_msg(__func__, xdr);
5369 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005370}
Andy Adamsonfc931582009-04-01 09:22:31 -04005371
5372static int decode_chan_attrs(struct xdr_stream *xdr,
5373 struct nfs4_channel_attrs *attrs)
5374{
5375 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005376 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005377
Benny Halevyc0eae662009-08-14 17:20:14 +03005378 p = xdr_inline_decode(xdr, 28);
5379 if (unlikely(!p))
5380 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005381 val = be32_to_cpup(p++); /* headerpadsz */
5382 if (val)
5383 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005384 attrs->max_rqst_sz = be32_to_cpup(p++);
5385 attrs->max_resp_sz = be32_to_cpup(p++);
5386 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5387 attrs->max_ops = be32_to_cpup(p++);
5388 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005389 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005390 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005391 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5392 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005393 return -EINVAL;
5394 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005395 if (nr_attrs == 1) {
5396 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5397 if (unlikely(!p))
5398 goto out_overflow;
5399 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005400 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005401out_overflow:
5402 print_overflow_msg(__func__, xdr);
5403 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005404}
5405
Benny Halevye78291e2009-08-14 17:20:00 +03005406static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5407{
5408 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005409}
5410
5411static int decode_create_session(struct xdr_stream *xdr,
5412 struct nfs41_create_session_res *res)
5413{
5414 __be32 *p;
5415 int status;
5416 struct nfs_client *clp = res->client;
5417 struct nfs4_session *session = clp->cl_session;
5418
5419 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005420 if (!status)
5421 status = decode_sessionid(xdr, &session->sess_id);
5422 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005423 return status;
5424
Andy Adamsonfc931582009-04-01 09:22:31 -04005425 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005426 p = xdr_inline_decode(xdr, 8);
5427 if (unlikely(!p))
5428 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005429 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005430 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005431
5432 /* Channel attributes */
5433 status = decode_chan_attrs(xdr, &session->fc_attrs);
5434 if (!status)
5435 status = decode_chan_attrs(xdr, &session->bc_attrs);
5436 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005437out_overflow:
5438 print_overflow_msg(__func__, xdr);
5439 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005440}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005441
5442static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5443{
5444 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5445}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005446
5447static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5448{
5449 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5450}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005451#endif /* CONFIG_NFS_V4_1 */
5452
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005453static int decode_sequence(struct xdr_stream *xdr,
5454 struct nfs4_sequence_res *res,
5455 struct rpc_rqst *rqstp)
5456{
5457#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005458 struct nfs4_sessionid id;
5459 u32 dummy;
5460 int status;
5461 __be32 *p;
5462
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005463 if (!res->sr_session)
5464 return 0;
5465
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005466 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005467 if (!status)
5468 status = decode_sessionid(xdr, &id);
5469 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005470 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005471
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005472 /*
5473 * If the server returns different values for sessionID, slotID or
5474 * sequence number, the server is looney tunes.
5475 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005476 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005477
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005478 if (memcmp(id.data, res->sr_session->sess_id.data,
5479 NFS4_MAX_SESSIONID_LEN)) {
5480 dprintk("%s Invalid session id\n", __func__);
5481 goto out_err;
5482 }
Benny Halevye78291e2009-08-14 17:20:00 +03005483
Benny Halevyc0eae662009-08-14 17:20:14 +03005484 p = xdr_inline_decode(xdr, 20);
5485 if (unlikely(!p))
5486 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005487
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005488 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005489 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005490 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005491 dprintk("%s Invalid sequence number\n", __func__);
5492 goto out_err;
5493 }
5494 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005495 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005496 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005497 dprintk("%s Invalid slot id\n", __func__);
5498 goto out_err;
5499 }
5500 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005501 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005502 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005503 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005504 /* result flags */
5505 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005506 status = 0;
5507out_err:
5508 res->sr_status = status;
5509 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005510out_overflow:
5511 print_overflow_msg(__func__, xdr);
5512 status = -EIO;
5513 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005514#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005515 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005516#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005517}
5518
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005519#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005520/*
5521 * TODO: Need to handle case when EOF != true;
5522 */
5523static int decode_getdevicelist(struct xdr_stream *xdr,
5524 struct pnfs_devicelist *res)
5525{
5526 __be32 *p;
5527 int status, i;
5528 struct nfs_writeverf verftemp;
5529
5530 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5531 if (status)
5532 return status;
5533
5534 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5535 if (unlikely(!p))
5536 goto out_overflow;
5537
5538 /* TODO: Skip cookie for now */
5539 p += 2;
5540
5541 /* Read verifier */
5542 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5543
5544 res->num_devs = be32_to_cpup(p);
5545
5546 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5547
5548 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005549 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005550 __func__, res->num_devs);
5551 return -EIO;
5552 }
5553
5554 p = xdr_inline_decode(xdr,
5555 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5556 if (unlikely(!p))
5557 goto out_overflow;
5558 for (i = 0; i < res->num_devs; i++)
5559 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5560 NFS4_DEVICEID4_SIZE);
5561 res->eof = be32_to_cpup(p);
5562 return 0;
5563out_overflow:
5564 print_overflow_msg(__func__, xdr);
5565 return -EIO;
5566}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005567
5568static int decode_getdeviceinfo(struct xdr_stream *xdr,
5569 struct pnfs_device *pdev)
5570{
5571 __be32 *p;
5572 uint32_t len, type;
5573 int status;
5574
5575 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5576 if (status) {
5577 if (status == -ETOOSMALL) {
5578 p = xdr_inline_decode(xdr, 4);
5579 if (unlikely(!p))
5580 goto out_overflow;
5581 pdev->mincount = be32_to_cpup(p);
5582 dprintk("%s: Min count too small. mincnt = %u\n",
5583 __func__, pdev->mincount);
5584 }
5585 return status;
5586 }
5587
5588 p = xdr_inline_decode(xdr, 8);
5589 if (unlikely(!p))
5590 goto out_overflow;
5591 type = be32_to_cpup(p++);
5592 if (type != pdev->layout_type) {
5593 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5594 __func__, pdev->layout_type, type);
5595 return -EINVAL;
5596 }
5597 /*
5598 * Get the length of the opaque device_addr4. xdr_read_pages places
5599 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5600 * and places the remaining xdr data in xdr_buf->tail
5601 */
5602 pdev->mincount = be32_to_cpup(p);
5603 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5604
5605 /* Parse notification bitmap, verifying that it is zero. */
5606 p = xdr_inline_decode(xdr, 4);
5607 if (unlikely(!p))
5608 goto out_overflow;
5609 len = be32_to_cpup(p);
5610 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005611 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005612
5613 p = xdr_inline_decode(xdr, 4 * len);
5614 if (unlikely(!p))
5615 goto out_overflow;
5616 for (i = 0; i < len; i++, p++) {
5617 if (be32_to_cpup(p)) {
5618 dprintk("%s: notifications not supported\n",
5619 __func__);
5620 return -EIO;
5621 }
5622 }
5623 }
5624 return 0;
5625out_overflow:
5626 print_overflow_msg(__func__, xdr);
5627 return -EIO;
5628}
5629
5630static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5631 struct nfs4_layoutget_res *res)
5632{
5633 __be32 *p;
5634 int status;
5635 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005636 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5637 struct kvec *iov = rcvbuf->head;
5638 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005639
5640 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5641 if (status)
5642 return status;
5643 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5644 if (unlikely(!p))
5645 goto out_overflow;
5646 res->return_on_close = be32_to_cpup(p++);
5647 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5648 layout_count = be32_to_cpup(p);
5649 if (!layout_count) {
5650 dprintk("%s: server responded with empty layout array\n",
5651 __func__);
5652 return -EINVAL;
5653 }
5654
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005655 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005656 if (unlikely(!p))
5657 goto out_overflow;
5658 p = xdr_decode_hyper(p, &res->range.offset);
5659 p = xdr_decode_hyper(p, &res->range.length);
5660 res->range.iomode = be32_to_cpup(p++);
5661 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005662 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005663
5664 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5665 __func__,
5666 (unsigned long)res->range.offset,
5667 (unsigned long)res->range.length,
5668 res->range.iomode,
5669 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005670 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005671
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005672 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5673 recvd = req->rq_rcv_buf.len - hdrlen;
5674 if (res->layoutp->len > recvd) {
5675 dprintk("NFS: server cheating in layoutget reply: "
5676 "layout len %u > recvd %u\n",
5677 res->layoutp->len, recvd);
5678 return -EINVAL;
5679 }
5680
5681 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005682
5683 if (layout_count > 1) {
5684 /* We only handle a length one array at the moment. Any
5685 * further entries are just ignored. Note that this means
5686 * the client may see a response that is less than the
5687 * minimum it requested.
5688 */
5689 dprintk("%s: server responded with %d layouts, dropping tail\n",
5690 __func__, layout_count);
5691 }
5692
5693 return 0;
5694out_overflow:
5695 print_overflow_msg(__func__, xdr);
5696 return -EIO;
5697}
Andy Adamson863a3c62011-03-23 13:27:54 +00005698
Benny Halevycbe82602011-05-22 19:52:37 +03005699static int decode_layoutreturn(struct xdr_stream *xdr,
5700 struct nfs4_layoutreturn_res *res)
5701{
5702 __be32 *p;
5703 int status;
5704
5705 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5706 if (status)
5707 return status;
5708 p = xdr_inline_decode(xdr, 4);
5709 if (unlikely(!p))
5710 goto out_overflow;
5711 res->lrs_present = be32_to_cpup(p);
5712 if (res->lrs_present)
5713 status = decode_stateid(xdr, &res->stateid);
5714 return status;
5715out_overflow:
5716 print_overflow_msg(__func__, xdr);
5717 return -EIO;
5718}
5719
Andy Adamson863a3c62011-03-23 13:27:54 +00005720static int decode_layoutcommit(struct xdr_stream *xdr,
5721 struct rpc_rqst *req,
5722 struct nfs4_layoutcommit_res *res)
5723{
5724 __be32 *p;
5725 __u32 sizechanged;
5726 int status;
5727
5728 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005729 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005730 if (status)
5731 return status;
5732
5733 p = xdr_inline_decode(xdr, 4);
5734 if (unlikely(!p))
5735 goto out_overflow;
5736 sizechanged = be32_to_cpup(p);
5737
5738 if (sizechanged) {
5739 /* throw away new size */
5740 p = xdr_inline_decode(xdr, 8);
5741 if (unlikely(!p))
5742 goto out_overflow;
5743 }
5744 return 0;
5745out_overflow:
5746 print_overflow_msg(__func__, xdr);
5747 return -EIO;
5748}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005749
5750static int decode_test_stateid(struct xdr_stream *xdr,
5751 struct nfs41_test_stateid_res *res)
5752{
5753 __be32 *p;
5754 int status;
5755 int num_res;
5756
5757 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5758 if (status)
5759 return status;
5760
5761 p = xdr_inline_decode(xdr, 4);
5762 if (unlikely(!p))
5763 goto out_overflow;
5764 num_res = be32_to_cpup(p++);
5765 if (num_res != 1)
5766 goto out;
5767
5768 p = xdr_inline_decode(xdr, 4);
5769 if (unlikely(!p))
5770 goto out_overflow;
5771 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005772
5773 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005774out_overflow:
5775 print_overflow_msg(__func__, xdr);
5776out:
5777 return -EIO;
5778}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005779
5780static int decode_free_stateid(struct xdr_stream *xdr,
5781 struct nfs41_free_stateid_res *res)
5782{
5783 __be32 *p;
5784 int status;
5785
5786 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5787 if (status)
5788 return status;
5789
5790 p = xdr_inline_decode(xdr, 4);
5791 if (unlikely(!p))
5792 goto out_overflow;
5793 res->status = be32_to_cpup(p++);
5794 return res->status;
5795out_overflow:
5796 print_overflow_msg(__func__, xdr);
5797 return -EIO;
5798}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005799#endif /* CONFIG_NFS_V4_1 */
5800
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801/*
Benny Halevy49c25592008-12-23 16:06:16 -05005802 * END OF "GENERIC" DECODE ROUTINES.
5803 */
5804
5805/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806 * Decode OPEN_DOWNGRADE response
5807 */
Chuck Leverbf269552010-12-14 14:59:29 +00005808static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5809 struct xdr_stream *xdr,
5810 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811{
Andy Adamson05d564f2008-12-23 16:06:15 -05005812 struct compound_hdr hdr;
5813 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814
Chuck Leverbf269552010-12-14 14:59:29 +00005815 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005816 if (status)
5817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005819 if (status)
5820 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005821 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005822 if (status)
5823 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005825 if (status != 0)
5826 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005827 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005829 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830}
5831
5832/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 * Decode ACCESS response
5834 */
Chuck Leverbf269552010-12-14 14:59:29 +00005835static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5836 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838 struct compound_hdr hdr;
5839 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005840
Chuck Leverbf269552010-12-14 14:59:29 +00005841 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005842 if (status)
5843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005844 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005845 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005848 if (status != 0)
5849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005851 if (status != 0)
5852 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005853 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854out:
5855 return status;
5856}
5857
5858/*
5859 * Decode LOOKUP response
5860 */
Chuck Leverbf269552010-12-14 14:59:29 +00005861static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5862 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 struct compound_hdr hdr;
5865 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005866
Chuck Leverbf269552010-12-14 14:59:29 +00005867 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005868 if (status)
5869 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005871 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005873 status = decode_putfh(xdr);
5874 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_lookup(xdr);
5877 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_getfh(xdr, res->fh);
5880 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005882 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883out:
5884 return status;
5885}
5886
5887/*
5888 * Decode LOOKUP_ROOT response
5889 */
Chuck Leverbf269552010-12-14 14:59:29 +00005890static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5891 struct xdr_stream *xdr,
5892 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 struct compound_hdr hdr;
5895 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005896
Chuck Leverbf269552010-12-14 14:59:29 +00005897 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005898 if (status)
5899 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005900 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005901 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005903 status = decode_putrootfh(xdr);
5904 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005906 status = decode_getfh(xdr, res->fh);
5907 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005908 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909out:
5910 return status;
5911}
5912
5913/*
5914 * Decode REMOVE response
5915 */
Chuck Leverbf269552010-12-14 14:59:29 +00005916static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5917 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 struct compound_hdr hdr;
5920 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005921
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005923 if (status)
5924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005926 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_putfh(xdr);
5929 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005930 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005931 status = decode_remove(xdr, &res->cinfo);
5932 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005933 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005934 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935out:
5936 return status;
5937}
5938
5939/*
5940 * Decode RENAME response
5941 */
Chuck Leverbf269552010-12-14 14:59:29 +00005942static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5943 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005944{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945 struct compound_hdr hdr;
5946 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005947
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005949 if (status)
5950 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005952 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_putfh(xdr);
5955 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_savefh(xdr);
5958 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_putfh(xdr);
5961 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5964 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005965 goto out;
5966 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005967 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_restorefh(xdr);
5970 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005971 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005972 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973out:
5974 return status;
5975}
5976
5977/*
5978 * Decode LINK response
5979 */
Chuck Leverbf269552010-12-14 14:59:29 +00005980static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5981 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983 struct compound_hdr hdr;
5984 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005985
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005987 if (status)
5988 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005990 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_putfh(xdr);
5993 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_savefh(xdr);
5996 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005998 status = decode_putfh(xdr);
5999 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_link(xdr, &res->cinfo);
6002 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006003 goto out;
6004 /*
6005 * Note order: OP_LINK leaves the directory as the current
6006 * filehandle.
6007 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006008 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006009 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_restorefh(xdr);
6011 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006012 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006013 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014out:
6015 return status;
6016}
6017
6018/*
6019 * Decode CREATE response
6020 */
Chuck Leverbf269552010-12-14 14:59:29 +00006021static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6022 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 struct compound_hdr hdr;
6025 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006026
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006028 if (status)
6029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006031 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_putfh(xdr);
6034 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006036 status = decode_savefh(xdr);
6037 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_create(xdr, &res->dir_cinfo);
6040 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_getfh(xdr, res->fh);
6043 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006045 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006046 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_restorefh(xdr);
6048 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006049 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006050 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051out:
6052 return status;
6053}
6054
6055/*
6056 * Decode SYMLINK response
6057 */
Chuck Leverbf269552010-12-14 14:59:29 +00006058static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6059 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060{
Chuck Leverbf269552010-12-14 14:59:29 +00006061 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062}
6063
6064/*
6065 * Decode GETATTR response
6066 */
Chuck Leverbf269552010-12-14 14:59:29 +00006067static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6068 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 struct compound_hdr hdr;
6071 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006072
Chuck Leverbf269552010-12-14 14:59:29 +00006073 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074 if (status)
6075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006076 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006077 if (status)
6078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080 if (status)
6081 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006082 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083out:
6084 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085}
6086
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006087/*
6088 * Encode an SETACL request
6089 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006090static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6091 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006092{
Andy Adamson05d564f2008-12-23 16:06:15 -05006093 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006094 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006095 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006096
Chuck Lever9f06c712010-12-14 14:59:18 +00006097 encode_compound_hdr(xdr, req, &hdr);
6098 encode_sequence(xdr, &args->seq_args, &hdr);
6099 encode_putfh(xdr, args->fh, &hdr);
6100 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006101 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006102}
Andy Adamson05d564f2008-12-23 16:06:15 -05006103
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006104/*
6105 * Decode SETACL response
6106 */
6107static int
Chuck Leverbf269552010-12-14 14:59:29 +00006108nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006109 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006110{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006111 struct compound_hdr hdr;
6112 int status;
6113
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006115 if (status)
6116 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006118 if (status)
6119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006121 if (status)
6122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006124out:
6125 return status;
6126}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127
6128/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006129 * Decode GETACL response
6130 */
6131static int
Chuck Leverbf269552010-12-14 14:59:29 +00006132nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006133 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006134{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006135 struct compound_hdr hdr;
6136 int status;
6137
Trond Myklebust331818f2012-02-03 18:30:53 -05006138 if (res->acl_scratch != NULL) {
6139 void *p = page_address(res->acl_scratch);
6140 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6141 }
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006143 if (status)
6144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006146 if (status)
6147 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006148 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006149 if (status)
6150 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006151 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006152
6153out:
6154 return status;
6155}
6156
6157/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 * Decode CLOSE response
6159 */
Chuck Leverbf269552010-12-14 14:59:29 +00006160static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6161 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162{
Andy Adamson05d564f2008-12-23 16:06:15 -05006163 struct compound_hdr hdr;
6164 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006173 if (status)
6174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006176 if (status != 0)
6177 goto out;
6178 /*
6179 * Note: Server may do delete on close for this file
6180 * in which case the getattr call will fail with
6181 * an ESTALE error. Shouldn't be a problem,
6182 * though, since fattr->valid will remain unset.
6183 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006184 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006186 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187}
6188
6189/*
6190 * Decode OPEN response
6191 */
Chuck Leverbf269552010-12-14 14:59:29 +00006192static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6193 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194{
Andy Adamson05d564f2008-12-23 16:06:15 -05006195 struct compound_hdr hdr;
6196 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006202 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_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006211 if (status)
6212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006215 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006218 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006219 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006221 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222}
6223
6224/*
6225 * Decode OPEN_CONFIRM response
6226 */
Chuck Leverbf269552010-12-14 14:59:29 +00006227static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6228 struct xdr_stream *xdr,
6229 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230{
Andy Adamson05d564f2008-12-23 16:06:15 -05006231 struct compound_hdr hdr;
6232 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006235 if (status)
6236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006238 if (status)
6239 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006242 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243}
6244
6245/*
6246 * Decode OPEN response
6247 */
Chuck Leverbf269552010-12-14 14:59:29 +00006248static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6249 struct xdr_stream *xdr,
6250 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251{
Andy Adamson05d564f2008-12-23 16:06:15 -05006252 struct compound_hdr hdr;
6253 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006259 if (status)
6260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006262 if (status)
6263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006265 if (status)
6266 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006267 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006269 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270}
6271
6272/*
6273 * Decode SETATTR response
6274 */
Chuck Leverbf269552010-12-14 14:59:29 +00006275static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6276 struct xdr_stream *xdr,
6277 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278{
Andy Adamson05d564f2008-12-23 16:06:15 -05006279 struct compound_hdr hdr;
6280 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006283 if (status)
6284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006286 if (status)
6287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006289 if (status)
6290 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006292 if (status)
6293 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006294 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006296 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297}
6298
6299/*
6300 * Decode LOCK response
6301 */
Chuck Leverbf269552010-12-14 14:59:29 +00006302static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6303 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 struct compound_hdr hdr;
6306 int status;
6307
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 if (status)
6310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006312 if (status)
6313 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315 if (status)
6316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318out:
6319 return status;
6320}
6321
6322/*
6323 * Decode LOCKT response
6324 */
Chuck Leverbf269552010-12-14 14:59:29 +00006325static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6326 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 struct compound_hdr hdr;
6329 int status;
6330
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006335 if (status)
6336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 if (status)
6339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341out:
6342 return status;
6343}
6344
6345/*
6346 * Decode LOCKU response
6347 */
Chuck Leverbf269552010-12-14 14:59:29 +00006348static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6349 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 struct compound_hdr hdr;
6352 int status;
6353
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 if (status)
6356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006358 if (status)
6359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 if (status)
6362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364out:
6365 return status;
6366}
6367
Chuck Leverbf269552010-12-14 14:59:29 +00006368static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6369 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006370{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006371 struct compound_hdr hdr;
6372 int status;
6373
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006375 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006377 return status;
6378}
6379
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380/*
6381 * Decode READLINK response
6382 */
Chuck Leverbf269552010-12-14 14:59:29 +00006383static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6384 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006385 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387 struct compound_hdr hdr;
6388 int status;
6389
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006394 if (status)
6395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400out:
6401 return status;
6402}
6403
6404/*
6405 * Decode READDIR response
6406 */
Chuck Leverbf269552010-12-14 14:59:29 +00006407static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6408 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 struct compound_hdr hdr;
6411 int status;
6412
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 if (status)
6421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423out:
6424 return status;
6425}
6426
6427/*
6428 * Decode Read response
6429 */
Chuck Leverbf269552010-12-14 14:59:29 +00006430static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6431 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433 struct compound_hdr hdr;
6434 int status;
6435
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 if (status)
6438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006440 if (status)
6441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 if (status)
6444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 if (!status)
6447 status = res->count;
6448out:
6449 return status;
6450}
6451
6452/*
6453 * Decode WRITE response
6454 */
Chuck Leverbf269552010-12-14 14:59:29 +00006455static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6456 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 struct compound_hdr hdr;
6459 int status;
6460
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 if (status)
6463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006465 if (status)
6466 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 if (status)
6469 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006471 if (status)
6472 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006473 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006474 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 if (!status)
6476 status = res->count;
6477out:
6478 return status;
6479}
6480
6481/*
6482 * Decode COMMIT response
6483 */
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6485 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 struct compound_hdr hdr;
6488 int status;
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 if (status)
6492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006494 if (status)
6495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 if (status)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006500 if (status)
6501 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006502 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006503 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504out:
6505 return status;
6506}
6507
6508/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006509 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 */
Chuck Leverbf269552010-12-14 14:59:29 +00006511static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006512 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 struct compound_hdr hdr;
6515 int status;
6516
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006520 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 return status;
6525}
6526
6527/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006528 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 */
Chuck Leverbf269552010-12-14 14:59:29 +00006530static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006531 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 struct compound_hdr hdr;
6534 int status;
6535
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006539 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 return status;
6544}
6545
6546/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006547 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 */
Chuck Leverbf269552010-12-14 14:59:29 +00006549static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006550 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 struct compound_hdr hdr;
6553 int status;
6554
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006558 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006559 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 return status;
6563}
6564
6565/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006566 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 */
Chuck Leverbf269552010-12-14 14:59:29 +00006568static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6569 struct xdr_stream *xdr,
6570 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 struct compound_hdr hdr;
6573 int status;
6574
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006579 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_putfh(xdr);
6582 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585out:
6586 return status;
6587}
6588
6589/*
6590 * Decode RENEW response
6591 */
Chuck Leverbf269552010-12-14 14:59:29 +00006592static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6593 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 struct compound_hdr hdr;
6596 int status;
6597
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 return status;
6602}
6603
6604/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006605 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 */
Chuck Leverbf269552010-12-14 14:59:29 +00006607static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6608 struct xdr_stream *xdr,
6609 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 struct compound_hdr hdr;
6612 int status;
6613
Chuck Leverbf269552010-12-14 14:59:29 +00006614 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 return status;
6618}
6619
6620/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006621 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 */
Chuck Leverbf269552010-12-14 14:59:29 +00006623static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6624 struct xdr_stream *xdr,
6625 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 struct compound_hdr hdr;
6628 int status;
6629
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006634 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637 return status;
6638}
6639
6640/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006641 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 */
Chuck Leverbf269552010-12-14 14:59:29 +00006643static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6644 struct xdr_stream *xdr,
6645 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 struct compound_hdr hdr;
6648 int status;
6649
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006651 if (status)
6652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006654 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006657 if (status != 0)
6658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006660 if (status != 0)
6661 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006662 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006663out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 return status;
6665}
6666
Trond Myklebust683b57b2006-06-09 09:34:22 -04006667/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006668 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006669 */
Chuck Leverbf269552010-12-14 14:59:29 +00006670static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6671 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006672 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006673{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006674 struct compound_hdr hdr;
6675 int status;
6676
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006678 if (status)
6679 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006681 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_putfh(xdr);
6684 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_lookup(xdr);
6687 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006689 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006690 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6691 NULL, res->fs_locations,
6692 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006693out:
6694 return status;
6695}
6696
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006697/*
6698 * Decode SECINFO response
6699 */
6700static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6701 struct xdr_stream *xdr,
6702 struct nfs4_secinfo_res *res)
6703{
6704 struct compound_hdr hdr;
6705 int status;
6706
6707 status = decode_compound_hdr(xdr, &hdr);
6708 if (status)
6709 goto out;
6710 status = decode_sequence(xdr, &res->seq_res, rqstp);
6711 if (status)
6712 goto out;
6713 status = decode_putfh(xdr);
6714 if (status)
6715 goto out;
6716 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006717out:
6718 return status;
6719}
6720
Benny Halevy99fe60d2009-04-01 09:22:29 -04006721#if defined(CONFIG_NFS_V4_1)
6722/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006723 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006724 */
Chuck Leverbf269552010-12-14 14:59:29 +00006725static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6726 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006727 void *res)
6728{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006729 struct compound_hdr hdr;
6730 int status;
6731
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006733 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006735 return status;
6736}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006737
6738/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006739 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006740 */
Chuck Leverbf269552010-12-14 14:59:29 +00006741static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6742 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006743 struct nfs41_create_session_res *res)
6744{
Andy Adamsonfc931582009-04-01 09:22:31 -04006745 struct compound_hdr hdr;
6746 int status;
6747
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006749 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006751 return status;
6752}
6753
6754/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006755 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006756 */
Chuck Leverbf269552010-12-14 14:59:29 +00006757static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6758 struct xdr_stream *xdr,
6759 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006760{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006761 struct compound_hdr hdr;
6762 int status;
6763
Chuck Leverbf269552010-12-14 14:59:29 +00006764 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006765 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006767 return status;
6768}
6769
6770/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006771 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006772 */
Chuck Leverbf269552010-12-14 14:59:29 +00006773static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6774 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006775 struct nfs4_sequence_res *res)
6776{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006777 struct compound_hdr hdr;
6778 int status;
6779
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006781 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006782 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006783 return status;
6784}
6785
6786/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006787 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006788 */
Chuck Leverbf269552010-12-14 14:59:29 +00006789static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6790 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006791 struct nfs4_get_lease_time_res *res)
6792{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006793 struct compound_hdr hdr;
6794 int status;
6795
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006797 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006799 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006801 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006802 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006803 return status;
6804}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006805
6806/*
6807 * Decode RECLAIM_COMPLETE response
6808 */
Chuck Leverbf269552010-12-14 14:59:29 +00006809static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6810 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006811 struct nfs41_reclaim_complete_res *res)
6812{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006813 struct compound_hdr hdr;
6814 int status;
6815
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006817 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006819 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006820 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006821 return status;
6822}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006823
6824/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006825 * Decode GETDEVICELIST response
6826 */
6827static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6828 struct xdr_stream *xdr,
6829 struct nfs4_getdevicelist_res *res)
6830{
6831 struct compound_hdr hdr;
6832 int status;
6833
6834 dprintk("encoding getdevicelist!\n");
6835
6836 status = decode_compound_hdr(xdr, &hdr);
6837 if (status != 0)
6838 goto out;
6839 status = decode_sequence(xdr, &res->seq_res, rqstp);
6840 if (status != 0)
6841 goto out;
6842 status = decode_putfh(xdr);
6843 if (status != 0)
6844 goto out;
6845 status = decode_getdevicelist(xdr, res->devlist);
6846out:
6847 return status;
6848}
6849
6850/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006851 * Decode GETDEVINFO response
6852 */
Chuck Leverbf269552010-12-14 14:59:29 +00006853static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6854 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006855 struct nfs4_getdeviceinfo_res *res)
6856{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006857 struct compound_hdr hdr;
6858 int status;
6859
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006861 if (status != 0)
6862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006864 if (status != 0)
6865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006866 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006867out:
6868 return status;
6869}
6870
6871/*
6872 * Decode LAYOUTGET response
6873 */
Chuck Leverbf269552010-12-14 14:59:29 +00006874static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6875 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006876 struct nfs4_layoutget_res *res)
6877{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006878 struct compound_hdr hdr;
6879 int status;
6880
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006882 if (status)
6883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006884 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006885 if (status)
6886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006887 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006888 if (status)
6889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006890 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006891out:
6892 return status;
6893}
Andy Adamson863a3c62011-03-23 13:27:54 +00006894
6895/*
Benny Halevycbe82602011-05-22 19:52:37 +03006896 * Decode LAYOUTRETURN response
6897 */
6898static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6899 struct xdr_stream *xdr,
6900 struct nfs4_layoutreturn_res *res)
6901{
6902 struct compound_hdr hdr;
6903 int status;
6904
6905 status = decode_compound_hdr(xdr, &hdr);
6906 if (status)
6907 goto out;
6908 status = decode_sequence(xdr, &res->seq_res, rqstp);
6909 if (status)
6910 goto out;
6911 status = decode_putfh(xdr);
6912 if (status)
6913 goto out;
6914 status = decode_layoutreturn(xdr, res);
6915out:
6916 return status;
6917}
6918
6919/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006920 * Decode LAYOUTCOMMIT response
6921 */
6922static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6923 struct xdr_stream *xdr,
6924 struct nfs4_layoutcommit_res *res)
6925{
6926 struct compound_hdr hdr;
6927 int status;
6928
6929 status = decode_compound_hdr(xdr, &hdr);
6930 if (status)
6931 goto out;
6932 status = decode_sequence(xdr, &res->seq_res, rqstp);
6933 if (status)
6934 goto out;
6935 status = decode_putfh(xdr);
6936 if (status)
6937 goto out;
6938 status = decode_layoutcommit(xdr, rqstp, res);
6939 if (status)
6940 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006941 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006942out:
6943 return status;
6944}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006945
6946/*
6947 * Decode SECINFO_NO_NAME response
6948 */
6949static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6950 struct xdr_stream *xdr,
6951 struct nfs4_secinfo_res *res)
6952{
6953 struct compound_hdr hdr;
6954 int status;
6955
6956 status = decode_compound_hdr(xdr, &hdr);
6957 if (status)
6958 goto out;
6959 status = decode_sequence(xdr, &res->seq_res, rqstp);
6960 if (status)
6961 goto out;
6962 status = decode_putrootfh(xdr);
6963 if (status)
6964 goto out;
6965 status = decode_secinfo(xdr, res);
6966out:
6967 return status;
6968}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006969
6970/*
6971 * Decode TEST_STATEID response
6972 */
6973static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6974 struct xdr_stream *xdr,
6975 struct nfs41_test_stateid_res *res)
6976{
6977 struct compound_hdr hdr;
6978 int status;
6979
6980 status = decode_compound_hdr(xdr, &hdr);
6981 if (status)
6982 goto out;
6983 status = decode_sequence(xdr, &res->seq_res, rqstp);
6984 if (status)
6985 goto out;
6986 status = decode_test_stateid(xdr, res);
6987out:
6988 return status;
6989}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006990
6991/*
6992 * Decode FREE_STATEID response
6993 */
6994static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6995 struct xdr_stream *xdr,
6996 struct nfs41_free_stateid_res *res)
6997{
6998 struct compound_hdr hdr;
6999 int status;
7000
7001 status = decode_compound_hdr(xdr, &hdr);
7002 if (status)
7003 goto out;
7004 status = decode_sequence(xdr, &res->seq_res, rqstp);
7005 if (status)
7006 goto out;
7007 status = decode_free_stateid(xdr, res);
7008out:
7009 return status;
7010}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007011#endif /* CONFIG_NFS_V4_1 */
7012
Chuck Lever573c4e12010-12-14 14:58:11 +00007013/**
7014 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7015 * the local page cache.
7016 * @xdr: XDR stream where entry resides
7017 * @entry: buffer to fill in with entry data
7018 * @plus: boolean indicating whether this should be a readdirplus entry
7019 *
7020 * Returns zero if successful, otherwise a negative errno value is
7021 * returned.
7022 *
7023 * This function is not invoked during READDIR reply decoding, but
7024 * rather whenever an application invokes the getdents(2) system call
7025 * on a directory already in our cache.
7026 */
7027int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7028 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007029{
Fred Isamandae100c2011-07-30 20:52:37 -04007030 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007032 __be32 *p = xdr_inline_decode(xdr, 4);
7033 if (unlikely(!p))
7034 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007035 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007036 p = xdr_inline_decode(xdr, 4);
7037 if (unlikely(!p))
7038 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007039 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007040 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007042 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 }
7044
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007045 p = xdr_inline_decode(xdr, 12);
7046 if (unlikely(!p))
7047 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 entry->prev_cookie = entry->cookie;
7049 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007050 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007051
Trond Myklebust9af8c222010-10-24 11:52:55 -04007052 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007053 if (unlikely(!p))
7054 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007055 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056
7057 /*
7058 * In case the server doesn't return an inode number,
7059 * we fake one here. (We don't use inode number 0,
7060 * since glibc seems to choke on it...)
7061 */
7062 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007063 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064
Trond Myklebust9af8c222010-10-24 11:52:55 -04007065 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007066 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007067
7068 if (decode_attr_length(xdr, &len, &p) < 0)
7069 goto out_overflow;
7070
Chuck Lever573c4e12010-12-14 14:58:11 +00007071 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007072 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007073 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007074 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7075 entry->ino = entry->fattr->mounted_on_fileid;
7076 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007077 entry->ino = entry->fattr->fileid;
7078
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007079 entry->d_type = DT_UNKNOWN;
7080 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7081 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7082
Chuck Lever573c4e12010-12-14 14:58:11 +00007083 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007084
7085out_overflow:
7086 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007087 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007088}
7089
7090/*
7091 * We need to translate between nfs status return values and
7092 * the local errno values which may not be the same.
7093 */
7094static struct {
7095 int stat;
7096 int errno;
7097} nfs_errtbl[] = {
7098 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007099 { NFS4ERR_PERM, -EPERM },
7100 { NFS4ERR_NOENT, -ENOENT },
7101 { NFS4ERR_IO, -errno_NFSERR_IO},
7102 { NFS4ERR_NXIO, -ENXIO },
7103 { NFS4ERR_ACCESS, -EACCES },
7104 { NFS4ERR_EXIST, -EEXIST },
7105 { NFS4ERR_XDEV, -EXDEV },
7106 { NFS4ERR_NOTDIR, -ENOTDIR },
7107 { NFS4ERR_ISDIR, -EISDIR },
7108 { NFS4ERR_INVAL, -EINVAL },
7109 { NFS4ERR_FBIG, -EFBIG },
7110 { NFS4ERR_NOSPC, -ENOSPC },
7111 { NFS4ERR_ROFS, -EROFS },
7112 { NFS4ERR_MLINK, -EMLINK },
7113 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7114 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7115 { NFS4ERR_DQUOT, -EDQUOT },
7116 { NFS4ERR_STALE, -ESTALE },
7117 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007118 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7119 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7120 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007121 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007122 { NFS4ERR_BADTYPE, -EBADTYPE },
7123 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007124 { NFS4ERR_SYMLINK, -ELOOP },
7125 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7126 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007127 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007128};
7129
7130/*
7131 * Convert an NFS error code to a local one.
7132 * This one is used jointly by NFSv2 and NFSv3.
7133 */
7134static int
David Howells0a8ea432006-08-22 20:06:08 -04007135nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007136{
7137 int i;
7138 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7139 if (nfs_errtbl[i].stat == stat)
7140 return nfs_errtbl[i].errno;
7141 }
7142 if (stat <= 10000 || stat > 10100) {
7143 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007144 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007145 }
7146 /* If we cannot translate the error, the recovery routines should
7147 * handle it.
7148 * Note: remaining NFSv4 error codes have values > 10000, so should
7149 * not conflict with native Linux error codes.
7150 */
Benny Halevy856dff32008-03-31 17:39:06 +03007151 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007152}
7153
Linus Torvalds1da177e2005-04-16 15:20:36 -07007154#define PROC(proc, argtype, restype) \
7155[NFSPROC4_CLNT_##proc] = { \
7156 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007157 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007158 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007159 .p_arglen = NFS4_##argtype##_sz, \
7160 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007161 .p_statidx = NFSPROC4_CLNT_##proc, \
7162 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007163}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007164
7165struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007166 PROC(READ, enc_read, dec_read),
7167 PROC(WRITE, enc_write, dec_write),
7168 PROC(COMMIT, enc_commit, dec_commit),
7169 PROC(OPEN, enc_open, dec_open),
7170 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7171 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7172 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7173 PROC(CLOSE, enc_close, dec_close),
7174 PROC(SETATTR, enc_setattr, dec_setattr),
7175 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7176 PROC(RENEW, enc_renew, dec_renew),
7177 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7178 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7179 PROC(LOCK, enc_lock, dec_lock),
7180 PROC(LOCKT, enc_lockt, dec_lockt),
7181 PROC(LOCKU, enc_locku, dec_locku),
7182 PROC(ACCESS, enc_access, dec_access),
7183 PROC(GETATTR, enc_getattr, dec_getattr),
7184 PROC(LOOKUP, enc_lookup, dec_lookup),
7185 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7186 PROC(REMOVE, enc_remove, dec_remove),
7187 PROC(RENAME, enc_rename, dec_rename),
7188 PROC(LINK, enc_link, dec_link),
7189 PROC(SYMLINK, enc_symlink, dec_symlink),
7190 PROC(CREATE, enc_create, dec_create),
7191 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7192 PROC(STATFS, enc_statfs, dec_statfs),
7193 PROC(READLINK, enc_readlink, dec_readlink),
7194 PROC(READDIR, enc_readdir, dec_readdir),
7195 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7196 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7197 PROC(GETACL, enc_getacl, dec_getacl),
7198 PROC(SETACL, enc_setacl, dec_setacl),
7199 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7200 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007201 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007202#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007203 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7204 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7205 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7206 PROC(SEQUENCE, enc_sequence, dec_sequence),
7207 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7208 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7209 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7210 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007211 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007212 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007213 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007214 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007215 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007216 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007217#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218};
7219
Trond Myklebusta613fa12012-01-20 13:53:56 -05007220const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007221 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007222 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007223 .procs = nfs4_procedures
7224};
7225
7226/*
7227 * Local variables:
7228 * c-basic-offset: 8
7229 * End:
7230 */